-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: basic tests for static pages [1393]
- Loading branch information
1 parent
811c2e9
commit a4ad0cf
Showing
5 changed files
with
178 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { render, screen, waitFor } from "@testing-library/react"; | ||
import { axe } from "jest-axe"; | ||
import { identity } from "lodash"; | ||
import PageNotFound from "src/app/not-found"; | ||
import { useTranslationsMock } from "tests/utils/intlMocks"; | ||
|
||
jest.mock("next-intl/server", () => ({ | ||
getTranslations: () => identity, | ||
unstable_setRequestLocale: identity, | ||
})); | ||
|
||
jest.mock("next-intl", () => ({ | ||
useTranslations: () => useTranslationsMock(), | ||
})); | ||
|
||
describe("PageNotFound", () => { | ||
it("renders alert with grants.gov link", () => { | ||
render(<PageNotFound />); | ||
|
||
const alert = screen.queryByTestId("alert"); | ||
|
||
expect(alert).toBeInTheDocument(); | ||
}); | ||
|
||
it("links back to the home page", () => { | ||
render(<PageNotFound />); | ||
const link = screen.getByRole("link", { name: "visit_homepage_button" }); | ||
|
||
expect(link).toBeInTheDocument(); | ||
}); | ||
|
||
it("passes accessibility scan", async () => { | ||
const { container } = render(<PageNotFound />); | ||
const results = await waitFor(() => axe(container)); | ||
|
||
expect(results).toHaveNoViolations(); | ||
}); | ||
}); |
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,32 @@ | ||
import { render, screen, waitFor } from "@testing-library/react"; | ||
import { axe } from "jest-axe"; | ||
import { identity } from "lodash"; | ||
import Home from "src/app/[locale]/page"; | ||
import { mockMessages, useTranslationsMock } from "tests/utils/intlMocks"; | ||
|
||
jest.mock("next-intl/server", () => ({ | ||
getTranslations: () => identity, | ||
unstable_setRequestLocale: identity, | ||
})); | ||
|
||
jest.mock("next-intl", () => ({ | ||
useTranslations: () => useTranslationsMock(), | ||
useMessages: () => mockMessages, | ||
})); | ||
|
||
describe("Home", () => { | ||
it("renders intro text", () => { | ||
render(<Home />); | ||
|
||
const content = screen.getByText("goal.paragraph_1"); | ||
|
||
expect(content).toBeInTheDocument(); | ||
}); | ||
|
||
it("passes accessibility scan", async () => { | ||
const { container } = render(<Home />); | ||
const results = await waitFor(() => axe(container)); | ||
|
||
expect(results).toHaveNoViolations(); | ||
}); | ||
}); |
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,32 @@ | ||
import { render, screen, waitFor } from "@testing-library/react"; | ||
import { axe } from "jest-axe"; | ||
import { identity } from "lodash"; | ||
import Process from "src/app/[locale]/process/page"; | ||
import { mockMessages, useTranslationsMock } from "tests/utils/intlMocks"; | ||
|
||
jest.mock("next-intl/server", () => ({ | ||
getTranslations: () => identity, | ||
unstable_setRequestLocale: identity, | ||
})); | ||
|
||
jest.mock("next-intl", () => ({ | ||
useTranslations: () => useTranslationsMock(), | ||
useMessages: () => mockMessages, | ||
})); | ||
|
||
describe("Process", () => { | ||
it("renders intro text", () => { | ||
render(<Process />); | ||
|
||
const content = screen.getByText("intro.content"); | ||
|
||
expect(content).toBeInTheDocument(); | ||
}); | ||
|
||
it("passes accessibility scan", async () => { | ||
const { container } = render(<Process />); | ||
const results = await waitFor(() => axe(container)); | ||
|
||
expect(results).toHaveNoViolations(); | ||
}); | ||
}); |
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,32 @@ | ||
import { render, screen, waitFor } from "@testing-library/react"; | ||
import { axe } from "jest-axe"; | ||
import { identity } from "lodash"; | ||
import Research from "src/app/[locale]/research/page"; | ||
import { mockMessages, useTranslationsMock } from "tests/utils/intlMocks"; | ||
|
||
jest.mock("next-intl/server", () => ({ | ||
getTranslations: () => identity, | ||
unstable_setRequestLocale: identity, | ||
})); | ||
|
||
jest.mock("next-intl", () => ({ | ||
useTranslations: () => useTranslationsMock(), | ||
useMessages: () => mockMessages, | ||
})); | ||
|
||
describe("Research", () => { | ||
it("renders intro text", () => { | ||
render(<Research />); | ||
|
||
const content = screen.getByText("intro.content"); | ||
|
||
expect(content).toBeInTheDocument(); | ||
}); | ||
|
||
it("passes accessibility scan", async () => { | ||
const { container } = render(<Research />); | ||
const results = await waitFor(() => axe(container)); | ||
|
||
expect(results).toHaveNoViolations(); | ||
}); | ||
}); |
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,44 @@ | ||
function mockUseTranslations(translationKey: string) { | ||
return translationKey; | ||
} | ||
|
||
mockUseTranslations.rich = (translationKey: string) => translationKey; | ||
|
||
// // test without i18n functionality, pass through translation key as text | ||
// export function generateNextIntlServerMock() { | ||
// return { | ||
// getTranslations: () => (translationKey: string) => translationKey, | ||
// unstable_setRequestLocale: () => {}, | ||
// }; | ||
// } | ||
|
||
export function useTranslationsMock() { | ||
return mockUseTranslations; | ||
} | ||
|
||
// mocking all types of messages, could split by message type in the future | ||
export const mockMessages = { | ||
Process: { | ||
intro: { | ||
boxes: ["firstKey"], | ||
}, | ||
milestones: { | ||
icon_list: ["firstIcon"], | ||
}, | ||
}, | ||
Research: { | ||
impact: { | ||
boxes: ["firstKey"], | ||
}, | ||
}, | ||
}; | ||
|
||
// export function useMessagesMock() { | ||
// return { | ||
// Process: { | ||
// intro: { | ||
// boxes: ["firstKey"], | ||
// }, | ||
// }, | ||
// }; | ||
// } |