From e1398f15585a3dcc8f56fe68b8dde55d44dc4015 Mon Sep 17 00:00:00 2001 From: Natalie Pina <34781875+nataliepina@users.noreply.github.com> Date: Tue, 29 Aug 2023 15:07:38 -0500 Subject: [PATCH] feat: custom data-cy attribute for dropdownmenu (#993) BREAKING CHANGE: Previously the DropdownMenu may have been targeted for tests using "popover". Now it will need to be targeted with "dropdownmenu". --- packages/dropdownMenu/components/DropdownMenu.tsx | 15 +++++++++++++-- .../__snapshots__/DropdownMenu.test.tsx.snap | 8 ++++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/packages/dropdownMenu/components/DropdownMenu.tsx b/packages/dropdownMenu/components/DropdownMenu.tsx index 0916f334d..114d4ab89 100644 --- a/packages/dropdownMenu/components/DropdownMenu.tsx +++ b/packages/dropdownMenu/components/DropdownMenu.tsx @@ -93,6 +93,10 @@ export interface DropdownMenuProps { * Allows custom styling */ className?: string; + /** + * Human-readable selector used for writing tests + */ + "data-cy"?: string; } const defaultItemToString = ( @@ -116,7 +120,8 @@ const DropdownMenu = (props: DropdownMenuProps) => { Direction.TopCenter, Direction.TopLeft ], - trigger + trigger, + "data-cy": dataCy = "dropdownmenu" } = props; const handleSelection = ( @@ -172,6 +177,7 @@ const DropdownMenu = (props: DropdownMenuProps) => { footer={footer} key={`dropdown-${sectionIndex}`} sectionIndex={sectionIndex} + data-cy={`${dataCy}-section-${sectionIndex}`} > {childrenWithKeys} @@ -204,6 +210,7 @@ const DropdownMenu = (props: DropdownMenuProps) => { { }) }) ) : ( - )} diff --git a/packages/dropdownMenu/tests/__snapshots__/DropdownMenu.test.tsx.snap b/packages/dropdownMenu/tests/__snapshots__/DropdownMenu.test.tsx.snap index d8433b759..e4013de7e 100644 --- a/packages/dropdownMenu/tests/__snapshots__/DropdownMenu.test.tsx.snap +++ b/packages/dropdownMenu/tests/__snapshots__/DropdownMenu.test.tsx.snap @@ -15,6 +15,7 @@ exports[`Dropdown renders a closed dropdown 1`] = ` aria-haspopup="true" aria-label="open menu" class="css-1m1ecn3" + data-cy="dropdownmenu-button" data-toggle="true" role="button" type="button" @@ -42,6 +43,7 @@ exports[`Dropdown renders a dropdown with a max height 1`] = ` aria-haspopup="true" aria-label="open menu" class="css-1m1ecn3" + data-cy="dropdownmenu-button" data-toggle="true" role="button" type="button" @@ -70,6 +72,7 @@ exports[`Dropdown renders an open dropdown 1`] = ` aria-haspopup="true" aria-label="close menu" class="css-1m1ecn3" + data-cy="dropdownmenu-button" data-toggle="true" role="button" type="button" @@ -87,7 +90,7 @@ exports[`Dropdown renders an open dropdown 1`] = `
@@ -153,6 +156,7 @@ exports[`Dropdown renders an open dropdown with multiple sections 1`] = ` aria-haspopup="true" aria-label="close menu" class="css-1m1ecn3" + data-cy="dropdownmenu-button" data-toggle="true" role="button" type="button" @@ -170,7 +174,7 @@ exports[`Dropdown renders an open dropdown with multiple sections 1`] = `