Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 30, 2026

Reviewers

@frano-m

Closes #4656.

Changes

Flaky tests in testDeselectFiltersThroughSearchBar caused by missing wait states and static CSS selectors that don't auto-retry.

Modified

  • e2e/testFunctions.ts: Added waitForLoadState("load") after filter selection and replaced :checked CSS selector with expect().toBeChecked() pattern

Issue 1: Missing wait after filter selection

// Before
await firstFilterOptionLocator.click();
await page.locator("body").click();

// After
await firstFilterOptionLocator.click();
await page.waitForLoadState("load");
await page.locator("body").click();

Issue 2: Static CSS selector race condition

// Before - no auto-retry, fails if not checked immediately
await filterOptionLocator
  .locator("input[type='checkbox']:checked")
  .first()
  .click();

// After - auto-retries until checked state is confirmed
const checkboxLocator = filterOptionLocator.getByRole("checkbox");
await expect(checkboxLocator).toBeChecked();
await checkboxLocator.click();

Now matches working pattern in testFilterTags function.

Definition of Done (from ticket)

  • Add page.waitForLoadState("load") after filter selection in testDeselectFiltersThroughSearchBar
  • Replace :checked CSS selector with expect(checkbox).toBeChecked() pattern
  • Tests pass consistently across multiple CI runs

QA steps (optional)

Run affected tests multiple times to verify no flakiness:

  • e2e/anvil-catalog/anvilcatalog-filters.spec.ts:46
  • e2e/anvil/anvil-filters.spec.ts:139

Known Issues

None.

Original prompt

This section details on the original issue you should resolve

<issue_title>Fix flaky filter deselection tests - missing wait states and race conditions</issue_title>
<issue_description>## Summary

Tests testDeselectFiltersThroughSearchBar and testFilterTags are flaky due to missing wait states and race conditions when interacting with filter checkboxes.

Affected Tests

  • e2e/anvil-catalog/anvilcatalog-filters.spec.ts:46 - "Check that deselecting filters through the 'Search all Filters' textbox works correctly on the Consortia tab"
  • e2e/anvil/anvil-filters.spec.ts:139 - "Check that the filter tags match the selected filter for an arbitrary filter on the BioSamples tab"

Root Cause Analysis

Issue 1: testDeselectFiltersThroughSearchBar (e2e/testFunctions.ts:764-801)

  1. Missing waitForLoadState("load") after selecting the filter - Lines 779-780:

    await firstFilterOptionLocator.click();
    await page.locator("body").click();  // No wait after filter selection!

    Compare with the working testFilterTags function (lines 643-645) which has an explicit wait:

    await firstFilterOptionLocator.getByRole("checkbox").click();
    await page.waitForLoadState("load");  // ← Has explicit wait
    await page.locator("body").click();
  2. No wait for checkbox state before using :checked selector - Lines 793-796 use a static CSS selector:

    await filterOptionLocator
      .locator("input[type='checkbox']:checked")  // ← Race condition!
      .first()
      .click();

    The :checked CSS selector doesn't auto-retry waiting for state changes like Playwright's expect(locator).toBeChecked() would.

Issue 2: testFilterTags (e2e/testFunctions.ts:625-661)

The local failures on BioSamples tab suggest timing issues with filter tag visibility/removal after interactions.

Recommended Fix

For testDeselectFiltersThroughSearchBar:

// After line 779, add waitForLoadState:
await firstFilterOptionLocator.click();
await page.waitForLoadState("load");  // ADD THIS
await page.locator("body").click();

// Replace lines 793-796 with explicit state wait:
const checkboxLocator = filterOptionLocator.getByRole("checkbox");
await expect(checkboxLocator).toBeChecked();  // Wait for checked state
await checkboxLocator.click();

Acceptance Criteria

  • Add page.waitForLoadState("load") after filter selection in testDeselectFiltersThroughSearchBar
  • Replace :checked CSS selector with expect(checkbox).toBeChecked() pattern
  • Tests pass consistently across multiple CI runs</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

… condition

Co-authored-by: frano-m <18710366+frano-m@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix flaky filter deselection tests with added wait states Fix flaky filter deselection tests - add wait states and replace CSS selector race conditions Jan 30, 2026
Copilot AI requested a review from frano-m January 30, 2026 04:42
@frano-m frano-m changed the title Fix flaky filter deselection tests - add wait states and replace CSS selector race conditions fix: flaky filter deselection tests - add wait states and replace css selector race conditions (#4656) Jan 30, 2026
Copy link
Contributor

@frano-m frano-m left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @copilot! 🦞

@frano-m frano-m marked this pull request as ready for review January 30, 2026 04:58
@NoopDog NoopDog merged commit 1fc0b45 into main Jan 30, 2026
3 checks passed
@frano-m frano-m deleted the copilot/fix-flaky-filter-tests branch January 30, 2026 04:59
@frano-m frano-m changed the title fix: flaky filter deselection tests - add wait states and replace css selector race conditions (#4656) Fix flaky filter deselection tests - add wait states and replace CSS selector race conditions Jan 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix flaky filter deselection tests - missing wait states and race conditions

3 participants