|
| 1 | +// @vitest-environment happy-dom |
| 2 | + |
| 3 | +import { act } from "react"; |
| 4 | +import { createRoot, type Root } from "react-dom/client"; |
| 5 | +import { afterEach, describe, expect, it, vi } from "vitest"; |
| 6 | +import { CompositionsTab } from "./sidebar/CompositionsTab"; |
| 7 | +import { TimelineToolbar } from "./TimelineToolbar"; |
| 8 | + |
| 9 | +// WCAG 2.2 (2.5.8) requires a 24x24 CSS pixel pointer target. happy-dom has no |
| 10 | +// CSS engine, so getBoundingClientRect() is 0x0 for everything here and the size |
| 11 | +// itself cannot be measured — these assert the utility classes that PRODUCE the |
| 12 | +// size instead, which is enough to fail if someone drops them. Real geometry |
| 13 | +// still needs a browser check. |
| 14 | + |
| 15 | +Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true }); |
| 16 | +( |
| 17 | + window as unknown as { happyDOM: { settings: { disableIframePageLoading: boolean } } } |
| 18 | +).happyDOM.settings.disableIframePageLoading = true; |
| 19 | + |
| 20 | +let root: Root | null = null; |
| 21 | + |
| 22 | +afterEach(() => { |
| 23 | + if (root) act(() => root?.unmount()); |
| 24 | + root = null; |
| 25 | + document.body.innerHTML = ""; |
| 26 | +}); |
| 27 | + |
| 28 | +function mount(element: React.ReactNode) { |
| 29 | + const host = document.createElement("div"); |
| 30 | + document.body.append(host); |
| 31 | + root = createRoot(host); |
| 32 | + act(() => root?.render(element)); |
| 33 | + return host; |
| 34 | +} |
| 35 | + |
| 36 | +describe("pointer target size (WCAG 2.5.8)", () => { |
| 37 | + it("gives the timeline zoom slider a 24px box without changing its 2px track or 10px thumb", () => { |
| 38 | + const host = mount(<TimelineToolbar />); |
| 39 | + const slider = host.querySelector<HTMLInputElement>('input[aria-label="Timeline zoom"]'); |
| 40 | + if (!slider) throw new Error("zoom slider did not render"); |
| 41 | + |
| 42 | + expect(slider.className).toContain("h-6"); |
| 43 | + expect(slider.className).toContain("[&::-webkit-slider-runnable-track]:h-[2px]"); |
| 44 | + expect(slider.className).toContain("[&::-webkit-slider-thumb]:h-[10px]"); |
| 45 | + expect(slider.className).toContain("[&::-webkit-slider-thumb]:w-[10px]"); |
| 46 | + }); |
| 47 | + |
| 48 | + it("gives the composition card's render button a 24x24 box around its 14px glyph", () => { |
| 49 | + const host = mount( |
| 50 | + <CompositionsTab |
| 51 | + projectId="demo" |
| 52 | + compositions={["compositions/headline.html"]} |
| 53 | + activeComposition={null} |
| 54 | + onSelect={vi.fn()} |
| 55 | + onRenderComposition={vi.fn()} |
| 56 | + />, |
| 57 | + ); |
| 58 | + const button = host.querySelector<HTMLButtonElement>('button[aria-label="Render headline"]'); |
| 59 | + if (!button) throw new Error("render button did not render"); |
| 60 | + |
| 61 | + expect(button.className).toContain("h-6"); |
| 62 | + expect(button.className).toContain("w-6"); |
| 63 | + expect(button.querySelector("svg")?.getAttribute("width")).toBe("14"); |
| 64 | + }); |
| 65 | +}); |
0 commit comments