Skip to content

Commit 7abc432

Browse files
Copilotfrano-m
andauthored
Fix flaky anvil-catalog filter deselection test (#4771)
* Initial plan * fix(e2e): use name-based locator in selectFirstOption to avoid flakiness Agent-Logs-Url: https://github.com/DataBiosphere/data-browser/sessions/4f68d6fe-5720-4897-8b51-8b219e4687d6 Co-authored-by: frano-m <18710366+frano-m@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: frano-m <18710366+frano-m@users.noreply.github.com>
1 parent d7324b4 commit 7abc432

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

e2e/anvil-catalog/anvilcatalog-filters.spec.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,19 @@ async function openFilterDropdown(
242242
await expectFilterPopoverOpen(filters.page());
243243
}
244244

245+
/**
246+
* Returns a locator for a named filter item in the open filter popover.
247+
* @param page - Page.
248+
* @param optionName - The display name of the filter option.
249+
* @returns A locator for the matching filter item.
250+
*/
251+
function namedPopoverFilterItem(page: Page, optionName: string): Locator {
252+
return filterPopover(page)
253+
.getByTestId(TEST_IDS.FILTER_ITEM)
254+
.filter({ hasText: new RegExp(`^${escapeRegExp(optionName)}\\s*\\d+\\s*`) })
255+
.first();
256+
}
257+
245258
/**
246259
* Opens a sidebar filter dropdown, selects its first option, and returns the
247260
* option name. Waits for the item to be selected before returning.
@@ -260,7 +273,10 @@ async function selectFirstOption(
260273
const name = await extractOptionName(option);
261274
await expectFilterItemNotSelected(option);
262275
await option.click();
263-
await expectFilterItemSelected(option);
276+
// Re-locate by name rather than position since the list may re-sort after
277+
// selection, causing the positional `.first()` locator to resolve to a
278+
// different (non-selected) element.
279+
await expectFilterItemSelected(namedPopoverFilterItem(page, name));
264280
await page.keyboard.press(KEYBOARD_KEYS.ESCAPE);
265281
await expectFilterPopoverClosed(page);
266282
return name;

0 commit comments

Comments
 (0)