-
Notifications
You must be signed in to change notification settings - Fork 16
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] (#2197)
* adds utils for mocking intl
- Loading branch information
1 parent
c3590d8
commit 27b6f35
Showing
5 changed files
with
160 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,26 @@ | ||
function mockUseTranslations(translationKey: string) { | ||
return translationKey; | ||
} | ||
|
||
mockUseTranslations.rich = (translationKey: string) => translationKey; | ||
|
||
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"], | ||
}, | ||
}, | ||
}; |
27b6f35
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Coverage report for
./frontend
Test suite run success
187 tests passing in 58 suites.
Report generated by 🧪jest coverage report action from 27b6f35