// @vitest-environment jsdom import { render, screen } from "@testing-library/react"; import type { ComponentType } from "react"; import { createMemoryRouter, RouterProvider } from "react-router-dom"; import { describe, expect, it } from "vitest"; import { TEMPLATE_APP_MODULE } from "../../src/apps/template-app.ts"; import { AppShell } from "../../src/presentation/layouts/app-shell.tsx"; import { ApplicationProvider } from "../../src/presentation/providers/application-provider.tsx"; import { PreferenceProviders } from "../../src/presentation/providers/preference-providers.tsx"; import { SessionProvider } from "../../src/presentation/providers/session-provider.tsx"; import { createTestApplication } from "../helpers/create-test-application.ts"; import { LAYOUT_PRODUCT_CONTEXT_MODULES } from "../helpers/fixture-layout-product.tsx"; /** * 09-03 (1101/14.4). The router moves focus to `#main-content` on every route * change, so every layout it mounts has to render a skip link to it and make * it the one main landmark around the page. The layouts are read from the * contexts of the installed product and of the fixture product, so a new * `context-layout.tsx` is checked without being named here. */ const contexts = [ ...TEMPLATE_APP_MODULE.contexts, // The fixture's offline layout chunk never arrives, by design. ...LAYOUT_PRODUCT_CONTEXT_MODULES.filter((context) => context.id !== "offline"), ]; const LAYOUTS: readonly (readonly [string, ComponentType])[] = [ ["AppShell", AppShell], ...(await Promise.all( contexts.flatMap((context) => { const loadLayout = context.route?.loadLayout; return loadLayout ? [loadLayout().then((Layout) => [`context ${context.id}`, Layout] as const)] : []; }), )), ]; describe("every layout the router mounts", () => { it.each(LAYOUTS)("%s links its skip link to its one main landmark", async (_name, Layout) => { const router = createMemoryRouter([ { path: "/", element: , children: [{ index: true, element:

Probe page

}] }, ]); render( , ); const page = await screen.findByRole("heading", { name: "Probe page", level: 1 }); const mains = document.querySelectorAll('main, [role="main"]'); expect(mains).toHaveLength(1); expect(mains[0]).toHaveAttribute("id", "main-content"); expect(mains[0]).toContainElement(page); expect(document.querySelector('a[href="#main-content"]')).not.toBeNull(); }); });