The code cited its plan instead of saying why: `E28 review J4`, `(R6 S3b)`, `S1 justified…`,
`deep-review round 5`. That plan lives in the private ops repo, so for every reader of this one the
citation was noise, and a sentence whose subject was the plan step ("round 2 showed…") hid its
lesson behind an id. Each one is gone and the "why" kept: a bare citation is deleted, a sentence
carrying a lesson is reworded around it ("a later attempt showed…").
Measured (`scripts/audit_metrics.py`, product code): 652 lines in 270 files carried an epic code by
the definition the next commit holds (507 / 241 by the old, two-digit-only one) -> 0. Across all
code, tests, scripts and configs: ~1100 epic-code lines plus ~320 sprint/round ids.
Behaviour unchanged, checked mechanically: every changed .py file has the same AST once docstrings
are blanked; css/sh/toml/yml/json files are identical once comments are stripped; the only
non-comment changes in TS/JS are test titles, one description string in a contract table, and five
ESLint messages, whose text is all the gates snapshot diff holds. Not touched: Markdown (docs and
the changelog keep their history), Alembic migrations, TV episode notation (`S2 · E5`), DESIGN.md
ids (`C1`, `B4`, `S3h`), tracker ids (`SEC-16`, `DX-17`).
One stale claim fixed on the way: test_hls_reaper's docstring said the player checkpoints "every
10 s whether or not it is playing", which plex/stream.py calls wrong; it now says what the code does.
119 lines
4.4 KiB
TypeScript
119 lines
4.4 KiB
TypeScript
// @vitest-environment jsdom
|
|
//
|
|
// Rendering integration of the shared SegmentedToggle. Labels are plain props (no i18n); the active
|
|
// paint is CSS (`.pill[aria-pressed]`), so we assert the aria-pressed contract, not styling.
|
|
import { describe, it, expect, vi, afterEach } from "vitest";
|
|
import { render, screen, fireEvent, cleanup } from "@testing-library/react";
|
|
import SegmentedToggle from "./SegmentedToggle";
|
|
|
|
const OPTS = [
|
|
{ value: "or", label: "Any" },
|
|
{ value: "and", label: "All" },
|
|
] as const;
|
|
|
|
afterEach(cleanup);
|
|
|
|
describe("SegmentedToggle", () => {
|
|
it("renders one button per option with the given labels", () => {
|
|
render(<SegmentedToggle options={OPTS} value="or" onChange={vi.fn()} ariaLabel="Match" />);
|
|
expect(screen.getAllByRole("button").map((b) => b.textContent)).toEqual(["Any", "All"]);
|
|
});
|
|
|
|
it("marks exactly the active option aria-pressed", () => {
|
|
render(<SegmentedToggle options={OPTS} value="and" onChange={vi.fn()} ariaLabel="Match" />);
|
|
expect(screen.getByRole("button", { name: "Any" }).getAttribute("aria-pressed")).toBe("false");
|
|
expect(screen.getByRole("button", { name: "All" }).getAttribute("aria-pressed")).toBe("true");
|
|
});
|
|
|
|
it("clicking an option fires onChange with its value", () => {
|
|
const onChange = vi.fn();
|
|
render(<SegmentedToggle options={OPTS} value="or" onChange={onChange} ariaLabel="Match" />);
|
|
fireEvent.click(screen.getByRole("button", { name: "All" }));
|
|
expect(onChange).toHaveBeenCalledWith("and");
|
|
});
|
|
|
|
it("sits on the toolbar rung unless a panel's caption asks for the small one", () => {
|
|
render(<SegmentedToggle options={OPTS} value="or" onChange={vi.fn()} ariaLabel="Default" />);
|
|
const plain = screen.getByRole("group", { name: "Default" });
|
|
expect(plain.className).toContain("text-xs");
|
|
expect(plain.querySelector("button")!.className).toContain("h-7");
|
|
render(
|
|
<SegmentedToggle options={OPTS} value="or" onChange={vi.fn()} ariaLabel="Small" size="sm" />,
|
|
);
|
|
expect(screen.getByRole("group", { name: "Small" }).className).toContain("text-3xs");
|
|
});
|
|
|
|
it("exposes the group aria-label", () => {
|
|
render(<SegmentedToggle options={OPTS} value="or" onChange={vi.fn()} ariaLabel="Match mode" />);
|
|
expect(screen.getByRole("group", { name: "Match mode" })).toBeTruthy();
|
|
});
|
|
|
|
it("renders the caption when label is set", () => {
|
|
render(
|
|
<SegmentedToggle
|
|
options={OPTS}
|
|
value="or"
|
|
onChange={vi.fn()}
|
|
ariaLabel="Match"
|
|
label="Match"
|
|
/>,
|
|
);
|
|
// caption text plus the two option labels
|
|
expect(screen.getByText("Match")).toBeTruthy();
|
|
expect(screen.getAllByRole("button")).toHaveLength(2);
|
|
});
|
|
|
|
it("renders per-option icons and tooltips (scope-bar shape)", () => {
|
|
render(
|
|
<SegmentedToggle
|
|
ariaLabel="Scope"
|
|
fullWidth
|
|
size="md"
|
|
options={[
|
|
{ value: "my", label: "Mine", icon: <svg data-testid="ic-my" />, title: "Your subs" },
|
|
{ value: "all", label: "Library", icon: <svg data-testid="ic-all" /> },
|
|
]}
|
|
value="my"
|
|
onChange={vi.fn()}
|
|
/>,
|
|
);
|
|
expect(screen.getByTestId("ic-my")).toBeTruthy();
|
|
expect(screen.getByRole("button", { name: "Mine" }).getAttribute("title")).toBe("Your subs");
|
|
});
|
|
|
|
// The hint was a `title` on a non-focusable box: the pointer's tooltip, and nothing at all for a
|
|
// keyboard or screen-reader user (deep review, debt burn). It is the group's description now.
|
|
it("describes the group by its title, standalone and captioned alike", () => {
|
|
render(
|
|
<>
|
|
<SegmentedToggle
|
|
options={OPTS}
|
|
value="or"
|
|
onChange={vi.fn()}
|
|
ariaLabel="Show"
|
|
title="Results per batch"
|
|
/>
|
|
<SegmentedToggle
|
|
options={OPTS}
|
|
value="or"
|
|
onChange={vi.fn()}
|
|
ariaLabel="Match"
|
|
label="Match"
|
|
title="Any or all"
|
|
/>
|
|
</>,
|
|
);
|
|
expect(
|
|
screen.getByRole("group", { name: "Show", description: "Results per batch" }),
|
|
).toBeTruthy();
|
|
expect(screen.getByRole("group", { name: "Match", description: "Any or all" })).toBeTruthy();
|
|
});
|
|
|
|
it("adds no description without a title", () => {
|
|
render(<SegmentedToggle options={OPTS} value="or" onChange={vi.fn()} ariaLabel="Match" />);
|
|
expect(screen.getByRole("group", { name: "Match" }).hasAttribute("aria-describedby")).toBe(
|
|
false,
|
|
);
|
|
});
|
|
});
|