diff --git a/src/components/admin/__tests__/api-token-no-collapse.test.tsx b/src/components/admin/__tests__/api-token-no-collapse.test.tsx new file mode 100644 index 000000000..6c943fa60 --- /dev/null +++ b/src/components/admin/__tests__/api-token-no-collapse.test.tsx @@ -0,0 +1,82 @@ +import { describe, expect, it, vi } from "vitest"; +import { renderToStaticMarkup } from "react-dom/server"; + +/** + * v1.4.19 phase A7 — `/admin/api-tokens` no longer renders a Collapse + * / Expand toggle. The toggle existed as an escape hatch from the + * v1.4 shared-admin page where 13 sections lived on one route; in + * v1.5 every section has its own dedicated route, so collapsing the + * only card on `/admin/api-tokens` hides the entire surface and + * confused Marc more than it helped. + */ + +vi.mock("next/navigation", () => ({ + useRouter: () => ({ push: vi.fn(), replace: vi.fn() }), + usePathname: () => "/admin/api-tokens", +})); + +vi.mock("@tanstack/react-query", () => ({ + useQuery: () => ({ + data: [], + isLoading: false, + isError: false, + refetch: vi.fn(), + }), + useQueryClient: () => ({ invalidateQueries: vi.fn() }), + useMutation: () => ({ + mutate: vi.fn(), + isPending: false, + isError: false, + error: null, + }), +})); + +vi.mock("@/hooks/use-auth", () => ({ + useAuth: () => ({ + user: { + id: "u1", + username: "marc", + email: "marc@example.com", + role: "ADMIN", + }, + isAuthenticated: true, + isLoading: false, + refetch: vi.fn(), + }), +})); + +import { I18nProvider } from "@/lib/i18n/context"; +import { ApiTokenOverviewSection } from "../api-token-overview-section"; + +function render(locale: "en" | "de" = "en") { + return renderToStaticMarkup( + + + , + ); +} + +describe("ApiTokenOverviewSection — no collapse button", () => { + it("does not render a Collapse / Expand button (English)", () => { + const html = render("en"); + expect(html).not.toMatch(/\bCollapse\b/); + expect(html).not.toMatch(/\bExpand\b/); + }); + + it("does not render an Einklappen / Ausklappen button (German)", () => { + const html = render("de"); + expect(html).not.toMatch(/\bEinklappen\b/); + expect(html).not.toMatch(/\bAusklappen\b/); + }); + + it("never renders an `aria-expanded` button on the section header", () => { + const html = render(); + // The toggle previously surfaced as +
+ +
{t("admin.apiTokens")}
- {expanded && ( -
- {isLoading ? ( +
+ {isLoading ? (
@@ -291,8 +275,7 @@ export function ApiTokenOverviewSection() { )} -
- )} +
); }