Test fix#129
Conversation
for more information, see https://pre-commit.ci
Codecov Report✅ All modified and coverable lines are covered by tests. 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Reviewer's guide (collapsed on small PRs)Reviewer's GuideAdjusts test locators for alert and dropdown components to be more specific and robust against unrelated DOM elements. File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
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 specificdata-*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>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| alert = Alert( | ||
| locator=f".//div[contains(@class, '-c-alert pf-m-{request.param}') and not(contains(@class, 'ws-nav-announcement'))][1]" | ||
| ) |
There was a problem hiding this comment.
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 classesTo fully satisfy your review comment (verifying behavior in presence of both elements), you should also ensure that the page this module tests contains:
- At least one "regular" alert matching
-c-alert pf-m-{type}. - At least one banner element with the
ws-nav-announcementclass 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.
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: