Skip to content

Commit a2d4d5f

Browse files
committed
test(runtime): cover layer re-registration ordering churn
1 parent 4b1b0bd commit a2d4d5f

1 file changed

Lines changed: 77 additions & 0 deletions

File tree

packages/core/src/widgets/__tests__/layers.golden.test.ts

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,43 @@ describe("Layer Registry - Basic Operations", () => {
162162
assert.equal(topmost.id, "second");
163163
});
164164

165+
test("re-registering equal z-index layer moves it to top deterministically", () => {
166+
const registry = createLayerRegistry();
167+
168+
registry.register({
169+
id: "a",
170+
zIndex: 120,
171+
rect: { x: 0, y: 0, w: 10, h: 10 },
172+
backdrop: "none",
173+
modal: false,
174+
closeOnEscape: true,
175+
});
176+
registry.register({
177+
id: "b",
178+
zIndex: 120,
179+
rect: { x: 0, y: 0, w: 10, h: 10 },
180+
backdrop: "none",
181+
modal: false,
182+
closeOnEscape: true,
183+
});
184+
185+
const before = hitTestLayers(registry, 2, 2);
186+
assert.equal(before.layer?.id, "b");
187+
188+
registry.unregister("a");
189+
registry.register({
190+
id: "a",
191+
zIndex: 120,
192+
rect: { x: 0, y: 0, w: 10, h: 10 },
193+
backdrop: "none",
194+
modal: false,
195+
closeOnEscape: true,
196+
});
197+
198+
const after = hitTestLayers(registry, 2, 2);
199+
assert.equal(after.layer?.id, "a");
200+
});
201+
165202
test("getTopmost returns highest z-index layer", () => {
166203
const registry = createLayerRegistry();
167204

@@ -487,6 +524,46 @@ describe("Layer Hit Testing", () => {
487524
assert.equal(result3.layer.id, "modal1");
488525
assert.equal(result3.blocked, false);
489526
});
527+
528+
test("equal-z modal re-registration updates blocking order deterministically", () => {
529+
const registry = createLayerRegistry();
530+
531+
registry.register({
532+
id: "modal",
533+
zIndex: 140,
534+
rect: { x: 20, y: 0, w: 8, h: 6 },
535+
backdrop: "none",
536+
modal: true,
537+
closeOnEscape: true,
538+
});
539+
registry.register({
540+
id: "content",
541+
zIndex: 140,
542+
rect: { x: 0, y: 0, w: 12, h: 8 },
543+
backdrop: "none",
544+
modal: false,
545+
closeOnEscape: true,
546+
});
547+
548+
const before = hitTestLayers(registry, 3, 3);
549+
assert.equal(before.layer?.id ?? null, "content");
550+
assert.equal(before.blocked, false);
551+
552+
registry.unregister("modal");
553+
registry.register({
554+
id: "modal",
555+
zIndex: 140,
556+
rect: { x: 20, y: 0, w: 8, h: 6 },
557+
backdrop: "none",
558+
modal: true,
559+
closeOnEscape: true,
560+
});
561+
562+
const after = hitTestLayers(registry, 3, 3);
563+
assert.equal(after.layer, null);
564+
assert.equal(after.blocked, true);
565+
assert.equal(after.blockingLayer?.id ?? null, "modal");
566+
});
490567
});
491568

492569
/* ========== Positioning Tests ========== */

0 commit comments

Comments
 (0)