fix(e2e): assert sidebar expansion without a self-resolving locator

The migration smoke waited on `getByRole("button", { expanded: false })`
after clicking it. Playwright re-resolves that locator on every retry, so
once the clicked group flipped to expanded it matched the next collapsed
group instead, and the assertion could never pass. Count the remaining
collapsed groups and wait for that count to drop by one.
This commit is contained in:
Yuneng Jiang 2026-08-31 14:45:11 -07:00
parent 6abb85155a
commit 78e1c658b4
No known key found for this signature in database

View file

@ -35,11 +35,12 @@ async function expectRendered(page: Page) {
*/
async function clickSidebar(page: Page, segment: string) {
const link = sidebar(page).locator(`a[href$="/ui/${segment}"]`).first();
const collapsedGroups = sidebar(page).getByRole("button", { expanded: false });
for (let i = 0; i < 8 && !(await link.isVisible().catch(() => false)); i++) {
const collapsedGroup = sidebar(page).getByRole("button", { expanded: false }).first();
if (!(await collapsedGroup.isVisible().catch(() => false))) break;
await collapsedGroup.click();
await expect(collapsedGroup).toHaveAttribute("aria-expanded", "true");
const stillCollapsed = await collapsedGroups.count();
if (stillCollapsed === 0) break;
await collapsedGroups.first().click();
await expect(collapsedGroups).toHaveCount(stillCollapsed - 1);
}
await link.click();
}