Skip to content

Commit 6b0c98d

Browse files
authored
test: move a11y test suite to the appropriate file (#7530)
1 parent b46746e commit 6b0c98d

2 files changed

Lines changed: 56 additions & 56 deletions

File tree

‎packages/menu-bar/test/a11y.common.js‎

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,62 @@ import { arrowDown, arrowRight, enter, fixtureSync, nextRender, outsideClick } f
33
import { getDeepActiveElement } from '@vaadin/a11y-base/src/focus-utils.js';
44

55
describe('a11y', () => {
6+
describe('ARIA attributes', () => {
7+
let menu, buttons, subMenu, overflow;
8+
9+
beforeEach(async () => {
10+
menu = fixtureSync('<vaadin-menu-bar></vaadin-menu-bar>');
11+
menu.items = [
12+
{
13+
text: 'Menu Item 1',
14+
children: [{ text: 'Menu Item 1 1' }, { text: 'Menu Item 1 2' }],
15+
},
16+
{ text: 'Menu Item 2' },
17+
{
18+
text: 'Menu Item 3',
19+
children: [{ text: 'Menu Item 3 1' }, { text: 'Menu Item 3 2' }],
20+
},
21+
];
22+
await nextRender(menu);
23+
subMenu = menu._subMenu;
24+
buttons = menu._buttons;
25+
overflow = menu._overflow;
26+
});
27+
28+
it('should set role attribute on host element', () => {
29+
expect(menu.getAttribute('role')).to.equal('menubar');
30+
});
31+
32+
it('should set role attribute on menu bar buttons', () => {
33+
buttons.forEach((btn) => {
34+
expect(btn.getAttribute('role')).to.equal('menuitem');
35+
});
36+
});
37+
38+
it('should set aria-haspopup attribute on buttons with nested items', () => {
39+
buttons.forEach((btn) => {
40+
const hasPopup = btn === overflow || btn.item.children ? 'true' : null;
41+
expect(btn.getAttribute('aria-haspopup')).to.equal(hasPopup);
42+
});
43+
});
44+
45+
it('should set aria-expanded attribute on buttons with nested items', () => {
46+
buttons.forEach((btn) => {
47+
const expanded = btn === overflow || btn.item.children ? 'false' : null;
48+
expect(btn.getAttribute('aria-expanded')).to.equal(expanded);
49+
});
50+
});
51+
52+
it('should toggle aria-expanded attribute on submenu open / close', async () => {
53+
buttons[0].click();
54+
await nextRender(subMenu);
55+
expect(buttons[0].getAttribute('aria-expanded')).to.equal('true');
56+
57+
buttons[0].click();
58+
expect(buttons[0].getAttribute('aria-expanded')).to.equal('false');
59+
});
60+
});
61+
662
describe('focus restoration', () => {
763
let menuBar, overlay, buttons;
864

‎packages/menu-bar/test/sub-menu.common.js‎

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -575,62 +575,6 @@ describe('open on hover', () => {
575575
});
576576
});
577577

578-
describe('accessibility', () => {
579-
let menu, buttons, subMenu, overflow;
580-
581-
beforeEach(async () => {
582-
menu = fixtureSync('<vaadin-menu-bar></vaadin-menu-bar>');
583-
menu.items = [
584-
{
585-
text: 'Menu Item 1',
586-
children: [{ text: 'Menu Item 1 1' }, { text: 'Menu Item 1 2' }],
587-
},
588-
{ text: 'Menu Item 2' },
589-
{
590-
text: 'Menu Item 3',
591-
children: [{ text: 'Menu Item 3 1' }, { text: 'Menu Item 3 2' }],
592-
},
593-
];
594-
await nextRender(menu);
595-
subMenu = menu._subMenu;
596-
buttons = menu._buttons;
597-
overflow = menu._overflow;
598-
});
599-
600-
it('should set role attribute on host element', () => {
601-
expect(menu.getAttribute('role')).to.equal('menubar');
602-
});
603-
604-
it('should set role attribute on menu bar buttons', () => {
605-
buttons.forEach((btn) => {
606-
expect(btn.getAttribute('role')).to.equal('menuitem');
607-
});
608-
});
609-
610-
it('should set aria-haspopup attribute on buttons with nested items', () => {
611-
buttons.forEach((btn) => {
612-
const hasPopup = btn === overflow || btn.item.children ? 'true' : null;
613-
expect(btn.getAttribute('aria-haspopup')).to.equal(hasPopup);
614-
});
615-
});
616-
617-
it('should set aria-expanded attribute on buttons with nested items', () => {
618-
buttons.forEach((btn) => {
619-
const expanded = btn === overflow || btn.item.children ? 'false' : null;
620-
expect(btn.getAttribute('aria-expanded')).to.equal(expanded);
621-
});
622-
});
623-
624-
it('should toggle aria-expanded attribute on submenu open / close', async () => {
625-
buttons[0].click();
626-
await nextRender(subMenu);
627-
expect(buttons[0].getAttribute('aria-expanded')).to.equal('true');
628-
629-
buttons[0].click();
630-
expect(buttons[0].getAttribute('aria-expanded')).to.equal('false');
631-
});
632-
});
633-
634578
describe('theme attribute', () => {
635579
let menu, subMenu, subMenuOverlay, buttons;
636580

0 commit comments

Comments
 (0)