diff --git a/e2e/activity.spec.ts b/e2e/activity.spec.ts index 2982fbf0..47d56490 100644 --- a/e2e/activity.spec.ts +++ b/e2e/activity.spec.ts @@ -1,4 +1,4 @@ -import {expect, faults, mockBackend, setAppearance, test} from './fixtures'; +import {expect, faults, mockBackend, scrollIntoList, setAppearance, test} from './fixtures'; import {createMockApi} from '../src/api/mock'; import {test as browserTest, type Page} from '@playwright/test'; import {sha256} from '../src/api/hash'; @@ -167,10 +167,14 @@ test('the latency tile names a node that is unavailable and keeps its size', asy await page.addInitScript(() => localStorage.setItem('doona-mock-scenario', 'faults')); await page.goto('/#/activity'); const tile = page.locator('.rp-card', {hasText: 'Latency'}).first(); + // The value link appears once the nodes have loaded; before that the tile shows its placeholder. + await expect(tile.getByRole('link')).toHaveAccessibleName(/^\S+: \d/); await expect(tile.locator('.rp-light')).toHaveCount(0); const height = (await tile.boundingBox())!.height; await page.getByRole('button', {name: 'Node', exact: true}).click(); - await page.getByRole('menuitemradio').filter({hasText: 'jp-01'}).click(); + const jp = page.getByRole('menuitemradio').filter({hasText: 'jp-01'}); + await scrollIntoList(jp); + await jp.click(); await expect(tile.locator('.rp-light')).toHaveText('Unavailable'); expect((await tile.boundingBox())!.height).toBe(height); }); diff --git a/e2e/fixtures.ts b/e2e/fixtures.ts index f5972899..b543b4b7 100644 --- a/e2e/fixtures.ts +++ b/e2e/fixtures.ts @@ -99,6 +99,22 @@ export const test = base.extend<{storage: Record; signedIn: stri // The default demo has none. export const faults = {'doona-mock-scenario': 'faults'}; +// A long menu is a virtual list, which turns pointer events off on its items until 300ms after its last scroll event. +// Playwright's own scroll into view can land the click in that window, where the list swallows it and the menu stays +// open. This scrolls the item into view and returns once the list takes pointer events again. +export async function scrollIntoList(item: Locator) { + await item.evaluate(async el => { + let scroller = el.parentElement; + while (scroller && !/auto|scroll/.test(getComputedStyle(scroller).overflowY)) scroller = scroller.parentElement; + if (!scroller) return; + const before = scroller.scrollTop; + const scrolled = new Promise(resolve => scroller.addEventListener('scroll', () => resolve(), {once: true})); + el.scrollIntoView({block: 'nearest'}); + if (scroller.scrollTop !== before) await scrolled; + }); + await expect.poll(() => item.evaluate(el => getComputedStyle(el).pointerEvents)).not.toBe('none'); +} + // The selected item's detail: an aside beside the list on wide screens, a drawer below 1200px. // A phone keeps every column and scrolls the table sideways, the container around a native table and the grid itself // once virtualised; this brings the trailing columns into view. A virtualised grid turns pointer events off on its