Skip to content

Commit 971d167

Browse files
Copilotilhan007
andcommitted
Add unit test for SegmentedButton ARIA attribute validation
Co-authored-by: ilhan007 <15702139+ilhan007@users.noreply.github.com>
1 parent a3b2f12 commit 971d167

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import { expect, test } from 'vitest'
2+
import "@ui5/webcomponents/dist/SegmentedButton.js";
3+
4+
test('SegmentedButton should have correct ARIA attributes for Single mode', async () => {
5+
const segmentedButton = document.createElement("ui5-segmented-button");
6+
segmentedButton.innerHTML = `
7+
<ui5-segmented-button-item>Option 1</ui5-segmented-button-item>
8+
<ui5-segmented-button-item>Option 2</ui5-segmented-button-item>
9+
`;
10+
document.body.appendChild(segmentedButton);
11+
12+
// Ensure it's in Single mode (default)
13+
expect(segmentedButton.selectionMode).toBe("Single");
14+
15+
// Wait for rendering
16+
await new Promise(resolve => setTimeout(resolve, 100));
17+
18+
const listbox = segmentedButton.shadowRoot.querySelector('ul[role="listbox"]');
19+
expect(listbox).toBeTruthy();
20+
expect(listbox.getAttribute('aria-multiselectable')).toBe('false');
21+
expect(listbox.getAttribute('aria-orientation')).toBe('horizontal');
22+
});
23+
24+
test('SegmentedButton should have correct ARIA attributes for Multiple mode', async () => {
25+
const segmentedButton = document.createElement("ui5-segmented-button");
26+
segmentedButton.selectionMode = "Multiple";
27+
segmentedButton.innerHTML = `
28+
<ui5-segmented-button-item>Option A</ui5-segmented-button-item>
29+
<ui5-segmented-button-item>Option B</ui5-segmented-button-item>
30+
`;
31+
document.body.appendChild(segmentedButton);
32+
33+
// Ensure it's in Multiple mode
34+
expect(segmentedButton.selectionMode).toBe("Multiple");
35+
36+
// Wait for rendering
37+
await new Promise(resolve => setTimeout(resolve, 100));
38+
39+
const listbox = segmentedButton.shadowRoot.querySelector('ul[role="listbox"]');
40+
expect(listbox).toBeTruthy();
41+
expect(listbox.getAttribute('aria-multiselectable')).toBe('true');
42+
expect(listbox.getAttribute('aria-orientation')).toBe('horizontal');
43+
});
44+
45+
test('SegmentedButton ARIA attributes should change when selectionMode changes', async () => {
46+
const segmentedButton = document.createElement("ui5-segmented-button");
47+
segmentedButton.innerHTML = `
48+
<ui5-segmented-button-item>Option X</ui5-segmented-button-item>
49+
<ui5-segmented-button-item>Option Y</ui5-segmented-button-item>
50+
`;
51+
document.body.appendChild(segmentedButton);
52+
53+
// Start with Single mode (default)
54+
expect(segmentedButton.selectionMode).toBe("Single");
55+
await new Promise(resolve => setTimeout(resolve, 100));
56+
57+
let listbox = segmentedButton.shadowRoot.querySelector('ul[role="listbox"]');
58+
expect(listbox.getAttribute('aria-multiselectable')).toBe('false');
59+
expect(listbox.getAttribute('aria-orientation')).toBe('horizontal');
60+
61+
// Change to Multiple mode
62+
segmentedButton.selectionMode = "Multiple";
63+
await new Promise(resolve => setTimeout(resolve, 100));
64+
65+
listbox = segmentedButton.shadowRoot.querySelector('ul[role="listbox"]');
66+
expect(listbox.getAttribute('aria-multiselectable')).toBe('true');
67+
expect(listbox.getAttribute('aria-orientation')).toBe('horizontal');
68+
});

0 commit comments

Comments
 (0)