Skip to content

Commit 0555cf3

Browse files
committed
test: target image element in zoom and close tests
Zoom gestures and double-click zoom should target the slide image, not the slide container or portal backdrop. Pointer events on .yarll__slide and .yarll__portal trigger backdrop close, which races with the exit animation fallback timeout on slower CI runners (Windows). Also make expectLightboxToBeClosed resilient to the portal already being unmounted by the fallback timeout before transitionEnd can be fired.
1 parent a3dff2d commit 0555cf3

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

test/Lightbox.spec.tsx

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ async function testNavigation(
7070
await expectLightboxToBeClosed();
7171
}
7272

73+
// Pointer events on .yarll__slide and .yarll__portal trigger backdrop close,
74+
// so zoom and gesture tests must target the slide image element instead.
75+
//
76+
// The portal exit animation has a fallback timeout that resolves without
77+
// transitionEnd (which never fires in jsdom). expectLightboxToBeClosed
78+
// handles the portal already being unmounted before transitionEnd is fired.
7379
describe("Lightbox", () => {
7480
it("supports mouse navigation", async () => {
7581
await testNavigation(clickButtonPrev, clickButtonNext, clickButtonClose);
@@ -171,7 +177,7 @@ describe("Lightbox", () => {
171177

172178
renderLightbox({ controller: { closeOnPullUp: false } });
173179

174-
await pointerSwipe(user, getCurrentSlide(), 0, -120);
180+
await pointerSwipe(user, getCurrentSlideImage(), 0, -120);
175181
await expectLightboxToBeOpen();
176182
});
177183

@@ -180,7 +186,7 @@ describe("Lightbox", () => {
180186

181187
renderLightbox({ controller: { closeOnPullDown: false } });
182188

183-
await pointerSwipe(user, getCurrentSlide(), 0, 120);
189+
await pointerSwipe(user, getCurrentSlideImage(), 0, 120);
184190
await expectLightboxToBeOpen();
185191
});
186192

@@ -465,7 +471,7 @@ describe("Lightbox", () => {
465471

466472
renderLightbox();
467473

468-
const target = getCurrentSlide();
474+
const target = getCurrentSlideImage();
469475

470476
await user.pointer([
471477
{ keys: "[TouchA>]", target, coords: { x: 100, y: 100 } },
@@ -496,7 +502,7 @@ describe("Lightbox", () => {
496502

497503
renderLightbox();
498504

499-
const target = getCurrentSlide();
505+
const target = getCurrentSlideImage();
500506

501507
await user.pointer([
502508
{ keys: "[TouchA>]", target, coords: { x: 100, y: 100 } },
@@ -538,11 +544,11 @@ describe("Lightbox", () => {
538544

539545
renderLightbox();
540546

541-
await user.dblClick(getController());
547+
await user.dblClick(getCurrentSlideImage());
542548
expectToBeZoomedIn();
543549

544550
for (let i = 0; i < 3; i += 1) {
545-
await user.dblClick(getController());
551+
await user.dblClick(getCurrentSlideImage());
546552
}
547553
expectToBeZoomedOut();
548554
});
@@ -552,7 +558,7 @@ describe("Lightbox", () => {
552558

553559
renderLightbox({ zoom: { disabled: true } });
554560

555-
await user.dblClick(getController());
561+
await user.dblClick(getCurrentSlideImage());
556562
expectToBeZoomedOut();
557563
});
558564

test/test-utils.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,12 @@ export async function expectLightboxToBeOpen() {
124124
}
125125

126126
export async function expectLightboxToBeClosed() {
127-
await act(async () => {
128-
fireEvent.transitionEnd(getController());
129-
});
127+
const controller = querySelector(".yarll__portal");
128+
if (controller) {
129+
await act(async () => {
130+
fireEvent.transitionEnd(controller);
131+
});
132+
}
130133

131134
expect(querySelector(".yarll__portal")).toBeNull();
132135
}

0 commit comments

Comments
 (0)