From 8205d48cb214f77139f3b061c968bb8d2cb5bd2f Mon Sep 17 00:00:00 2001 From: Aleksandra Danilina Date: Wed, 9 Aug 2023 15:36:57 +0200 Subject: [PATCH] test: Add more tests --- .../button-dropdown-accessibility.test.tsx | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/button-dropdown/__tests__/button-dropdown-accessibility.test.tsx b/src/button-dropdown/__tests__/button-dropdown-accessibility.test.tsx index 32d0818681..40c82ea1d6 100644 --- a/src/button-dropdown/__tests__/button-dropdown-accessibility.test.tsx +++ b/src/button-dropdown/__tests__/button-dropdown-accessibility.test.tsx @@ -89,12 +89,31 @@ const items: ButtonDropdownProps.Items = [ expect(menuElement.getElement()).toHaveAccessibleName('Custom label'); }); - it('does not label dropdown with icon trigger', () => { + it('does not auto-label dropdown with icon trigger', () => { const wrapper = renderButtonDropdown({ ...props, variant: 'icon' }); wrapper.openDropdown(); const menuElement = wrapper.findOpenDropdown()!.find('[role="menu"]')!; expect(menuElement.getElement()).not.toHaveAttribute('aria-labelledby'); }); + it('passes aria-label to icon trigger', () => { + const wrapper = renderButtonDropdown({ ...props, variant: 'icon', ariaLabel: 'Button trigger' }); + wrapper.openDropdown(); + const menuElement = wrapper.findOpenDropdown()!.find('[role="menu"]')!; + expect(menuElement.getElement()).toHaveAccessibleName('Button trigger'); + }); + + it('does not auto-label dropdown with inline icon trigger', () => { + const wrapper = renderButtonDropdown({ ...props, variant: 'inline-icon' }); + wrapper.openDropdown(); + const menuElement = wrapper.findOpenDropdown()!.find('[role="menu"]')!; + expect(menuElement.getElement()).not.toHaveAttribute('aria-labelledby'); + }); + it('passes aria-label to inline icon trigger', () => { + const wrapper = renderButtonDropdown({ ...props, variant: 'inline-icon', ariaLabel: 'Button trigger' }); + wrapper.openDropdown(); + const menuElement = wrapper.findOpenDropdown()!.find('[role="menu"]')!; + expect(menuElement.getElement()).toHaveAccessibleName('Button trigger'); + }); }); });