@@ -137,8 +137,12 @@ def test_search_filter_configuration(self):
137
137
config = SiteConfiguration .get_solo ()
138
138
139
139
def _assert_facet_checkbox_count (response , facet , count ):
140
- controls = response .pyquery (f"input[form='search-form'][name='{ facet } ']" )
141
- self .assertEqual (len (controls ), count )
140
+ details_selector = f"details.filter div.filter__list input[name='{ facet } ']"
141
+ checkboxes = response .pyquery (details_selector )
142
+
143
+ self .assertEqual (
144
+ len (checkboxes ), count , f"Incorrect number of { facet } checkboxes"
145
+ )
142
146
143
147
with self .subTest ("tags" ):
144
148
config .search_filter_tags = False
@@ -301,16 +305,35 @@ def test_search_with_filters(self):
301
305
expect (checkbox ).to_be_enabled ()
302
306
expect (checkbox ).not_to_be_checked ()
303
307
304
- def _click_checkbox_for_name (page = page , name = "" ):
305
- # first open de <details> through the summary
306
- page .locator (".filter" ).filter (
307
- has = page .get_by_role ("checkbox" , name = name )
308
- ).locator (".filter__title" ).click ()
309
- # our checkbox widget hides the <input> element and styles the <label> and a pseudo-element
310
- # this a problem for playwright accessibility, so we find the label for the checkbox and click on the label like a user would
311
- page .locator (".checkbox" ).filter (
312
- has = page .get_by_role ("checkbox" , name = name )
313
- ).locator ("label" ).click ()
308
+ def _click_checkbox_for_name (page , name ):
309
+ # Find the details element containing the label
310
+ details_with_label = page .locator ("details.filter" ).filter (
311
+ has = page .get_by_text (name , exact = True )
312
+ )
313
+
314
+ # If exact match fails, try partial match
315
+ if details_with_label .count () == 0 :
316
+ details_with_label = page .locator ("details.filter" ).filter (
317
+ has = page .get_by_text (name )
318
+ )
319
+
320
+ # Ensure the details element is open and scrolled into view
321
+ summary = details_with_label .locator ("summary" )
322
+ summary .scroll_into_view_if_needed ()
323
+ summary .click ()
324
+
325
+ # Find the checkbox input
326
+ checkbox_input = (
327
+ details_with_label .locator (
328
+ f"input[type='checkbox'] + label:has-text('{ name } ')"
329
+ )
330
+ .locator (".." )
331
+ .locator ("input[type='checkbox']" )
332
+ )
333
+
334
+ # Scroll the checkbox into view and click
335
+ checkbox_input .scroll_into_view_if_needed ()
336
+ checkbox_input .click ()
314
337
315
338
def _test_search (checkbox_name , expected_text ):
316
339
page .goto (self .live_reverse ("search:search" , params = {"query" : "summary" }))
0 commit comments