Skip to content

Commit

Permalink
✅ FIX broken test.
Browse files Browse the repository at this point in the history
  • Loading branch information
stefrado committed Mar 4, 2025
1 parent f07672a commit 17285a8
Showing 1 changed file with 36 additions and 24 deletions.
60 changes: 36 additions & 24 deletions src/open_inwoner/search/tests/test_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,30 +137,38 @@ def test_search_filter_configuration(self):
config = SiteConfiguration.get_solo()

def _assert_facet_checkbox_count(response, facet, count):
details_selector = f"details.filter[aria-label='Filter'] div.filter__list input[name='{facet}']"
details_selector = f"details.filter div.filter__list input[name='{facet}']"
checkboxes = response.pyquery(details_selector)

if count > 0:
# If we expect checkboxes, verify their count and details element
details_elements = response.pyquery(f"details.filter[aria-label='Filter'] div.filter__list")

self.assertEqual(len(checkboxes), count,
f"Incorrect number of {facet} checkboxes")

# If we expect checkboxes, verify their count and details element
details_elements = response.pyquery("details.filter div.filter__list")

self.assertEqual(
len(checkboxes), count, f"Incorrect number of {facet} checkboxes"
)

# Optionally, you could add a check for the counter
counter_text = response.pyquery(f"details.filter span.filter__counter")
self.assertEqual(len(counter_text), 1,
f"Filter counter for {facet} should exist")

counter_text = response.pyquery("details.filter span.filter__counter")
self.assertEqual(
len(counter_text), 1, f"Filter counter for {facet} should exist"
)

# Verify the counter shows the correct number of choices
expected_counter_text = f"({count})"
self.assertEqual(counter_text.text(), expected_counter_text,
f"Counter text should match number of {facet} checkboxes")
self.assertEqual(
counter_text.text(),
expected_counter_text,
f"Counter text should match number of {facet} checkboxes",
)
else:
# If no checkboxes expected, the entire details element should not be present
details_elements = response.pyquery(f"details.filter[aria-label='Filter']")
self.assertEqual(len(details_elements), 0,
f"Details element for {facet} should not be present")
details_elements = response.pyquery("details.filter")
self.assertEqual(
len(details_elements),
0,
f"Details element for {facet} should not be present",
)

with self.subTest("tags"):
config.search_filter_tags = False
Expand Down Expand Up @@ -324,14 +332,18 @@ def test_search_with_filters(self):
expect(checkbox).not_to_be_checked()

def _click_checkbox_for_name(page, name):
# Open the <details> element and click on it.
page.locator(".filter").filter(has=page.get_by_text(name)).click()

# our checkbox widget hides the <input> element and styles the <label> and a pseudo-element
# this a problem for playwright accessibility, so we find the label for the checkbox and click on the label like a user would
page.locator(".checkbox").filter(
has=page.get_by_role("checkbox", name=name)
).locator("label").click()
# Find the details element containing the label with the specific name
details_with_label = page.locator("details.filter").filter(
has=page.get_by_text(name, exact=True)
)

# Open the details element if it's not already open
if not details_with_label.locator("input[type='checkbox']").is_visible():
details_with_label.locator("summary").click()

# Find and click the checkbox label
checkbox_label = details_with_label.locator(f"label:has-text('{name}')")
checkbox_label.click()

def _test_search(checkbox_name, expected_text):
page.goto(self.live_reverse("search:search", params={"query": "summary"}))
Expand Down

0 comments on commit 17285a8

Please sign in to comment.