Set up unit testing infrastructure

Extract slot generation from book.ts into pure utility for unit testing.
Add 8 API unit tests and 4 web component tests with coverage thresholds.

Closes #39

Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit was merged in pull request #42.
This commit is contained in:
groombook-paperclip[bot]
2026-03-18 01:55:02 +00:00
committed by GitHub
parent d718821515
commit cba502e35f
10 changed files with 1046 additions and 26 deletions
+58
View File
@@ -0,0 +1,58 @@
import { describe, it, expect, vi, beforeEach } from "vitest";
import { render, screen, within, act } from "@testing-library/react";
import { MemoryRouter } from "react-router-dom";
import { App } from "../App.js";
// Prevent fetch errors from page components loading data on mount
beforeEach(() => {
global.fetch = vi.fn().mockResolvedValue({
ok: true,
json: async () => [],
} as unknown as Response);
});
async function renderApp(route = "/") {
await act(async () => {
render(
<MemoryRouter initialEntries={[route]}>
<App />
</MemoryRouter>
);
});
return screen.getByRole("navigation");
}
describe("App navigation", () => {
it("renders the Groom Book brand", async () => {
const nav = await renderApp();
expect(within(nav).getByText("Groom Book")).toBeInTheDocument();
});
it("renders the Book CTA button", async () => {
const nav = await renderApp();
expect(within(nav).getByText("Book")).toBeInTheDocument();
});
it("renders all primary nav links", async () => {
const nav = await renderApp();
const expectedLinks = [
"Appointments",
"Clients",
"Services",
"Staff",
"Invoices",
"Group Bookings",
"Reports",
];
expectedLinks.forEach((label) => {
expect(within(nav).getByText(label)).toBeInTheDocument();
});
});
it("highlights the active route link", async () => {
const nav = await renderApp("/clients");
const clientsLink = within(nav).getByText("Clients");
// Active links use fontWeight 600
expect(clientsLink).toHaveStyle({ fontWeight: "600" });
});
});
+1
View File
@@ -0,0 +1 @@
import "@testing-library/jest-dom";