Skip to content

Commit

Permalink
Update page tests
Browse files Browse the repository at this point in the history
  • Loading branch information
acouch committed Jan 17, 2025
1 parent 2d29a8d commit ae3527a
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 7 deletions.
1 change: 1 addition & 0 deletions frontend/src/utils/testing/intlMocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const localeParams = new Promise<{ locale: string }>((resolve) => {
resolve({ locale: "en" });
});


// mocking all types of messages, could split by message type in the future
export const mockMessages = {
Process: {
Expand Down
7 changes: 7 additions & 0 deletions frontend/tests/pages/dev/feature-flags/page.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ const mockSetFeatureFlag = jest.fn(
},
);

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

jest.mock("src/hooks/useFeatureFlags", () => ({
useFeatureFlags: () => mockUseFeatureFlags(),
}));
Expand Down
7 changes: 7 additions & 0 deletions frontend/tests/pages/maintenance/page.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ jest.mock("next-intl/server", () => ({
setRequestLocale: identity,
}));

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

jest.mock("next-intl", () => ({
useTranslations: () => useTranslationsMock(),
useMessages: () => mockMessages,
Expand Down
7 changes: 7 additions & 0 deletions frontend/tests/pages/not-found.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ import { identity } from "lodash";
import PageNotFound from "src/app/[locale]/not-found";
import { 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,
unstable_setRequestLocale: identity,
Expand Down
7 changes: 7 additions & 0 deletions frontend/tests/pages/page.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ import {
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,
Expand Down
14 changes: 9 additions & 5 deletions frontend/tests/pages/process/page.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ import {
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,
Expand All @@ -20,17 +27,14 @@ jest.mock("next-intl", () => ({

describe("Process", () => {
it("renders intro text", () => {
render(Process({ params: localeParams }));

render(<Process params={localeParams} />);
const content = screen.getByText("intro.content");

expect(content).toBeInTheDocument();
});

it("passes accessibility scan", async () => {
const { container } = render(Process({ params: localeParams }));
const { container } = render(<Process params={localeParams} />);
const results = await waitFor(() => axe(container));

expect(results).toHaveNoViolations();
});
});
7 changes: 7 additions & 0 deletions frontend/tests/pages/research/page.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ import {
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,
Expand Down
5 changes: 4 additions & 1 deletion frontend/tests/pages/search/page.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import { render, screen } from "@testing-library/react";
import { identity } from "lodash";
import Search from "src/app/[locale]/search/page";
import { SEARCH_NO_STATUS_VALUE } from "src/constants/search";
import { useTranslationsMock } from "src/utils/testing/intlMocks";
import {
useTranslationsMock,
} from "src/utils/testing/intlMocks";

import { ReadonlyURLSearchParams } from "next/navigation";

Expand Down Expand Up @@ -54,6 +56,7 @@ jest.mock("react", () => ({
...jest.requireActual<typeof import("react")>("react"),
Suspense: ({ fallback }: { fallback: React.Component }) => fallback,
cache: (fn: unknown) => fn,
use: jest.fn((e:{ [key: string]: string }) => (e)),
}));

const fetchMock = jest.fn().mockResolvedValue({
Expand Down
7 changes: 7 additions & 0 deletions frontend/tests/pages/subscribe/page.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ jest.mock("react-dom", () => {
};
});

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

jest.mock("next-intl", () => ({
useTranslations: () => useTranslationsMock(),
}));
Expand Down
2 changes: 1 addition & 1 deletion frontend/tests/services/withFeatureFlag.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describe("WithFeatureFlag", () => {
expect(OriginalComponent).toHaveBeenCalledTimes(1);

// not sure what the second arg represents here but let's forget about it for now
expect(OriginalComponent).toHaveBeenCalledWith({ searchParams }, {});
expect(OriginalComponent).toHaveBeenCalledWith({ searchParams }, undefined);
});
it("calls onEnabled during wrapped component render when feature flag is enabled", () => {
enableFeature = true;
Expand Down

0 comments on commit ae3527a

Please sign in to comment.