diff --git a/tests/Browser/CarouselTest.php b/tests/Browser/CarouselTest.php index 54f548ce..d6e0fe01 100644 --- a/tests/Browser/CarouselTest.php +++ b/tests/Browser/CarouselTest.php @@ -70,7 +70,11 @@ const FIRST_ITEM = '#carousel [data-md-carousel-item] >> nth=0'; function carouselShowcase(array $options = []) { + // Pinned rather than left to the host's own window: at a wide enough viewport the multi-browse + // row's 8 items (220px each) leave a remainder the keyline math does not reduce to zero the way + // it does here, so "scroll by exactly 2 slots" no longer lands item 2 on the open keyline. return visit('/material/carousel', $options) + ->resize(1280, 900) ->waitForEvent('networkidle') ->assertScript("typeof window.Alpine !== 'undefined'"); } @@ -164,14 +168,18 @@ it('brings a partly hidden item into focus when it is pressed, and leaves an ope }); it('scrolls instantly and leaves every item unmasked under reduced motion', function () { - carouselShowcase(['reducedMotion' => 'reduce']) - ->assertScript(onCarousel(0, <<<'JS' - root.querySelector('[aria-label="Next"]').click() - const arrived = at(1) - await pause(50) - return arrived && items.every((_, i) => inset(i) === 0) - && items.every((item) => Math.abs(item.getBoundingClientRect().width - size) < 1.5) - JS)); + // A click, then a separate read-only assertScript: assertScript retries its whole expression + // on a false result (this file's own comment above), and a click inside it would fire again on + // every retry, drifting the carousel one further item each time and never recovering. + $page = carouselShowcase(['reducedMotion' => 'reduce']); + + $page->script(onCarousel(0, 'root.querySelector(\'[aria-label="Next"]\').click()')); + + $page->assertScript(onCarousel(0, <<<'JS' + await pause(50) + return at(1) && items.every((_, i) => inset(i) === 0) + && items.every((item) => Math.abs(item.getBoundingClientRect().width - size) < 1.5) + JS)); }); it('brings an item cut off at the row\'s edge into view when it is pressed under reduced motion', function () {