Skip to content

test: make the AnVIL e2e tests assert where sonarjs/assertions-in-tests can see it (#5151) - #5157

Open
frano-m wants to merge 3 commits into
mainfrom
frano-m/5151-anvil-e2e-assertions
Open

frano-m wants to merge 3 commits into
mainfrom
frano-m/5151-anvil-e2e-assertions

Conversation

@frano-m

@frano-m frano-m commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Closes #5151

What changed

The AnVIL tab, URL, sort and file manifest e2e tests now follow the style of the cleaned-up specs, such as anvil-pagination.spec.ts:

  • one test.describe per spec, with short lowercase test names
  • tests generated per tab from ANVIL_TAB_LIST
  • every expect in the test body, with small helpers at the bottom of the spec

Shared locators now live in e2e/features/common/locators.ts: getCard, getFirstRowCell, getHeadingWithText and getTab.

testSortAzul and testBulkDownloadFileManifestWorkflow, and the helpers only they used, are deleted from e2e/testFunctions.ts. testTab, testUrl and the other functions the anvil-catalog specs call stay.

Fixes and improvements

Lint and failure reporting

  • Assertions the rule can see: sonarjs/assertions-in-tests (sonarjs 4.2.3) now finds an assertion in all 16 tests. The issue counted 15, but anvil-sort.spec.ts has 5 tests. The old specs get 16 reports.
  • No test.fail(): the sort and manifest tests used to fail only through test.fail(), which reports nothing useful. They now fail with an assertion error that says what went wrong. For example, a column missing from the tab config fails expect(unknownColumns).toEqual([]) and names the column.

Bugs the old tests hid

  • Files tab sort checked the wrong cell: after each sort, the test checked the first-row cell one column to the left. The column position skipped the unnamed first column, but the cell index did not. It now checks the sorted column's own cell.

  • Export form checkboxes were never ticked: makeMinimalExportRequest read the checkboxes with locator.all(), which doesn't wait. The Organism Type checkboxes render a moment later, so the step that ticks them ran on an empty list and never ran at all. The test now waits for the checkboxes before reading them, so it ticks them as intended.

  • Export table checkboxes could be read too early: the same race applied to the table rows. If they rendered late, the test would throw a bare TypeError, so the test now waits for the first table row first.

  • Index manifest card matched by a prefix: the test found the card through a substring match on "Download TSV Manifest". That text is the dataset page's card title. The index export page's card is "Download TSV Manifest for All Selected Data Files", so there is now a constant for that title: TITLE_TEXT_REQUEST_FILE_MANIFEST_SELECTED_DATA.

  • Sort could pass without checking anything: the sort test read the column headers without waiting for the table, so an empty header list could have passed. It now waits for the table's first cell first.

  • Firefox flake in the dataset manifest test: "displays download file manifest" in anvil-dataset.spec.ts sometimes failed on Firefox, including on main-based branches. The detail page rewrites its URL to add ?list=datasets after it loads. A click that lands before that rewrite can be overwritten by it, so the test waited until it timed out. goToDataset now waits for the ?list=datasets URL, as anvil-filter-navigation.spec.ts already does (findable-ui#1271).

Vague selectors made precise

  • Tab: an exact match on the tab's visible text, not a substring of any [role='tab'] text. It matches on text, not accessible name, because the selected tab's tooltip replaces its accessible name with the tab description.
  • Export method card: the link whose accessible name is the card title. It was an XPath to a MuiPaper-root ancestor plus the .MuiCardActionArea-root class.
  • Card heading: an exact level 3 heading by role. It was h3:has-text(...), which matches substrings.
  • First table row: the row holding the table-first-cell test ID. It was rowgroup.nth(1).
  • Export button: its test ID, not the link text "Export".
  • Manifest buttons: the "Prepare Manifest" and "Download Manifest" names now match exactly.

Less duplication

  • Shared card locators: anvil-dataset.spec.ts now uses the shared getCard and getHeadingWithText in place of its own copies.
  • Shared first-cell locator: anvil-filter-navigation.spec.ts now uses getFirstRowCell in place of its own copy.
  • testFunctions.ts: it now uses the shared getTab and getFirstRowCell, and deletes getTabByText and getFirstRowNthColumnCellLocator.

Why

eslint-plugin-sonarjs 4 adds sonarjs/assertions-in-tests, and it can't see an assertion inside an imported helper or behind test.fail(). Copies of these tests in repos on sonarjs 4 suppress the rule with eslint-disable comments, and fixing the tests here lets those copies drop the suppressions. This change is also a step toward retiring the legacy e2e/testFunctions.ts.

Assumptions I made

  • Scope: AnVIL CMG only. The anvil-catalog specs still use testTab, testUrl and testSortCatalog, which still calls test.fail(). They are left as they are: the anvil-catalog app is slated for deletion, and its catalog-style tests may move to the NCPI repo.
  • Test titles: the new short titles reset Playwright's history for these tests in CI reports.
  • Export request: the manifest test now really sends Organism Type ("Unspecified" plus "Human") with the .bam format. While I worked, that one manifest's first build failed in the browser with "Failed to fetch" for about 15 minutes, then cleared. Other first-time builds (.cram, .md5) poll and finish normally, with CORS headers on every response. I take it to be a temporary Azul failure, but that is unconfirmed without Azul logs. If it recurs, the test will fail at the "Download Manifest" step.
  • Type-aware linting: not used. The tests are restructured instead.

How to verify

  1. Check out the branch and run npm ci. Then run grep -n "test.fail" e2e/anvil/*.spec.ts: it prints nothing.

  2. Run npm install --no-save eslint-plugin-sonarjs@4.2.3, then npx eslint e2e/anvil --rule '{"sonarjs/assertions-in-tests": "error"}': it reports no errors. Run npm ci to restore version 3.

  3. Run npm run test:anvil-cmg: all 132 tests pass. Run npm run test:anvil-catalog: all 48 pass, which covers the edited testFunctions.ts.

  4. Break one check on purpose and run that spec, for example:

    • pass a wrong tab name to getTab in anvil-urls.spec.ts, or
    • append "X" to a column name in anvil-tabs-buttons.spec.ts.

    It fails with an assertion error. Revert the change.

Definition of done:

  • No test in e2e/anvil/ uses test.fail() to report a failed check: step 1.
  • sonarjs/assertions-in-tests 4.2.3 reports none of the tests, and none has an eslint-disable comment for it: step 2.
  • The AnVIL e2e suite passes, and a changed test still fails when its check fails: steps 3 and 4.

Plan

  1. Shared locators in e2e/features/common/locators.ts.
  2. Rewrite anvil-urls.spec.ts, with a loop over ANVIL_TAB_LIST and the assertions in the body.
  3. Rewrite anvil-tabs-buttons.spec.ts, keeping the same five tab transitions.
  4. Rewrite anvil-sort.spec.ts, with an assertion in place of the console.log and return false.
  5. Move the manifest workflow into the body of the manifest test in anvil-index-export-button.spec.ts.
  6. Delete the helpers testFunctions.ts no longer uses.
  7. Update e2e/testReadme.md.
  8. Verify: grep, sonarjs 4.2.3, lint, tsc, both e2e suites, and break checks.

Deviations

  • Sort wait: the sort test waits for the table's first cell before it reads the headers.
  • Review fixes: the Files tab cell offset, the waits before reading checkboxes with .all(), the exact tab and selector matches, and the new index manifest title constant.
  • Files the plan didn't name:
    • anvil-dataset.spec.ts and anvil-filter-navigation.spec.ts switched to the shared locators.
    • e2e/anvil/common/constants.tsx gained the index manifest title constant.
  • CI fix: goToDataset in anvil-dataset.spec.ts waits for the ?list=datasets URL, which fixes a Firefox flake that CI hit.
  • Simplify fixes: testFunctions.ts uses the shared locators and import type.

🤖 Generated with Claude Code

…sts` can see it (#5151)

Move the assertions of the AnVIL tab, URL, sort and manifest export e2e tests
into the test bodies, replace `test.fail()` with assertions, and share
tab, table, heading and export card locators from
`e2e/features/common/locators.ts`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@frano-m frano-m self-assigned this Dec 3, 2026
@frano-m
frano-m requested review from NoopDog and a balanced review from Copilot December 3, 2026 05:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The AnVIL-CMG end-to-end test refactor has no active review issues.

No open issues 🎉

What changed in this PR

Refactors AnVIL-CMG end-to-end tests so sonarjs/assertions-in-tests can detect assertions, addressing #5151 without changing the lint dependency.

Changes:

  • Moves assertions into test bodies and generates tab-specific tests from shared configuration.
  • Centralizes locators and improves sort-cell selection and export-checkbox waits.
  • Removes obsolete helpers while preserving AnVIL-Catalog support.
File Description
e2e/​testReadme.md Documents test organization and sort checks.
e2e/​testFunctions.ts Removes migrated helpers and adopts shared locators.
e2e/​features/​common/​locators.ts Adds shared card, heading, tab, and cell locators.
e2e/​anvil/​common/​constants.tsx Adds the exact index manifest card title.
e2e/​anvil/​anvil-urls.spec.ts Generates URL tests with direct assertions.
e2e/​anvil/​anvil-tabs-buttons.spec.ts Generates navigation tests with direct assertions.
e2e/​anvil/​anvil-sort.spec.ts Inlines sort assertions and corrects cell indexing.
e2e/​anvil/​anvil-index-export-button.spec.ts Inlines manifest workflow and waits for checkboxes.
e2e/​anvil/​anvil-filter-navigation.spec.ts Reuses the shared first-row cell locator.
e2e/​anvil/​anvil-dataset.spec.ts Reuses shared card and heading locators.

Review effort: Balanced

@frano-m
frano-m marked this pull request as ready for review December 3, 2026 05:35
@frano-m
frano-m requested a review from a team December 3, 2026 05:35
@frano-m
frano-m marked this pull request as draft December 3, 2026 05:35
frano-m and others added 2 commits December 3, 2026 15:40
… in the dataset e2e (#5151)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@frano-m
frano-m requested a balanced review from Copilot December 3, 2026 05:43
@frano-m
frano-m marked this pull request as ready for review December 3, 2026 05:46

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The AnVIL-CMG end-to-end test refactor has no active review issues.

No open issues 🎉

Review effort: Balanced

This branch has not been deployed

No deployments
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.

Make the AnVIL e2e tests assert where sonarjs/assertions-in-tests can see it

2 participants