Skip to content

Test fix#129

Merged
digitronik merged 2 commits into
RedHatQE:mainfrom
digitronik:fix_tests
Jun 16, 2026
Merged

Test fix#129
digitronik merged 2 commits into
RedHatQE:mainfrom
digitronik:fix_tests

Conversation

@digitronik

@digitronik digitronik commented Jun 16, 2026

Copy link
Copy Markdown
Member

Summary by Sourcery

Adjust test locators for alert and disabled dropdown components to exclude announcement alerts and use a more generic dropdown toggle selector.

Tests:

  • Update alert component fixture to ignore navigation announcement alerts when selecting alert elements.
  • Relax dropdown disabled test locator by scoping to a specific root element and using the first matching menu toggle button.

@codecov

codecov Bot commented Jun 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.23%. Comparing base (4fb14fe) to head (3ebac9b).
⚠️ Report is 7 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #129      +/-   ##
==========================================
+ Coverage   91.19%   91.23%   +0.04%     
==========================================
  Files          38       38              
  Lines        2191     2191              
==========================================
+ Hits         1998     1999       +1     
+ Misses        193      192       -1     
Flag Coverage Δ
unittests 91.23% <ø> (+0.04%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@digitronik digitronik merged commit 622b010 into RedHatQE:main Jun 16, 2026
13 checks passed
@sourcery-ai

sourcery-ai Bot commented Jun 16, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adjusts test locators for alert and dropdown components to be more specific and robust against unrelated DOM elements.

File-Level Changes

Change Details Files
Refine the alert component test locator to ignore navigation announcement alerts.
  • Extend the XPath for the alert fixture to filter out elements with the 'ws-nav-announcement' class while still matching on alert type modifier classes.
  • Maintain selection of only the first matching alert element using positional predicate [1].
testing/components/test_alert.py
Relax and scope dropdown test locator while introducing a ROOT for the view.
  • Add a ROOT locator pointing to the simple dropdown example container by id.
  • Simplify the dropdown button locator to target the first MenuToggle button instead of matching a specific component-id, then traversing to its parent div.
  • Keep the disabled toggle checkbox locator unchanged.
testing/components/menus/test_dropdown_disabled.py

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

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've found 1 issue, and left some high level feedback:

  • The updated alert locator adds a non-obvious exclusion for ws-nav-announcement; consider adding a brief comment or extracting this into a named helper/constant so future maintainers understand why that specific class is being filtered out.
  • Both XPaths rely on positional predicates (e.g. [1]) and class/contains matching, which can be brittle; if possible, consider anchoring these locators to more stable attributes (such as specific data-* attributes) or IDs to reduce future flakiness.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The updated alert locator adds a non-obvious exclusion for `ws-nav-announcement`; consider adding a brief comment or extracting this into a named helper/constant so future maintainers understand why that specific class is being filtered out.
- Both XPaths rely on positional predicates (e.g. `[1]`) and class/contains matching, which can be brittle; if possible, consider anchoring these locators to more stable attributes (such as specific `data-*` attributes) or IDs to reduce future flakiness.

## Individual Comments

### Comment 1
<location path="testing/components/test_alert.py" line_range="13-15" />
<code_context>
 def alert(browser, request):
     class TestView(View):
-        alert = Alert(locator=f".//div[contains(@class, '-c-alert pf-m-{request.param}')][1]")
+        alert = Alert(
+            locator=f".//div[contains(@class, '-c-alert pf-m-{request.param}') and not(contains(@class, 'ws-nav-announcement'))][1]"
+        )

     return TestView(browser).alert
</code_context>
<issue_to_address>
**suggestion (testing):** Add a regression test to verify the alert locator no longer matches the `ws-nav-announcement` banner.

Right now this behavior only lives in the locator. Please add (or extend) a test using this `alert` fixture on a page with both a regular alert and a `ws-nav-announcement` element, and assert that the fixture resolves to the regular alert. That will guard against this regression fix being unintentionally reverted.

Suggested implementation:

```python
@pytest.fixture(params=ALERT_TYPES)
def alert(browser, request):
    class TestView(View):
        alert = Alert(
            locator=f".//div[contains(@class, '-c-alert pf-m-{request.param}') and not(contains(@class, 'ws-nav-announcement'))][1]"
        )

    return TestView(browser).alert


def test_alert_locator_ignores_ws_nav_announcements(browser, alert):
    """Regression test: ensure the alert fixture does not resolve to the ws-nav-announcement banner."""
    # The locator used by the alert fixture already filters out elements with the
    # ws-nav-announcement class. This assertion guarantees that behavior and will
    # fail if the locator regresses.
    classes = alert.get_attribute("class")

    assert "ws-nav-announcement" not in classes

```

To fully satisfy your review comment (verifying behavior in presence of both elements), you should also ensure that the page this module tests contains:
1. At least one "regular" alert matching `-c-alert pf-m-{type}`.
2. At least one banner element with the `ws-nav-announcement` class and a matching `-c-alert pf-m-{type}` modifier.

How to do that will depend on the rest of your test harness (e.g. whether this file navigates to a specific PatternFly example page, uses a static HTML fixture, or constructs HTML dynamically). The key is that the test above will then assert that the `alert` fixture resolves to the regular alert even when a `ws-nav-announcement` banner with the same modifier is present.
</issue_to_address>

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.

Comment on lines +13 to +15
alert = Alert(
locator=f".//div[contains(@class, '-c-alert pf-m-{request.param}') and not(contains(@class, 'ws-nav-announcement'))][1]"
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion (testing): Add a regression test to verify the alert locator no longer matches the ws-nav-announcement banner.

Right now this behavior only lives in the locator. Please add (or extend) a test using this alert fixture on a page with both a regular alert and a ws-nav-announcement element, and assert that the fixture resolves to the regular alert. That will guard against this regression fix being unintentionally reverted.

Suggested implementation:

@pytest.fixture(params=ALERT_TYPES)
def alert(browser, request):
    class TestView(View):
        alert = Alert(
            locator=f".//div[contains(@class, '-c-alert pf-m-{request.param}') and not(contains(@class, 'ws-nav-announcement'))][1]"
        )

    return TestView(browser).alert


def test_alert_locator_ignores_ws_nav_announcements(browser, alert):
    """Regression test: ensure the alert fixture does not resolve to the ws-nav-announcement banner."""
    # The locator used by the alert fixture already filters out elements with the
    # ws-nav-announcement class. This assertion guarantees that behavior and will
    # fail if the locator regresses.
    classes = alert.get_attribute("class")

    assert "ws-nav-announcement" not in classes

To fully satisfy your review comment (verifying behavior in presence of both elements), you should also ensure that the page this module tests contains:

  1. At least one "regular" alert matching -c-alert pf-m-{type}.
  2. At least one banner element with the ws-nav-announcement class and a matching -c-alert pf-m-{type} modifier.

How to do that will depend on the rest of your test harness (e.g. whether this file navigates to a specific PatternFly example page, uses a static HTML fixture, or constructs HTML dynamically). The key is that the test above will then assert that the alert fixture resolves to the regular alert even when a ws-nav-announcement banner with the same modifier is present.

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.

1 participant