2424from e2e_utils import get_pivot , open_settings_popover
2525
2626
27+ def click_menu_item (locator ) -> None :
28+ """Click a menu item reliably even when the popover clips its viewport."""
29+ locator .evaluate (
30+ "el => { el.scrollIntoView({ block: 'center', inline: 'nearest' }); el.click(); }"
31+ )
32+
33+
2734def test_header_menu_sort_key_asc (page_at_app : Page ):
2835 """Sorting A->Z via header menu reorders rows alphabetically."""
2936 page = page_at_app
@@ -34,16 +41,16 @@ def test_header_menu_sort_key_asc(page_at_app: Page):
3441 menu = page .get_by_test_id ("header-menu-Region" )
3542 expect (menu ).to_be_visible (timeout = 5000 )
3643
37- menu .get_by_test_id ("header-sort-key-asc" ).evaluate ("el => el.click()" )
38-
39- expect (container .get_by_test_id ("pivot-row-header" ).first ).to_have_text (
40- "East" , timeout = 10000
41- )
42-
43- row_headers = [
44+ row_headers_before = [
4445 h .inner_text () for h in container .get_by_test_id ("pivot-row-header" ).all ()
4546 ]
46- assert row_headers == sorted (row_headers ), f"Rows not sorted A->Z: { row_headers } "
47+ expected_headers = sorted (row_headers_before )
48+
49+ click_menu_item (menu .get_by_test_id ("header-sort-key-asc" ))
50+
51+ expect (container .get_by_test_id ("pivot-row-header" )).to_have_text (
52+ expected_headers , timeout = 10000
53+ )
4754
4855
4956def test_header_menu_sort_key_desc (page_at_app : Page ):
@@ -59,21 +66,14 @@ def test_header_menu_sort_key_desc(page_at_app: Page):
5966 row_headers_before = [
6067 h .inner_text () for h in container .get_by_test_id ("pivot-row-header" ).all ()
6168 ]
69+ expected_headers = sorted (row_headers_before , reverse = True )
6270 sort_button = menu .get_by_test_id ("header-sort-key-desc" )
63- sort_button . evaluate ( "el => el.click()" )
71+ click_menu_item ( sort_button )
6472
65- expect (container .get_by_test_id ("pivot-row-header" ). first ).to_have_text (
66- "West" , timeout = 10000
73+ expect (container .get_by_test_id ("pivot-row-header" )).to_have_text (
74+ expected_headers , timeout = 10000
6775 )
6876
69- row_headers = [
70- h .inner_text () for h in container .get_by_test_id ("pivot-row-header" ).all ()
71- ]
72- assert row_headers != row_headers_before
73- assert row_headers == sorted (
74- row_headers , reverse = True
75- ), f"Rows not sorted Z->A: { row_headers } "
76-
7777
7878def test_header_menu_sort_by_value (page_at_app : Page ):
7979 """Sorting by value via header menu reorders rows by aggregated measure."""
@@ -88,11 +88,19 @@ def test_header_menu_sort_by_value(page_at_app: Page):
8888 row_headers_before = [
8989 h .inner_text () for h in container .get_by_test_id ("pivot-row-header" ).all ()
9090 ]
91- menu .get_by_test_id ("header-sort-value-desc" ).evaluate ("el => el.click()" )
92-
93- expect (container .get_by_test_id ("pivot-row-header" ).first ).to_have_text (
94- "South" , timeout = 10000
91+ click_menu_item (menu .get_by_test_id ("header-sort-value-desc" ))
92+ value_field = page .get_by_test_id ("header-sort-value-field" )
93+ expect (value_field ).to_be_visible (timeout = 5000 )
94+ value_field .select_option ("Revenue" )
95+ col_key = page .get_by_test_id ("header-sort-col-key" )
96+ expect (col_key ).to_be_visible (timeout = 5000 )
97+ col_key .select_option ("" )
98+
99+ expect (container .get_by_test_id ("pivot-row-header" )).to_have_text (
100+ ["South" , "North" , "West" , "East" ],
101+ timeout = 10000 ,
95102 )
103+
96104 row_headers_after = [
97105 h .inner_text () for h in container .get_by_test_id ("pivot-row-header" ).all ()
98106 ]
@@ -176,12 +184,12 @@ def test_header_menu_show_values_as_pct(page_at_app: Page):
176184
177185 trigger = container .get_by_test_id ("header-menu-trigger-Revenue" ).first
178186 expect (trigger ).to_be_visible (timeout = 5000 )
179- trigger .click ()
187+ trigger .click (force = True )
180188
181- display_group = container .get_by_test_id ("header-menu-display" )
189+ display_group = page .get_by_test_id ("header-menu-display" )
182190 expect (display_group ).to_be_visible (timeout = 5000 )
183191
184- container .get_by_test_id ("header-display-pct_of_total" ).click ()
192+ page .get_by_test_id ("header-display-pct_of_total" ).click (force = True )
185193
186194 cells = container .get_by_test_id ("pivot-data-cell" )
187195 expect (cells .first ).to_contain_text ("%" , timeout = 10000 )
0 commit comments