Skip to content

Commit 9c802b7

Browse files
committed
refactor(test): split scroll-edge-state suite further, tighten unreachable branch
Splits container-selection.test.ts (562 LOC, over the 500-LOC extract tripwire) into four narrower suites by durable question: container existence, hidden-edge decisions, target resolution, and broad selection. Adds a scrollNode() fixture builder to cut inline node-literal repetition across the suite. Removes the "captureNodes resolves to undefined" test: the real contract (both production call sites, and captureScrollEdgeState's own captureNodes type) always resolves to a real array, so this exercised an unreachable branch behind a type-unsound cast. Tightens analyzeScrollEdgeState's parameter type to drop the now-provably-unreachable `| undefined`. Simplifies buildScrollContainerScope to filter out non-string identifier/label fields instead of mapping them to an empty-string placeholder — behaviorally identical (the placeholder always failed isUsefulScope's length check anyway) but removes a StringLiteral mutation surface that a synthetic fallback could never legitimately kill without coupling a test to Stryker's specific replacement text. Addresses further review feedback on PR #1474 (#1455).
1 parent 444ab66 commit 9c802b7

8 files changed

Lines changed: 401 additions & 587 deletions
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import { test } from 'vitest';
2+
import assert from 'node:assert/strict';
3+
import { capture, scrollNode, windowRoot } from './scroll-edge-state-fixtures.ts';
4+
5+
// ---------------------------------------------------------------------------
6+
// selectScrollContainer: broad selection (no target), multiple scrollables
7+
// ---------------------------------------------------------------------------
8+
9+
test('selectScrollContainer (broad): among containers with a hidden edge, the largest one wins', async () => {
10+
const nodes = [
11+
windowRoot(),
12+
scrollNode(1, {
13+
identifier: 'small-hidden',
14+
hiddenContentBelow: true,
15+
rect: { x: 0, y: 0, width: 100, height: 100 },
16+
}),
17+
scrollNode(2, {
18+
identifier: 'large-hidden',
19+
hiddenContentBelow: true,
20+
rect: { x: 0, y: 200, width: 300, height: 300 },
21+
}),
22+
];
23+
const state = await capture(nodes, 'bottom');
24+
assert.equal(state.scope, 'large-hidden');
25+
});
26+
27+
test('selectScrollContainer (broad): with no hidden edge anywhere, the LARGEST visible-in-viewport container wins, not just the first visible one', async () => {
28+
// Declaration order deliberately disagrees with area order (visible-small is
29+
// declared first) so a sort-less "first visible" implementation would pick
30+
// the wrong one; offscreen-huge is bigger still but must be excluded by the
31+
// visibility filter entirely.
32+
const nodes = [
33+
windowRoot(),
34+
scrollNode(1, { identifier: 'visible-small', rect: { x: 0, y: 0, width: 50, height: 50 } }),
35+
scrollNode(2, { identifier: 'visible-large', rect: { x: 0, y: 0, width: 200, height: 200 } }),
36+
scrollNode(3, {
37+
identifier: 'offscreen-huge',
38+
rect: { x: -5000, y: 0, width: 1000, height: 1000 },
39+
}),
40+
];
41+
const state = await capture(nodes, 'bottom');
42+
assert.equal(state.canScroll, false);
43+
assert.equal(state.scope, 'visible-large');
44+
});
45+
46+
test('selectScrollContainer (broad): when nothing is visible, the LARGEST scrollable overall is chosen regardless of declaration order', async () => {
47+
// offscreen-small is declared first, offscreen-large second — a sort-less
48+
// "first" fallback would wrongly pick offscreen-small.
49+
const nodes = [
50+
windowRoot(),
51+
scrollNode(1, {
52+
identifier: 'offscreen-small',
53+
rect: { x: -2000, y: 0, width: 100, height: 100 },
54+
}),
55+
scrollNode(2, {
56+
identifier: 'offscreen-large',
57+
rect: { x: -1000, y: 0, width: 300, height: 300 },
58+
}),
59+
];
60+
const state = await capture(nodes, 'bottom');
61+
assert.equal(state.scope, 'offscreen-large');
62+
});
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { test } from 'vitest';
2+
import assert from 'node:assert/strict';
3+
import { capture, scrollNode, windowRoot } from './scroll-edge-state-fixtures.ts';
4+
5+
// ---------------------------------------------------------------------------
6+
// analyzeScrollEdgeState (private) exercised through captureScrollEdgeState:
7+
// empty snapshot / no scrollable container
8+
// ---------------------------------------------------------------------------
9+
10+
test('captureScrollEdgeState: empty node list reports emptySnapshot and cannot scroll', async () => {
11+
const state = await capture([]);
12+
assert.deepEqual(state, { canScroll: false, emptySnapshot: true });
13+
});
14+
15+
test('captureScrollEdgeState: no scrollable node anywhere yields a null container', async () => {
16+
const nodes = [
17+
windowRoot(),
18+
{
19+
ref: 'e2',
20+
index: 1,
21+
parentIndex: 0,
22+
type: 'Button',
23+
label: 'Tap me',
24+
rect: { x: 20, y: 40, width: 100, height: 40 },
25+
},
26+
];
27+
const state = await capture(nodes);
28+
assert.equal(state.canScroll, false);
29+
assert.equal(state.emptySnapshot, false);
30+
assert.equal(state.scope, undefined);
31+
});
32+
33+
test('captureScrollEdgeState: a scrollable node with a zero-width rect does not count as a container', async () => {
34+
const nodes = [
35+
windowRoot(),
36+
scrollNode(1, { hiddenContentBelow: true, rect: { x: 0, y: 100, width: 0, height: 600 } }),
37+
];
38+
const state = await capture(nodes);
39+
assert.equal(state.canScroll, false);
40+
assert.equal(state.scope, undefined);
41+
});
42+
43+
test('captureScrollEdgeState: a scrollable node with a zero-height rect does not count as a container', async () => {
44+
const nodes = [
45+
windowRoot(),
46+
scrollNode(1, { hiddenContentBelow: true, rect: { x: 0, y: 100, width: 400, height: 0 } }),
47+
];
48+
const state = await capture(nodes);
49+
assert.equal(state.canScroll, false);
50+
assert.equal(state.scope, undefined);
51+
});

0 commit comments

Comments
 (0)