40 lines
1.5 KiB
TypeScript
40 lines
1.5 KiB
TypeScript
import "@testing-library/jest-dom";
|
|
import { render, screen } from "@testing-library/react";
|
|
import React from "react";
|
|
import { MemoryRouter } from "react-router";
|
|
import { describe, expect, it, vi } from "vitest";
|
|
import Page404 from "./Page404";
|
|
|
|
const translations = vi.hoisted<Record<string, string>>(() => ({
|
|
"404.eyebrow": "404 error",
|
|
}));
|
|
|
|
vi.mock("react-i18next", () => ({
|
|
useTranslation: () => ({
|
|
t: (key: string) => translations[key] ?? key,
|
|
}),
|
|
}));
|
|
|
|
vi.mock("~/components/brand/Logo", () => ({ default: () => <div data-testid="logo">Logo</div> }));
|
|
vi.mock("~/components/public/PublicFooter", () => ({ default: () => <footer data-testid="public-footer">Footer</footer> }));
|
|
|
|
function renderPage404(props: React.ComponentProps<typeof Page404> = {}) {
|
|
return render(
|
|
<MemoryRouter>
|
|
<Page404 {...props} />
|
|
</MemoryRouter>
|
|
);
|
|
}
|
|
|
|
describe("Page404", () => {
|
|
it("delegates to the shared 404 error page while preserving custom title and controls", () => {
|
|
renderPage404({ title: "Missing project", withFooter: false, withGoBack: false });
|
|
|
|
expect(screen.getByTestId("error-page")).toHaveAttribute("data-error-status", "404");
|
|
expect(screen.getByRole("heading", { name: "Missing project" })).toBeInTheDocument();
|
|
expect(screen.getByText("404 error")).toBeInTheDocument();
|
|
expect(screen.queryByTestId("public-footer")).not.toBeInTheDocument();
|
|
expect(screen.queryByRole("button", { name: /go back/i })).not.toBeInTheDocument();
|
|
});
|
|
});
|