From 760a4bf7e13f6eaf0cbf6a488cfd67c6d02b3146 Mon Sep 17 00:00:00 2001 From: bchanot Date: Mon, 23 Nov 2026 10:33:48 +0100 Subject: [PATCH] test(tests): assert D25 property coverage, leader endpoints, no button off screen --- apps/app/tests/unit/anatomy.accessLabels.test.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/apps/app/tests/unit/anatomy.accessLabels.test.ts b/apps/app/tests/unit/anatomy.accessLabels.test.ts index 0e632282..e7a0d821 100644 --- a/apps/app/tests/unit/anatomy.accessLabels.test.ts +++ b/apps/app/tests/unit/anatomy.accessLabels.test.ts @@ -84,6 +84,7 @@ describe('placeAccessLabels', () => { const out = run(one({ x: 500, y: 100, w: 60, h: 40 }, 50)) expect(out.placed).toEqual([]) expect(out.overflow).toEqual([]) + expect(out.button).toBeNull() }) it('caps a long name at the maximum width', () => { @@ -175,6 +176,8 @@ const cross = (s: Segment, t: Segment) => { return turn(p, q, a) * turn(p, q, b) < 0 && turn(a, b, p) * turn(a, b, q) < 0 } function leaderHitsBox(s: Segment, b: Box): boolean { + const within = (x: number, y: number) => x > b.x && x < b.x + b.w && y > b.y && y < b.y + b.h + if (within(s.x1, s.y1) || within(s.x2, s.y2)) return true const c = [[b.x, b.y], [b.x + b.w, b.y], [b.x + b.w, b.y + b.h], [b.x, b.y + b.h]] const edges = c.map((v, i) => ({ x1: v[0], y1: v[1], x2: c[(i + 1) % 4][0], y2: c[(i + 1) % 4][1] })) return edges.some((e) => cross(s, e)) @@ -206,9 +209,17 @@ function checkInvariants(input: ReturnType, out: LabelLayout describe('placeAccessLabels invariants', () => { it('holds on 2000 seeded random layouts', () => { const r = rng(20261122) + const seen = { leader: 0, overflow: 0, button: 0 } for (let i = 0; i < 2000; i++) { const input = randomInput(r) - checkInvariants(input, placeAccessLabels({ ...input, button: BUTTON })) + const out = placeAccessLabels({ ...input, button: BUTTON }) + checkInvariants(input, out) + if (out.placed.some((p) => p.leader !== null)) seen.leader++ + if (out.overflow.length > 0) seen.overflow++ + if (out.button !== null) seen.button++ } + expect(seen.leader).toBeGreaterThan(0) + expect(seen.overflow).toBeGreaterThan(0) + expect(seen.button).toBeGreaterThan(0) }) })