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.
103 lines
3.7 KiB
TypeScript
103 lines
3.7 KiB
TypeScript
// @vitest-environment jsdom
|
|
//
|
|
// The shared chip-overflow measure core. jsdom has no layout engine — every offset* / clientWidth
|
|
// is 0 — so we stub those on the real ref'd nodes and assert the hook (a) reads the geometry off them
|
|
// (chip right edges, pill width, the gap between the last chip and the pill, and the lane's available
|
|
// width), (b) returns the caller's `decide` result, and (c) re-measures when `deps` changes.
|
|
import { describe, it, expect, afterEach } from "vitest";
|
|
import { useRef } from "react";
|
|
import { render, screen, cleanup, act } from "@testing-library/react";
|
|
import { useChipOverflowFit, type ChipRowGeometry } from "./useChipOverflowFit";
|
|
|
|
function stub(
|
|
el: HTMLElement,
|
|
props: Partial<Record<"offsetLeft" | "offsetWidth" | "clientWidth", number>>,
|
|
) {
|
|
for (const [k, v] of Object.entries(props)) {
|
|
Object.defineProperty(el, k, { configurable: true, get: () => v });
|
|
}
|
|
}
|
|
|
|
let lastGeom: ChipRowGeometry | null = null;
|
|
|
|
function Harness({ deps }: { deps: string }) {
|
|
const rowRef = useRef<HTMLDivElement | null>(null);
|
|
const chipRefs = useRef<Array<HTMLElement | null>>([]);
|
|
const pillRef = useRef<HTMLSpanElement | null>(null);
|
|
const visible = useChipOverflowFit<number>({
|
|
rowRef,
|
|
chipsRef: chipRefs,
|
|
pillRef,
|
|
deps,
|
|
initial: -1,
|
|
decide: (g) => {
|
|
lastGeom = g;
|
|
// A trivial policy: count the chips whose right edge fits the lane.
|
|
return g.chipRights.filter((r) => r <= g.avail).length;
|
|
},
|
|
});
|
|
return (
|
|
<div>
|
|
<div ref={rowRef} data-testid="row" />
|
|
<span
|
|
ref={(el) => {
|
|
chipRefs.current[0] = el;
|
|
}}
|
|
data-testid="chip0"
|
|
/>
|
|
<span
|
|
ref={(el) => {
|
|
chipRefs.current[1] = el;
|
|
}}
|
|
data-testid="chip1"
|
|
/>
|
|
<span ref={pillRef} data-testid="pill" />
|
|
<div data-testid="visible">{visible}</div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
afterEach(() => {
|
|
cleanup();
|
|
lastGeom = null;
|
|
});
|
|
|
|
describe("useChipOverflowFit", () => {
|
|
it("reads geometry off the refs and returns the decide() result; re-measures on deps change", () => {
|
|
const { rerender } = render(<Harness deps="a" />);
|
|
|
|
// First pass ran against jsdom's 0-sized boxes.
|
|
expect(lastGeom).toEqual({ avail: 0, chipRights: [0, 0], pillW: 0, gap: 0 });
|
|
|
|
// Give the boxes real geometry, then bump deps to force a re-measure.
|
|
stub(screen.getByTestId("row"), { clientWidth: 100 });
|
|
stub(screen.getByTestId("chip0"), { offsetLeft: 0, offsetWidth: 30 }); // right edge 30
|
|
stub(screen.getByTestId("chip1"), { offsetLeft: 36, offsetWidth: 30 }); // right edge 66
|
|
stub(screen.getByTestId("pill"), { offsetLeft: 72, offsetWidth: 20 }); // gap = 72 - 66 = 6
|
|
|
|
act(() => {
|
|
rerender(<Harness deps="b" />);
|
|
});
|
|
|
|
expect(lastGeom).toEqual({ avail: 100, chipRights: [30, 66], pillW: 20, gap: 6 });
|
|
// decide counted both chips (30 and 66 both <= 100).
|
|
expect(screen.getByTestId("visible").textContent).toBe("2");
|
|
});
|
|
|
|
it("drops a chip whose right edge exceeds the lane, via the caller's policy", () => {
|
|
const { rerender } = render(<Harness deps="a" />);
|
|
stub(screen.getByTestId("row"), { clientWidth: 40 });
|
|
stub(screen.getByTestId("chip0"), { offsetLeft: 0, offsetWidth: 30 }); // right edge 30 <= 40
|
|
stub(screen.getByTestId("chip1"), { offsetLeft: 36, offsetWidth: 30 }); // right edge 66 > 40
|
|
stub(screen.getByTestId("pill"), { offsetLeft: 72, offsetWidth: 20 });
|
|
|
|
act(() => {
|
|
rerender(<Harness deps="b" />);
|
|
});
|
|
|
|
expect(lastGeom).toEqual({ avail: 40, chipRights: [30, 66], pillW: 20, gap: 6 });
|
|
// Only chip0 (right edge 30) fits the 40-wide lane; chip1 (66) is dropped by the policy.
|
|
expect(screen.getByTestId("visible").textContent).toBe("1");
|
|
});
|
|
});
|