Skip to content

Commit 5363165

Browse files
test(menu-item): add aria-current tests
1 parent 4c076e3 commit 5363165

File tree

1 file changed

+71
-1
lines changed

1 file changed

+71
-1
lines changed

1st-gen/packages/menu/test/menu-item.test.ts

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ describe('Menu item', () => {
199199
const descriptionElement = el.querySelector('span') as HTMLElement;
200200
expect(descriptionElement.assignedSlot).to.not.be.null;
201201
});
202-
it('acualizes a submenu', async () => {
202+
it('actualizes a submenu', async () => {
203203
const test = await fixture<Menu>(html`
204204
<sp-menu>
205205
<sp-menu-item selected>Selected</sp-menu-item>
@@ -256,4 +256,74 @@ describe('Menu item', () => {
256256
for (const menuItem of menuItems)
257257
expect(getComputedStyle(menuItem).textAlign).to.equal('start');
258258
});
259+
it('sets aria-current to true if the item has selected property', async () => {
260+
const el = await fixture<Menu>(html`
261+
<sp-menu>
262+
<sp-menu-item selected>First</sp-menu-item>
263+
<sp-menu-item>Second</sp-menu-item>
264+
</sp-menu>
265+
`);
266+
await elementUpdated(el);
267+
268+
const selectedItem = el.querySelector(
269+
'sp-menu-item[selected]'
270+
) as MenuItem;
271+
const unselectedItem = el.querySelector(
272+
'sp-menu-item:not([selected])'
273+
) as MenuItem;
274+
275+
expect(selectedItem?.hasAttribute('aria-current')).to.be.true;
276+
expect(selectedItem?.getAttribute('aria-current')).to.equal('true');
277+
expect(unselectedItem?.hasAttribute('aria-current')).to.be.false;
278+
expect(unselectedItem?.getAttribute('aria-current')).to.be.null;
279+
});
280+
it('removes aria-current if the item is deselected', async () => {
281+
const el = await fixture<Menu>(html`
282+
<sp-menu>
283+
<sp-menu-item selected>Selected Text</sp-menu-item>
284+
</sp-menu>
285+
`);
286+
await elementUpdated(el);
287+
const item = el.querySelector('sp-menu-item') as MenuItem;
288+
289+
expect(item.hasAttribute('aria-current')).to.be.true;
290+
expect(item.getAttribute('aria-current')).to.equal('true');
291+
292+
item.selected = false;
293+
await elementUpdated(item);
294+
295+
expect(item.hasAttribute('aria-current')).to.be.false;
296+
expect(item.getAttribute('aria-current')).to.be.null;
297+
});
298+
it('updates aria-current when the selected item changes', async () => {
299+
const el = await fixture<Menu>(html`
300+
<sp-menu>
301+
<sp-menu-item selected>First</sp-menu-item>
302+
<sp-menu-item>Second</sp-menu-item>
303+
</sp-menu>
304+
`);
305+
await elementUpdated(el);
306+
307+
const selectedItem = el.querySelector(
308+
'sp-menu-item[selected]'
309+
) as MenuItem;
310+
const unselectedItem = el.querySelector(
311+
'sp-menu-item:not([selected])'
312+
) as MenuItem;
313+
314+
expect(selectedItem?.hasAttribute('aria-current')).to.be.true;
315+
expect(selectedItem?.getAttribute('aria-current')).to.equal('true');
316+
expect(unselectedItem?.hasAttribute('aria-current')).to.be.false;
317+
expect(unselectedItem?.getAttribute('aria-current')).to.be.null;
318+
319+
selectedItem.selected = false;
320+
unselectedItem.selected = true;
321+
await elementUpdated(selectedItem);
322+
await elementUpdated(unselectedItem);
323+
324+
expect(selectedItem?.hasAttribute('aria-current')).to.be.false;
325+
expect(selectedItem?.getAttribute('aria-current')).to.be.null;
326+
expect(unselectedItem?.hasAttribute('aria-current')).to.be.true;
327+
expect(unselectedItem?.getAttribute('aria-current')).to.equal('true');
328+
});
259329
});

0 commit comments

Comments
 (0)