From 3607efe17e663bee2ae9d928730c908270126f93 Mon Sep 17 00:00:00 2001 From: Marco Ciampini Date: Fri, 25 Oct 2024 12:14:35 +0200 Subject: [PATCH] Update unit tests --- .../src/dropdown-menu-v2/test/index.tsx | 597 ++++++++++-------- 1 file changed, 345 insertions(+), 252 deletions(-) diff --git a/packages/components/src/dropdown-menu-v2/test/index.tsx b/packages/components/src/dropdown-menu-v2/test/index.tsx index cb674f27edaac..68d348b166997 100644 --- a/packages/components/src/dropdown-menu-v2/test/index.tsx +++ b/packages/components/src/dropdown-menu-v2/test/index.tsx @@ -22,23 +22,29 @@ describe( 'DropdownMenu', () => { // See https://www.w3.org/WAI/ARIA/apg/patterns/menu-button/ it( 'should follow the WAI-ARIA spec', async () => { render( - Open dropdown }> - Dropdown menu item - - - Dropdown submenu - - } - > + + + Open dropdown + + - Dropdown submenu item 1 - - - Dropdown submenu item 2 + Dropdown menu item - + + + + Dropdown submenu + + + + Dropdown submenu item 1 + + + Dropdown submenu item 2 + + + + ); @@ -94,10 +100,15 @@ describe( 'DropdownMenu', () => { describe( 'pointer and keyboard interactions', () => { it( 'should open and focus the menu when clicking the trigger', async () => { render( - Open dropdown }> - - Dropdown menu item - + + + Open dropdown + + + + Dropdown menu item + + ); @@ -117,12 +128,17 @@ describe( 'DropdownMenu', () => { it( 'should open and focus the first item when pressing the arrow down key on the trigger', async () => { render( - Open dropdown }> - - First item - - Second item - Third item + + + Open dropdown + + + + First item + + Second item + Third item + ); @@ -149,12 +165,17 @@ describe( 'DropdownMenu', () => { it( 'should open and focus the first item when pressing the space key on the trigger', async () => { render( - Open dropdown }> - - First item - - Second item - Third item + + + Open dropdown + + + + First item + + Second item + Third item + ); @@ -181,10 +202,15 @@ describe( 'DropdownMenu', () => { it( 'should close when pressing the escape key', async () => { render( - Open dropdown }> - - Dropdown menu item - + + + Open dropdown + + + + Dropdown menu item + + ); @@ -212,13 +238,15 @@ describe( 'DropdownMenu', () => { it( 'should close when clicking outside of the content', async () => { render( - Open dropdown } - > - - Dropdown menu item - + + + Open dropdown + + + + Dropdown menu item + + ); @@ -232,13 +260,15 @@ describe( 'DropdownMenu', () => { it( 'should close when clicking on a menu item', async () => { render( - Open dropdown } - > - - Dropdown menu item - + + + Open dropdown + + + + Dropdown menu item + + ); @@ -252,13 +282,15 @@ describe( 'DropdownMenu', () => { it( 'should not close when clicking on a menu item when the `hideOnClick` prop is set to `false`', async () => { render( - Open dropdown } - > - - Dropdown menu item - + + + Open dropdown + + + + Dropdown menu item + + ); @@ -272,13 +304,15 @@ describe( 'DropdownMenu', () => { it( 'should not close when clicking on a disabled menu item', async () => { render( - Open dropdown } - > - - Dropdown menu item - + + + Open dropdown + + + + Dropdown menu item + + ); @@ -292,33 +326,34 @@ describe( 'DropdownMenu', () => { it( 'should reveal submenu content when hovering over the submenu trigger', async () => { render( - Open dropdown } - > - - Dropdown menu item 1 - - - Dropdown menu item 2 - - - Dropdown submenu - - } - > + + + Open dropdown + + - Dropdown submenu item 1 + Dropdown menu item 1 - Dropdown submenu item 2 + Dropdown menu item 2 - - - Dropdown menu item 3 - + + + Dropdown submenu + + + + Dropdown submenu item 1 + + + Dropdown submenu item 2 + + + + + Dropdown menu item 3 + + ); @@ -343,33 +378,34 @@ describe( 'DropdownMenu', () => { it( 'should navigate menu items and subitems using the arrow, spacebar and enter keys', async () => { render( - Open dropdown } - > - - Dropdown menu item 1 - - - Dropdown menu item 2 - - - Dropdown submenu - - } - > + + + Open dropdown + + - Dropdown submenu item 1 + Dropdown menu item 1 - Dropdown submenu item 2 + Dropdown menu item 2 - - - Dropdown menu item 3 - + + + Dropdown submenu + + + + Dropdown submenu item 1 + + + Dropdown submenu item 2 + + + + + Dropdown menu item 3 + + ); @@ -479,25 +515,30 @@ describe( 'DropdownMenu', () => { setRadioValue( e.target.value ); }; return ( - Open dropdown }> - - - Radio item one - - - Radio item two - - + + + Open dropdown + + + + + Radio item one + + + Radio item two + + + ); }; @@ -556,28 +597,33 @@ describe( 'DropdownMenu', () => { it( 'should check radio items and keep the menu open when clicking (uncontrolled)', async () => { const onRadioValueChangeSpy = jest.fn(); render( - Open dropdown }> - - - onRadioValueChangeSpy( e.target.value ) - } - > - Radio item one - - - onRadioValueChangeSpy( e.target.value ) - } - > - Radio item two - - + + + Open dropdown + + + + + onRadioValueChangeSpy( e.target.value ) + } + > + Radio item one + + + onRadioValueChangeSpy( e.target.value ) + } + > + Radio item two + + + ); @@ -640,38 +686,43 @@ describe( 'DropdownMenu', () => { useState< boolean >(); return ( - Open dropdown }> - { - onCheckboxValueChangeSpy( - e.target.name, - e.target.value, - e.target.checked - ); - setItemOneChecked( e.target.checked ); - } } - > - Checkbox item one - - - { - onCheckboxValueChangeSpy( - e.target.name, - e.target.value, - e.target.checked - ); - setItemTwoChecked( e.target.checked ); - } } - > - Checkbox item two - + + + Open dropdown + + + { + onCheckboxValueChangeSpy( + e.target.name, + e.target.value, + e.target.checked + ); + setItemOneChecked( e.target.checked ); + } } + > + Checkbox item one + + + { + onCheckboxValueChangeSpy( + e.target.name, + e.target.value, + e.target.checked + ); + setItemTwoChecked( e.target.checked ); + } } + > + Checkbox item two + + ); }; @@ -763,35 +814,40 @@ describe( 'DropdownMenu', () => { const onCheckboxValueChangeSpy = jest.fn(); render( - Open dropdown }> - { - onCheckboxValueChangeSpy( - e.target.name, - e.target.value, - e.target.checked - ); - } } - > - Checkbox item one - - - { - onCheckboxValueChangeSpy( - e.target.name, - e.target.value, - e.target.checked - ); - } } - > - Checkbox item two - + + + Open dropdown + + + { + onCheckboxValueChangeSpy( + e.target.name, + e.target.value, + e.target.checked + ); + } } + > + Checkbox item one + + + { + onCheckboxValueChangeSpy( + e.target.name, + e.target.value, + e.target.checked + ); + } } + > + Checkbox item two + + ); @@ -881,10 +937,15 @@ describe( 'DropdownMenu', () => { it( 'should be modal by default', async () => { render( <> - Open dropdown }> - - Dropdown menu item - + + + Open dropdown + + + + Dropdown menu item + + @@ -910,13 +971,15 @@ describe( 'DropdownMenu', () => { it( 'should not be modal when the `modal` prop is set to `false`', async () => { render( <> - Open dropdown } - modal={ false } - > - - Dropdown menu item - + + + Open dropdown + + + + Dropdown menu item + + @@ -949,10 +1012,15 @@ describe( 'DropdownMenu', () => { describe( 'items prefix and suffix', () => { it( 'should display a prefix on regular items', async () => { render( - Open dropdown }> - Item prefix }> - Dropdown menu item - + + + Open dropdown + + + Item prefix }> + Dropdown menu item + + ); @@ -973,10 +1041,15 @@ describe( 'DropdownMenu', () => { it( 'should display a suffix on regular items', async () => { render( - Open dropdown }> - Item suffix }> - Dropdown menu item - + + + Open dropdown + + + Item suffix }> + Dropdown menu item + + ); @@ -997,14 +1070,19 @@ describe( 'DropdownMenu', () => { it( 'should display a suffix on radio items', async () => { render( - Open dropdown }> - - Radio item one - + + + Open dropdown + + + + Radio item one + + ); @@ -1025,14 +1103,19 @@ describe( 'DropdownMenu', () => { it( 'should display a suffix on checkbox items', async () => { render( - Open dropdown }> - - Checkbox item one - + + + Open dropdown + + + + Checkbox item one + + ); @@ -1055,9 +1138,14 @@ describe( 'DropdownMenu', () => { describe( 'typeahead', () => { it( 'should highlight matching item', async () => { render( - Open dropdown }> - One - Two + + + Open dropdown + + + One + Two + ); @@ -1088,9 +1176,14 @@ describe( 'DropdownMenu', () => { it( 'should keep previous focus when no matches are found', async () => { render( - Open dropdown }> - One - Two + + + Open dropdown + + + One + Two + );