BS-002 Establish public marketing routes and navigation

This commit is contained in:
rob
2026-11-10 14:06:46 +00:00
parent 52265961cb
commit ea28637259
13 changed files with 165 additions and 199 deletions
+33
View File
@@ -0,0 +1,33 @@
import { fireEvent, render, screen, within } 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 details"], ["/about", "About BortStack"],
["/contact", "Contact"], ["/privacy", "Privacy policy"],
["/login", "Page not found"], ["/register", "Page not found"], ["/dashboard", "Page not found"],
])("loads %s without account infrastructure", (path, heading) => {
const fetchMock = vi.fn();
vi.stubGlobal("fetch", fetchMock);
window.history.replaceState({}, "", path);
render(<App />);
expect(screen.getByRole("heading", { level: 1, name: heading })).toBeInTheDocument();
expect(fetchMock).not.toHaveBeenCalled();
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();
});
});