-
-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'codu-code:develop' into bugfix/pr-lint-issues
- Loading branch information
Showing
15 changed files
with
537 additions
and
4,278 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,75 +1,75 @@ | ||
import React from "react"; | ||
import { render, screen } from "@testing-library/react"; | ||
import userEvent from "@testing-library/user-event"; | ||
import "@testing-library/jest-dom"; | ||
import { PromptDialog } from "@/components/PromptService"; | ||
// TODO refactor into e2e Playwright tests | ||
|
||
class ResizeObserver { | ||
observe() { | ||
// do nothing | ||
} | ||
unobserve() { | ||
// do nothing | ||
} | ||
disconnect() { | ||
// do nothing | ||
} | ||
} | ||
// import React from "react"; | ||
|
||
window.ResizeObserver = ResizeObserver; | ||
// import { PromptDialog } from "@/components/PromptService"; | ||
|
||
jest.mock("next/navigation", () => ({ | ||
useRouter: jest.fn(), | ||
})); | ||
// class ResizeObserver { | ||
// observe() { | ||
// // do nothing | ||
// } | ||
// unobserve() { | ||
// // do nothing | ||
// } | ||
// disconnect() { | ||
// // do nothing | ||
// } | ||
// } | ||
|
||
jest.mock("./PromptContext", () => ({ | ||
usePrompt: jest.fn(), | ||
})); | ||
// window.ResizeObserver = ResizeObserver; | ||
|
||
describe("PromptDialog Component", () => { | ||
const mockConfirm = jest.fn(); | ||
const mockCancel = jest.fn(); | ||
// jest.mock("next/navigation", () => ({ | ||
// useRouter: jest.fn(), | ||
// })); | ||
|
||
jest.mock("next/navigation", () => ({ | ||
useRouter: jest.fn(), | ||
})); | ||
// jest.mock("./PromptContext", () => ({ | ||
// usePrompt: jest.fn(), | ||
// })); | ||
|
||
const PromptDialogTestComponent = ( | ||
<PromptDialog | ||
title="Test Title" | ||
subTitle="Test Subtitle" | ||
content="Test Content" | ||
confirm={mockConfirm} | ||
cancel={mockCancel} | ||
confirmText="Continue without saving" | ||
cancelText="Keep editing" | ||
/> | ||
); | ||
// describe("PromptDialog Component", () => { | ||
// const mockConfirm = jest.fn(); | ||
// const mockCancel = jest.fn(); | ||
|
||
it("renders with provided title, subtitle and content", () => { | ||
render(PromptDialogTestComponent); | ||
expect(screen.getByText("Test Title")).toBeInTheDocument(); | ||
expect(screen.getByText("Test Subtitle")).toBeInTheDocument(); | ||
expect(screen.getByText("Test Content")).toBeInTheDocument(); | ||
}); | ||
// jest.mock("next/navigation", () => ({ | ||
// useRouter: jest.fn(), | ||
// })); | ||
|
||
it("calls confirm callback when continue button is clicked", async () => { | ||
render(PromptDialogTestComponent); | ||
await userEvent.click( | ||
screen.getByRole("button", { name: "Continue without saving" }), | ||
); | ||
expect(mockConfirm).toHaveBeenCalled(); | ||
}); | ||
// const PromptDialogTestComponent = ( | ||
// <PromptDialog | ||
// title="Test Title" | ||
// subTitle="Test Subtitle" | ||
// content="Test Content" | ||
// confirm={mockConfirm} | ||
// cancel={mockCancel} | ||
// confirmText="Continue without saving" | ||
// cancelText="Keep editing" | ||
// /> | ||
// ); | ||
|
||
it("calls cancel callback when cancel button is clicked", async () => { | ||
render(PromptDialogTestComponent); | ||
await userEvent.click(screen.getByRole("button", { name: "Keep editing" })); | ||
expect(mockCancel).toHaveBeenCalled(); | ||
}); | ||
// it("renders with provided title, subtitle and content", () => { | ||
// render(PromptDialogTestComponent); | ||
// expect(screen.getByText("Test Title")).toBeInTheDocument(); | ||
// expect(screen.getByText("Test Subtitle")).toBeInTheDocument(); | ||
// expect(screen.getByText("Test Content")).toBeInTheDocument(); | ||
// }); | ||
|
||
it("calls cancel callback when close icon is clicked", async () => { | ||
render(PromptDialogTestComponent); | ||
await userEvent.click(screen.getByRole("button", { name: "Close" })); | ||
expect(mockCancel).toHaveBeenCalled(); | ||
}); | ||
}); | ||
// it("calls confirm callback when continue button is clicked", async () => { | ||
// render(PromptDialogTestComponent); | ||
// await userEvent.click( | ||
// screen.getByRole("button", { name: "Continue without saving" }), | ||
// ); | ||
// expect(mockConfirm).toHaveBeenCalled(); | ||
// }); | ||
|
||
// it("calls cancel callback when cancel button is clicked", async () => { | ||
// render(PromptDialogTestComponent); | ||
// await userEvent.click(screen.getByRole("button", { name: "Keep editing" })); | ||
// expect(mockCancel).toHaveBeenCalled(); | ||
// }); | ||
|
||
// it("calls cancel callback when close icon is clicked", async () => { | ||
// render(PromptDialogTestComponent); | ||
// await userEvent.click(screen.getByRole("button", { name: "Close" })); | ||
// expect(mockCancel).toHaveBeenCalled(); | ||
// }); | ||
// }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,38 @@ | ||
import { render, screen } from "@testing-library/react"; | ||
import "@testing-library/jest-dom"; | ||
import userEvent from "@testing-library/user-event"; | ||
import { ThemeProvider } from "next-themes"; | ||
import { axe, toHaveNoViolations } from "jest-axe"; | ||
import ThemeToggle from "./ThemeToggle"; | ||
// TODO refactor into e2e Playwright tests | ||
// Use @axe-core/playwright - https://playwright.dev/docs/accessibility-testing | ||
|
||
expect.extend(toHaveNoViolations); | ||
// import { render, screen } from "@testing-library/react"; | ||
// import "@testing-library/jest-dom"; | ||
// import userEvent from "@testing-library/user-event"; | ||
// import { ThemeProvider } from "next-themes"; | ||
// import { axe, toHaveNoViolations } from "jest-axe"; | ||
// import ThemeToggle from "./ThemeToggle"; | ||
|
||
describe("Theme Toggle", () => { | ||
const user = userEvent.setup(); | ||
// expect.extend(toHaveNoViolations); | ||
|
||
it("renders with no axe violations", async () => { | ||
const { container } = render(<ThemeToggle />, { wrapper: ThemeProvider }); | ||
const results = await axe(container); | ||
expect(results).toHaveNoViolations(); | ||
}); | ||
// describe("Theme Toggle", () => { | ||
// const user = userEvent.setup(); | ||
|
||
it("renders a theme toggle button and toggles pressed state", async () => { | ||
render(<ThemeToggle />, { wrapper: ThemeProvider }); | ||
// it("renders with no axe violations", async () => { | ||
// const { container } = render(<ThemeToggle />, { wrapper: ThemeProvider }); | ||
// const results = await axe(container); | ||
// expect(results).toHaveNoViolations(); | ||
// }); | ||
|
||
const toggleButton = screen.getByRole("button", { | ||
name: "Toggle Dark Mode", | ||
pressed: false, | ||
}); | ||
// it("renders a theme toggle button and toggles pressed state", async () => { | ||
// render(<ThemeToggle />, { wrapper: ThemeProvider }); | ||
|
||
expect(toggleButton).toBeInTheDocument(); | ||
// const toggleButton = screen.getByRole("button", { | ||
// name: "Toggle Dark Mode", | ||
// pressed: false, | ||
// }); | ||
|
||
await user.click(toggleButton); | ||
expect(toggleButton).toHaveAttribute("aria-pressed", "true"); | ||
// expect(toggleButton).toBeInTheDocument(); | ||
|
||
await user.click(toggleButton); | ||
expect(toggleButton).toHaveAttribute("aria-pressed", "false"); | ||
}); | ||
}); | ||
// await user.click(toggleButton); | ||
// expect(toggleButton).toHaveAttribute("aria-pressed", "true"); | ||
|
||
// await user.click(toggleButton); | ||
// expect(toggleButton).toHaveAttribute("aria-pressed", "false"); | ||
// }); | ||
// }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { test, expect } from "playwright/test"; | ||
|
||
test.describe("Articles", () => { | ||
test("Should load more articles when scrolling to the end of the page", async ({ | ||
page, | ||
}) => { | ||
await page.goto("http://localhost:3000/articles"); | ||
// Waits for articles to be loaded | ||
await page.waitForSelector("article"); | ||
|
||
const initialArticleCount = await page.$$eval( | ||
"article", | ||
(articles) => articles.length, | ||
); | ||
|
||
await page.evaluate(() => { | ||
window.scrollTo(0, document.body.scrollHeight); | ||
}); | ||
|
||
await expect(page.locator(".animate-pulse")).toBeVisible(); | ||
await expect(page.locator(".animate-pulse")).not.toBeVisible(); | ||
|
||
const finalArticleCount = await page.$$eval( | ||
"article", | ||
(articles) => articles.length, | ||
); | ||
|
||
expect(finalArticleCount).toBeGreaterThan(initialArticleCount); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { test, expect } from "playwright/test"; | ||
|
||
test.afterEach(async ({ page }) => { | ||
// Sign out the user after all tests are done | ||
await page.goto("http://localhost:3000/api/auth/signout"); | ||
await page.getByRole("button", { name: "Sign out" }).click(); | ||
await expect(page.locator("#submitButton")).not.toBeVisible(); | ||
}); | ||
|
||
test.beforeEach(async ({ page }) => { | ||
await page.goto("http://localhost:3000/get-started"); | ||
}); | ||
|
||
test.describe("Login Page", () => { | ||
test("should display the login button", async ({ page }) => { | ||
const loginButton = page.getByRole("button", { | ||
name: "Sign in with GitHub Login", | ||
}); | ||
expect(loginButton).toBeTruthy(); | ||
}); | ||
|
||
test("should navigate to GitHub login page when clicking the login button", async ({ | ||
page, | ||
}) => { | ||
const button = page.getByRole("button", { | ||
name: "Sign in with GitHub Login", | ||
}); | ||
|
||
await button.click(); | ||
await page.waitForURL("https://github.com/**"); | ||
|
||
expect(page.getByLabel("Username or email address")).toBeTruthy(); | ||
|
||
expect(page.getByLabel("Password")).toBeTruthy(); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.