From 9270ea9e5ec7ded9d6838623ef6136af7cad210b Mon Sep 17 00:00:00 2001 From: Elizabeth Wright Date: Mon, 30 Nov 2026 16:46:22 -0800 Subject: [PATCH] text fixes --- frontend/e2e/admin.ts | 123 +++++++++++++++++++++++++++--------------- 1 file changed, 81 insertions(+), 42 deletions(-) diff --git a/frontend/e2e/admin.ts b/frontend/e2e/admin.ts index 60e4d14..6f5abf1 100644 --- a/frontend/e2e/admin.ts +++ b/frontend/e2e/admin.ts @@ -1,5 +1,5 @@ // Helpers for the admin pages -import { expect, type Locator, type Page } from '@playwright/test' +import { expect, type Locator, type Page } from "@playwright/test"; /** * The User Management table row with this email. The table shows 10 users a page and a long run creates many users, so this pages @@ -7,48 +7,87 @@ import { expect, type Locator, type Page } from '@playwright/test' * "1-10 of 120" text to change, so a page is never skipped before it has rendered */ export const userRow = async (page: Page, email: string): Promise => { - const row = page.getByRole('row').filter({ hasText: email }) - const footer = page.locator('.v-data-table-footer__info') - const next = page.getByRole('button', { name: 'Next page' }) - await expect(async () => { - for (;;) { - if ((await row.count()) > 0) return - if (!(await next.isEnabled())) throw new Error(`${email} is not in the table yet`) - const before = await footer.innerText() - await next.click() - await expect(footer).not.toHaveText(before) - } - }).toPass({ timeout: 20_000 }) - return row -} + const row = page.getByRole("row").filter({ hasText: email }); + const footer = page.locator(".v-data-table-footer__info"); + const next = page.getByRole("button", { name: "Next page" }); + await expect(async () => { + for (;;) { + if ((await row.count()) > 0) return; + if (!(await next.isEnabled())) throw new Error(`${email} is not in the table yet`); + const before = await footer.innerText(); + await next.click(); + await expect(footer).not.toHaveText(before); + } + }).toPass({ timeout: 20_000 }); + return row; +}; /** - * Opens a Vuetify dropdown and picks the option with this exact text. Long lists only render the rows in view, so this scrolls the list - * until the option exists (a plain getByRole('option') would not find rows below the fold) + * Opens a Vuetify dropdown and picks the option with this exact text. Long lists (users and datasets, hundreds of rows after a long run) + * only render the rows in view, so the list is scrolled until the option exists (a plain getByRole('option') would not find rows below + * the fold). The lists are in creation order and tests pick the rows they have just created, so the end of the list is tried first */ export const pickOption = async (page: Page, field: Locator, name: string) => { - await field.click() - const option = page.getByRole('option', { name, exact: true }) - // The menu of the previous dropdown can still be fading out, and the newest one is last in the page - const list = page.getByRole('listbox').last() - await expect(list).toBeVisible() - // Scroll the list until the option is rendered or the end of the list is reached. The scroll position is set directly because mouse - // wheel events are unreliable (smooth scrolling) in headless Firefox. A frame is awaited after each step so the list can render its new rows - await expect(async () => { - await list.hover({ timeout: 2_000 }) - }).toPass({ timeout: 10_000 }) - for (let step = 0; step < 300 && (await option.count()) === 0; step++) { - const atEnd = await list.evaluate((el) => { - const before = el.scrollTop - el.scrollTop += 300 - return el.scrollTop === before - }) - await page.evaluate(() => new Promise((resolve) => requestAnimationFrame(() => requestAnimationFrame(resolve)))) - if (atEnd && (await option.count()) === 0) break - } - // A multi-select menu stays open after a pick, so only a single-select one is expected to close - const multiple = (await list.getAttribute('aria-multiselectable')) === 'true' - await option.click() - // Wait for the menu to close so it cannot cover the next field (which may also still be disabled until this pick settles) - if (!multiple) await expect(list).toBeHidden() -} + await field.click(); + // The menu of the previous dropdown can still be fading out, so the list is the one this field controls (aria-controls), not the last + // one in the page. The field is the role=combobox element itself (.v-field), or holds it (the whole .v-select) + const menuId = + (await field.getAttribute("aria-controls")) ?? + (await field.locator("[aria-controls]").first().getAttribute("aria-controls")); + if (!menuId) throw new Error("The dropdown field does not say which menu it controls"); + const list = page.locator(`[id="${menuId}"]`).getByRole("listbox"); + const option = list.getByRole("option", { name, exact: true }); + await expect(list).toBeVisible(); + // The menu can still be sliding into place (or be re-rendered) when it first appears, and another field can sit under it for a moment, + // so the hover is retried until the list is stable and on top + await expect(async () => { + await list.hover({ timeout: 2_000 }); + }).toPass({ timeout: 10_000 }); + + const frame = () => + page.evaluate(() => new Promise((resolve) => requestAnimationFrame(() => requestAnimationFrame(resolve)))); + const scrollToOption = async () => { + // The list only estimates its height until its rows are rendered, so one jump to the end lands short of it and each further jump + // lands closer. Done until the option shows up, the jumps stop getting anywhere, or there are enough of them + let before = -1; + for (let jump = 0; jump < 12 && (await option.count()) === 0; jump++) { + const height = await list.evaluate((el) => { + el.scrollTop = el.scrollHeight; + return el.scrollHeight; + }); + await frame(); + if (height === before && jump > 2) break; + before = height; + } + // Not at the end (a row picked from an older run, a short multi-select list): scan down from the top. The rows render a frame after + // a scroll, so a step is half the list's height, and the list can still be laying out on the first steps (nothing to scroll yet), so + // its end is only trusted after several steps in a row + let stuck = 0; + for (let step = 0; (await option.count()) === 0 && stuck < 5 && step < 400; step++) { + const moved = await list.evaluate((el, first) => { + const previous = el.scrollTop; + el.scrollTop = first ? 0 : el.scrollTop + Math.max(el.clientHeight / 2, 60); + return el.scrollTop !== previous; + }, step === 0); + stuck = moved || step === 0 ? 0 : stuck + 1; + await frame(); + } + }; + + // A multi-select menu stays open after a pick + if ((await list.getAttribute("aria-multiselectable")) === "true") { + await scrollToOption(); + await option.click(); + return; + } + // A single-select menu closes on a pick, and it must be closed so it cannot cover the next field (which may also be disabled until + // this pick settles). The list can re-render under the click (e.g. the users change when a dataset is chosen), which swallows it or + // scrolls the list back to the top, so the scrolling and the click are repeated until the menu is gone + await expect(async () => { + if (await list.isVisible()) { + await scrollToOption(); + await option.click({ timeout: 3_000 }); + } + await expect(list).toBeHidden({ timeout: 2_000 }); + }).toPass({ timeout: 20_000 }); +};