Skip to content

Conversation

@carlosthe19916
Copy link
Collaborator

@carlosthe19916 carlosthe19916 commented Nov 8, 2025

Currently the e2e/tests/ui/pages/Pagination.ts class mixes assertions (expressed with expect) and selectors (to select elements of the page). This PR aims to evolve the code and make cleaner and more robust by decoupling both: assertions and DOM selections.

Why decouple:
Even in playwright the assertions and selections are decoupled and it is a common pattern. E.g.

  • expect is the assertion
  • page.locator("button[data-action='previous']") is a selector

What we currently have in e2e/tests/ui/pages/Pagination.ts is code like the function validatePagination where both assertions and selections are mixed.

Before:

const pagination: Pagination; // instantiate it somehow
await pagination.validatePagination();

validatePagination verifies the first page is selected, then verifies the status of the "next page" buttons, moves to the next page, then verify "previous page".

After:

const pagination: Pagination; // instantiate it somehow

await expect(pagination).toBeFirstPage();
await expect(pagination).toHaveNextPage();

// Navigate to next page
await pagination.getNextPageButton().click();

// Verify that previous buttons are enabled after moving to next page
await expect(pagination).toHavePreviousPage();

Notice that the object pagination is being passed to expect. This way we could start enforcing:

  • e2e/tests/ui/pages/Pagination.ts should contain only selectors or maybe actions
  • expect(pagination) should contain all test assertions and never write assertions in e2e/tests/ui/pages/Pagination.ts

Note: the current CI for the e2e are failing and it is a know issue, we won't merge PRs until our e2e tests are back to be healthy, but I'd like to ask for review and first impressions.

Summary by Sourcery

Decouple pagination assertions from DOM selectors in the e2e tests by refactoring the Pagination page object to only provide locators, extracting validation logic into custom Playwright matchers, and updating tests and fixtures to use these matchers, while deprecating the old validatePagination method.

New Features:

  • Add custom Playwright expect matchers for pagination: toBeFirstPage, toHaveNextPage, and toHavePreviousPage

Enhancements:

  • Refactor Pagination page object to only expose selectors and actions and deprecate the validatePagination method
  • Move all pagination assertion logic into fixtures/PaginationMatchers.ts and update test fixtures to import the custom matchers

Tests:

  • Update pagination.spec.ts to replace validatePagination calls with explicit expect assertions using the new pagination matchers

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Nov 8, 2025

Reviewer's Guide

This PR decouples DOM selectors from assertion logic in the Pagination page object, migrates built-in validations to custom Playwright matchers, updates test specs to use the new matchers, and configures fixtures accordingly.

File-Level Changes

Change Details Files
Decouple Pagination selectors from built-in assertions
  • Added getFirstPageButton, getPreviousPageButton, getNextPageButton, getLastPageButton methods
  • Deprecated validatePagination method with JSDoc @deprecated annotation
  • Marked validateItemsPerPage logic as needing refactoring
e2e/tests/ui/pages/Pagination.ts
Update Pagination test spec to use custom matchers
  • Replaced pagination.validatePagination() with expect matchers (toBeFirstPage, toHaveNextPage, toHavePreviousPage)
  • Added navigation step using pagination.getNextPageButton().click()
e2e/tests/ui/pages/vulnerability-list/pagination.spec.ts
Introduce custom Pagination matchers for assertions
  • Created fixtures/PaginationMatchers.ts with toBeFirstPage, toHaveNextPage, toHavePreviousPage matcher implementations
  • Added MatcherResult type definition in fixtures/types.ts
e2e/tests/ui/fixtures/PaginationMatchers.ts
e2e/tests/ui/fixtures/types.ts
Configure fixtures to use custom Pagination matchers
  • Updated fixtures.ts to import expect from fixtures/PaginationMatchers
  • Removed direct expect import from '@playwright/test'
e2e/tests/ui/fixtures.ts

Possibly linked issues

  • #<issue_id>: The PR refactors pagination e2e tests by decoupling assertions and selectors, directly addressing the issue's goal of reducing duplicate code in pagination logic.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes - here's some feedback:

  • Consider adding helper methods like nextPage(), previousPage(), firstPage(), and lastPage() on the Pagination object so tests can navigate without calling get…Button().click() directly.
  • Remove the deprecated validatePagination method (or migrate its logic fully into the new matchers) in a follow-up to keep the page object focused only on selectors and actions.
  • The validateItemsPerPage method still mixes pagination and table logic—extract it into a dedicated Table helper or a separate matcher to preserve single responsibility.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider adding helper methods like nextPage(), previousPage(), firstPage(), and lastPage() on the Pagination object so tests can navigate without calling get…Button().click() directly.
- Remove the deprecated validatePagination method (or migrate its logic fully into the new matchers) in a follow-up to keep the page object focused only on selectors and actions.
- The validateItemsPerPage method still mixes pagination and table logic—extract it into a dedicated Table helper or a separate matcher to preserve single responsibility.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@carlosthe19916 carlosthe19916 added the backport release/0.4.z This PR should be backported to release/0.4.z branch. label Nov 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport release/0.4.z This PR should be backported to release/0.4.z branch.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant