- F12 (owner: A): SwitchRow, the whole settings row toggles; a Config boolean toggles from its title and hint (a label pointed at the switch). - F14 (owner: B): the form dropdown trigger wears the field frame (see-through, the >= 3:1 edge); labelled pills keep the faint edge and the accent-edge hover. DESIGN says so, with log rows. - F6: ~15 bg-card / bg-border / opacity hovers onto the B3 state layer; a lint rule (HOVER_SWAP) refuses the swap, contract-tested. - F10: bare 14px icon links onto IconLink / LinkButton; a local lint rule refuses a glyph-only <a>. - F13: reason-disabled controls are aria-disabled (Users, Channels backfill, Discovery, Scheduler runs, Config tests); FocusSafeButton now swallows the click of a caller's aria-disabled; the Config tests say why while dirty (testDirty, HU/EN). - F5/F11: every control measured live at 24 (mouse) and 44 (coarse) across every page; touch-target is a utility that wins over a caller's min-h-6; link variants carry it too; SegmentedToggle, Tabs, NavRail, menu rows, PriorityStepper, sliders, CheckRow, InnerInput, card links and the rest. - F9: DismissibleChip's label reaches the chip's 24; the Combobox chips are DismissibleChips. - F15: the "+N" / "More..." open state worded as it renders.
52 lines
2.1 KiB
TypeScript
52 lines
2.1 KiB
TypeScript
// @vitest-environment jsdom
|
||
//
|
||
// E28 audit: the Switch was a bare 36×20 track — under the 24 floor on a mouse, never the 44 touch box
|
||
// DESIGN.md A3 lists it under, and its name was optional, so the Plex-sync switch shipped nameless.
|
||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||
import { cleanup, fireEvent, render, screen } from "@testing-library/react";
|
||
|
||
import { Switch, SwitchRow } from "./form";
|
||
|
||
afterEach(cleanup);
|
||
|
||
describe("Switch", () => {
|
||
it("is a named switch whose own box meets the 24 floor and grows to the touch target", () => {
|
||
const onChange = vi.fn();
|
||
render(<Switch label="Dark mode" checked={false} onChange={onChange} />);
|
||
const sw = screen.getByRole("switch", { name: "Dark mode" });
|
||
expect(sw.getAttribute("aria-checked")).toBe("false");
|
||
expect(sw.className).toContain("h-6");
|
||
expect(sw.className).toContain("pointer-coarse:min-h-(--touch-target)");
|
||
fireEvent.click(sw);
|
||
expect(onChange).toHaveBeenCalledWith(true);
|
||
});
|
||
|
||
it("cannot be rendered without a name", () => {
|
||
// @ts-expect-error — `label` is required: a switch has no text of its own to be named by.
|
||
render(<Switch checked onChange={() => {}} />);
|
||
expect(screen.getByRole("switch")).toBeTruthy();
|
||
});
|
||
});
|
||
|
||
describe("SwitchRow", () => {
|
||
// Owner decision F12: a settings row toggles from its whole surface, as on iOS and in Material.
|
||
it("toggles from its text as well as from the switch, once per click", () => {
|
||
const onChange = vi.fn();
|
||
render(
|
||
<SwitchRow label="Dark mode" hint="Easier on the eyes" checked={false} onChange={onChange} />,
|
||
);
|
||
fireEvent.click(screen.getByText("Dark mode"));
|
||
expect(onChange).toHaveBeenCalledTimes(1);
|
||
fireEvent.click(screen.getByRole("switch", { name: "Dark mode" }));
|
||
expect(onChange).toHaveBeenCalledTimes(2);
|
||
expect(onChange).toHaveBeenLastCalledWith(true);
|
||
});
|
||
|
||
it("does nothing from its text while disabled", () => {
|
||
const onChange = vi.fn();
|
||
render(<SwitchRow label="Sync" checked onChange={onChange} disabled />);
|
||
fireEvent.click(screen.getByText("Sync"));
|
||
expect(onChange).not.toHaveBeenCalled();
|
||
});
|
||
});
|