Skip to content

Commit

Permalink
Add tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
freddieyebra committed Feb 27, 2025
1 parent 964a135 commit 6bca9d9
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 2 deletions.
4 changes: 2 additions & 2 deletions frontend/src/app/[locale]/roadmap/RoadmapMilestones.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default function RoadmapMilestones() {
sectionBackgroundColorClass="bg-base-lightest"
sectionContent={
<>
<h4>{t("contentTitle")}</h4>
<h2>{t("contentTitle")}</h2>
{Object.keys(contentItems).map((key) => {
const title = t(`contentItems.${key}.title`);
const content = t.rich(`contentItems.${key}.content`, {
Expand All @@ -25,7 +25,7 @@ export default function RoadmapMilestones() {
});
return (
<div key={`roadmap-milestones-${title}-key`}>
<h5>{title}</h5>
<h3>{title}</h3>
{content}
</div>
);
Expand Down
21 changes: 21 additions & 0 deletions frontend/src/utils/testing/intlMocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,25 @@ export const mockMessages = {
boxes: ["firstKey"],
},
},
Roadmap: {
pageHeaderTitle: "Product roadmap",
sections: {
progress: {
title: "progress test title",
contentItems: [
[{ title: "test title 1", content: "test content 1" }],
[{ title: "test title 2", content: "test content 2" }],
],
},
milestones: {
title: "milestones test title",
contentItems: [{ title: "test title 3", content: "test content 3" }],
},
process: {
title: "process test title",
sectionSummary: "process test summary",
contentItems: [{ title: "test title 4", content: "test content 4" }],
},
},
},
};
14 changes: 14 additions & 0 deletions frontend/tests/components/roadmap/RoadmapHeader.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import RoadmapHeader from "src/app/[locale]/roadmap/RoadmapHeader";
import { render, screen } from "tests/react-utils";

describe("RoadmapHeader Content", () => {
it("Renders with expected header", () => {
render(<RoadmapHeader />);
const RoadmapH1 = screen.getByRole("heading", {
level: 1,
name: /Product roadmap?/i,
});

expect(RoadmapH1).toBeInTheDocument();
});
});
14 changes: 14 additions & 0 deletions frontend/tests/components/roadmap/RoadmapMilestones.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import RoadmapMilestones from "src/app/[locale]/roadmap/RoadmapMilestones";
import { render, screen } from "tests/react-utils";

describe("RoadmapMilestones Content", () => {
it("Renders with expected header", () => {
render(<RoadmapMilestones />);
const RoadmapMilestonesH2 = screen.getByRole("heading", {
level: 2,
name: /Recent milestones reached?/i,
});

expect(RoadmapMilestonesH2).toBeInTheDocument();
});
});
36 changes: 36 additions & 0 deletions frontend/tests/pages/roadmap/page.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { render, screen, waitFor } from "@testing-library/react";
import { axe } from "jest-axe";
import { identity } from "lodash";
import Roadmap from "src/app/[locale]/roadmap/page";
import { mockMessages, useTranslationsMock } from "src/utils/testing/intlMocks";

jest.mock("react", () => ({
...jest.requireActual<typeof import("react")>("react"),
use: jest.fn(() => ({
locale: "en",
})),
}));

jest.mock("next-intl/server", () => ({
getTranslations: () => identity,
setRequestLocale: identity,
}));

jest.mock("next-intl", () => ({
useTranslations: () => useTranslationsMock(),
useMessages: () => mockMessages,
}));

describe("Roadmap", () => {
it("renders header title text", () => {
render(<Roadmap />);
const content = screen.getByText("pageHeaderTitle");
expect(content).toBeInTheDocument();
});

it("passes accessibility scan", async () => {
const { container } = render(<Roadmap />);
const results = await waitFor(() => axe(container));
expect(results).toHaveNoViolations();
});
});

0 comments on commit 6bca9d9

Please sign in to comment.