39 lines
2.4 KiB
React
39 lines
2.4 KiB
React
import { fireEvent, render, screen, within, waitFor } from "@testing-library/react";
|
|
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
import App from "../App";
|
|
|
|
afterEach(() => { window.history.replaceState({}, "", "/"); vi.unstubAllGlobals(); });
|
|
describe("public marketing routes", () => {
|
|
it.each([
|
|
["/services", "Services"], ["/projects", "Projects"],
|
|
["/projects/example", "Project not found"], ["/about", "About BortStack"],
|
|
["/contact", "Have a project in mind?"], ["/privacy", "Privacy policy"],
|
|
["/login", "Page not found"], ["/register", "Page not found"], ["/dashboard", "Page not found"],
|
|
])("loads %s without account infrastructure", async (path, heading) => {
|
|
const fetchMock = vi.fn().mockResolvedValue({ ok: true, json: async () => ({ email: null, available: false }) });
|
|
vi.stubGlobal("fetch", fetchMock);
|
|
window.history.replaceState({}, "", path);
|
|
render(<App />);
|
|
expect(screen.getByRole("heading", { level: 1, name: heading })).toBeInTheDocument();
|
|
if (path === "/contact") {
|
|
expect(fetchMock).toHaveBeenCalledWith("/api/contact/config");
|
|
await waitFor(() => expect(screen.getByText(/Enquiries are temporarily unavailable/)).toBeInTheDocument());
|
|
}
|
|
else expect(fetchMock).not.toHaveBeenCalled();
|
|
if (path === "/privacy") await waitFor(() => expect(document.querySelector('meta[name="robots"]')).toHaveAttribute("content", "noindex, nofollow"));
|
|
expect(screen.queryByRole("link", { name: /login|register|dashboard/i })).not.toBeInTheDocument();
|
|
});
|
|
it("exposes the four marketing links and closes navigation on selection", async () => {
|
|
render(<App />);
|
|
const nav = screen.getByRole("navigation", { name: "Main navigation" });
|
|
fireEvent.click(screen.getByRole("button", { name: "Toggle navigation" }));
|
|
await within(nav).findByRole("link", { name: "Services" });
|
|
for (const name of ["Services", "Projects", "About", "Contact"]) {
|
|
expect(within(nav).getByRole("link", { name })).toBeInTheDocument();
|
|
}
|
|
fireEvent.click(within(nav).getByRole("link", { name: "Services" }));
|
|
expect(screen.getByRole("button", { name: "Toggle navigation" })).toHaveAttribute("aria-expanded", "false");
|
|
expect(screen.getByRole("heading", { name: "Services" })).toBeInTheDocument();
|
|
});
|
|
});
|