Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 81 additions & 42 deletions frontend/e2e/admin.ts
Original file line number Diff line number Diff line change
@@ -1,54 +1,93 @@
// 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
* forward until the row shows up (a user invited while the page is open lands at the end). Each step waits for the footer's
* "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<Locator> => {
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 });

Check failure on line 92 in frontend/e2e/admin.ts

View workflow job for this annotation

GitHub Actions / E2E

[webkit] › e2e/admin-pages.spec.ts:147:3 › permission management › creates a permission from the dialog

1) [webkit] › e2e/admin-pages.spec.ts:147:3 › permission management › creates a permission from the dialog Error: locator.click: Timeout 3000ms exceeded. Call log: - waiting for locator('[id="menu-v-97"]').getByRole('listbox').getByRole('option', { name: 'E2E dataset mx3zk6e16hbn', exact: true }) 3 × locator resolved to <div tabindex="-2" role="option" aria-setsize="118" aria-posinset="118" aria-selected="false" class="v-list-item v-list-item--link v-theme--light v-list-item--density-default v-list-item--one-line rounded-0 v-list-item--variant-text">…</div> - attempting click action - waiting for element to be visible, enabled and stable - element is not stable - retrying click action - waiting for element to be visible, enabled and stable - element was detached from the DOM, retrying Call Log: - Timeout 20000ms exceeded while waiting on the predicate at admin.ts:92 90 | } 91 | await expect(list).toBeHidden({ timeout: 2_000 }); > 92 | }).toPass({ timeout: 20_000 }); | ^ 93 | }; 94 | at pickOption (/home/runner/work/data-visualizer/data-visualizer/frontend/e2e/admin.ts:92:8) at /home/runner/work/data-visualizer/data-visualizer/frontend/e2e/admin-pages.spec.ts:156:5
};
Loading