import { describe, expect, it, vi } from "vitest"; import { renderToStaticMarkup } from "react-dom/server"; /** * v1.4.16 — `/admin/api-tokens` no horizontal overflow on * Pixel-5-class viewports (393 CSS px). * * The v1.4.15 fix tried hiding columns + tightening padding, but a * scrollbar still showed up because the wrapper kept `overflow-x-auto` * on mobile and content like long permission badges or token names * could exceed the available width. v1.4.16 mirrors the * `` pattern: the desktop `` is gated * behind `hidden md:block` and a real card-list renders at ({ useRouter: () => ({ push: vi.fn(), replace: vi.fn() }), usePathname: () => "/admin/api-tokens", })); const sampleTokens = [ { id: "tok1", name: "iOS app", permissions: ["*"], lastUsedAt: "2026-05-08T12:00:00Z", expiresAt: null, createdAt: "2026-05-01T08:00:00Z", revoked: false, user: { id: "u1", username: "testuser" }, }, ]; vi.mock("@tanstack/react-query", () => ({ useQuery: () => ({ data: sampleTokens, 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: "testuser", email: "user@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() { return renderToStaticMarkup( , ); } describe("ApiTokenOverviewSection — responsive", () => { it("hides the desktop table on mobile (
never paints (and never tries to scroll) on phones. expect(html).toMatch(/]*\bhidden\b[^>]*md:block[^>]*>[\s\S]*
{ const html = render(); // The mobile fallback is a
`s no longer carry // `whitespace-nowrap`. The v1.4.19 production probe confirmed that // class was the actual culprit behind the residual horizontal // scrollbar at 768-1280px: a formatted date+time string // ("05.05.2026, 21:46") overflowed its 12% colgroup allotment // (~84px on a 700px content area) and won over `table-fixed`'s // width contract, so the table's intrinsic width exceeded 100% // and the wrapping `overflow-x-auto` painted a scrollbar. Letting // the cell wrap to two lines costs one row of height but kills // the bar. const tableMatch = html.match(//); expect(tableMatch).not.toBeNull(); const tableMarkup = tableMatch![0]; // Pick every inside the desktop table that renders one of the // two date columns (text-right + text-xs is unique to those cells) // and assert none carries whitespace-nowrap. const dateCellMatches = tableMarkup.match(/]*\btext-right\b[^>]*\btext-xs\b[^>]*>/g) ?? []; expect(dateCellMatches.length).toBeGreaterThanOrEqual(2); for (const cell of dateCellMatches) { expect(cell).not.toContain("whitespace-nowrap"); } }); it("mobile timestamp lines wrap (no nowrap on the meta paragraphs)", () => { const html = render(); const mobileMatch = html.match(/]*md:hidden[^>]*>([\s\S]*?)<\/ul>/); expect(mobileMatch).not.toBeNull(); // The Last-used + Created lines are muted

meta — // no whitespace-nowrap so a long German date+time can flow onto a // second line within the card. The shadcn `` primitive // does carry `whitespace-nowrap`, which is fine for the short // permission strings we render — those are scoped to a flex-wrap // container that line-breaks at the badge boundary. expect(mobileMatch![1]).toMatch( /]*text-muted-foreground[^>]*text-xs[^>]*>(?![^<]*whitespace-nowrap)/, ); }); });