-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(menu): add aria-attributes and roles to menu and its components (#…
…1514) * feat: add relevant aria-attributes and roles to menu and its child components * fix: update role to menuitem in sharing-dialog-autocomplete test
- Loading branch information
Showing
8 changed files
with
148 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import { mount } from 'enzyme' | ||
import React from 'react' | ||
import { MenuItem } from '../menu-item.js' | ||
|
||
describe('Menu Component', () => { | ||
it('Default menu item has role', () => { | ||
const menuItemDataTest = 'data-test-menu-item' | ||
const wrapper = mount( | ||
<MenuItem dataTest={menuItemDataTest} label="Menu item" /> | ||
) | ||
const menuItem = wrapper.find({ 'data-test': menuItemDataTest }) | ||
expect(menuItem.childAt(0).prop('role')).toBe('menuitem') | ||
expect(menuItem.childAt(0).prop('aria-disabled')).toBe(undefined) | ||
expect(menuItem.childAt(0).prop('aria-label')).toBe('Menu item') | ||
}) | ||
|
||
it('Disabled menu item has aria-disabled attribute', () => { | ||
const menuItemDataTest = 'data-test-menu-item' | ||
const wrapper = mount( | ||
<MenuItem | ||
dataTest={menuItemDataTest} | ||
label="Disabled menu item" | ||
disabled={true} | ||
/> | ||
) | ||
const menuItem = wrapper.find({ 'data-test': menuItemDataTest }) | ||
|
||
expect(menuItem.childAt(0).prop('role')).toBe('menuitem') | ||
expect(menuItem.childAt(0).prop('aria-disabled')).toBe(true) | ||
expect(menuItem.childAt(0).prop('aria-label')).toBe( | ||
'Disabled menu item' | ||
) | ||
}) | ||
|
||
it('Toggle-able menu item has menuitemcheckbox role', () => { | ||
const menuItemDataTest = 'data-test-menu-item' | ||
const wrapper = mount( | ||
<MenuItem | ||
dataTest={menuItemDataTest} | ||
label="Toggle-able menu item" | ||
checkbox | ||
checked={false} | ||
/> | ||
) | ||
const menuItem = wrapper.find({ 'data-test': menuItemDataTest }) | ||
|
||
expect(menuItem.childAt(0).prop('role')).not.toBe('menuitem') | ||
expect(menuItem.childAt(0).prop('role')).toBe('menuitemcheckbox') | ||
expect(menuItem.childAt(0).prop('aria-checked')).toBe(false) | ||
expect(menuItem.childAt(0).prop('aria-label')).toBe( | ||
'Toggle-able menu item' | ||
) | ||
}) | ||
|
||
it('Submenu has relevant aria attributes', () => { | ||
const showSubMenu = false | ||
const wrapper = mount( | ||
<MenuItem | ||
showSubMenu={showSubMenu} | ||
toggleSubMenu={() => jest.fn()} | ||
label="Parent of submenus" | ||
> | ||
<MenuItem label="Test submenu child" /> | ||
</MenuItem> | ||
) | ||
|
||
const menuItem = wrapper.find({ role: 'menuitem' }) | ||
|
||
expect(menuItem.prop('aria-haspopup')).toBe('menu') | ||
expect(menuItem.prop('aria-expanded')).toBe(false) | ||
expect(menuItem.prop('aria-label')).toBe('Parent of submenus') | ||
expect(wrapper.find({ label: 'Test submenu child' }).exists()).toBe( | ||
false | ||
) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { mount } from 'enzyme' | ||
import React from 'react' | ||
import { MenuDivider } from '../../menu-divider/menu-divider.js' | ||
import { MenuItem } from '../../menu-item/menu-item.js' | ||
import { MenuSectionHeader } from '../../menu-section-header/menu-section-header.js' | ||
import { Menu } from '../menu.js' | ||
|
||
describe('Menu Component', () => { | ||
it('Menu and menu items have aria attributes', () => { | ||
const menuDataTest = 'data-test-menu' | ||
const menuItemDataTest = 'data-test-menu-item' | ||
const dividerDataTest = 'data-test-menu-divider' | ||
const wrapper = mount( | ||
<Menu dataTest={menuDataTest} dense={false}> | ||
<MenuSectionHeader label="Header" /> | ||
<MenuDivider dataTest={dividerDataTest} /> | ||
<MenuItem dataTest={menuItemDataTest} label="Menu item" /> | ||
</Menu> | ||
) | ||
const menuElement = wrapper.find({ 'data-test': menuDataTest }) | ||
const menuItem = wrapper.find({ 'data-test': menuItemDataTest }) | ||
const menuDivider = wrapper.find({ 'data-test': dividerDataTest }) | ||
|
||
expect(menuElement.prop('role')).toBe('menu') | ||
|
||
expect(menuItem.childAt(0).props().role).toBe('menuitem') | ||
expect(menuItem.childAt(0).prop('aria-label')).toBe('Menu item') | ||
expect(menuDivider.prop('role')).toBe('separator') | ||
}) | ||
|
||
it('Empty menu has role menu', () => { | ||
const menuDataTest = 'data-test-menu' | ||
const wrapper = mount(<Menu dataTest={menuDataTest} dense={false} />) | ||
const menuElement = wrapper.find({ 'data-test': menuDataTest }) | ||
expect(menuElement.prop('role')).toBe('menu') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters