Skip to content

Commit bc48f80

Browse files
committed
test: add CollapsibleSection aria-expanded toggle and a11y regression tests
1 parent c7af425 commit bc48f80

1 file changed

Lines changed: 53 additions & 0 deletions

File tree

test/nuxt/a11y.spec.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2247,6 +2247,59 @@ describe('component accessibility audits', () => {
22472247
const results = await runAxe(component)
22482248
expect(results.violations).toEqual([])
22492249
})
2250+
2251+
it('title button has aria-expanded=true when open and false after click', async () => {
2252+
const component = await mountSuspended(CollapsibleSection, {
2253+
props: { title: 'Dependencies', id: 'deps-section' },
2254+
slots: { default: '<p>Some content</p>' },
2255+
})
2256+
2257+
// Find the title button (second button in the heading — the one with visible text)
2258+
const buttons = component.findAll('button')
2259+
const titleButton = buttons.find(b => b.text().includes('Dependencies'))
2260+
expect(titleButton).toBeDefined()
2261+
2262+
// Initially open
2263+
expect(titleButton!.attributes('aria-expanded')).toBe('true')
2264+
2265+
// After click it should be collapsed
2266+
await titleButton!.trigger('click')
2267+
expect(titleButton!.attributes('aria-expanded')).toBe('false')
2268+
2269+
// Click again to re-expand
2270+
await titleButton!.trigger('click')
2271+
expect(titleButton!.attributes('aria-expanded')).toBe('true')
2272+
})
2273+
2274+
it('title button has aria-controls pointing to the content element', async () => {
2275+
const component = await mountSuspended(CollapsibleSection, {
2276+
props: { title: 'Section Title', id: 'ctrl-test' },
2277+
slots: { default: '<p>Controlled content</p>' },
2278+
})
2279+
2280+
const buttons = component.findAll('button')
2281+
const titleButton = buttons.find(b => b.text().includes('Section Title'))
2282+
expect(titleButton).toBeDefined()
2283+
2284+
const controls = titleButton!.attributes('aria-controls')
2285+
expect(controls).toBe('ctrl-test-collapsible-content')
2286+
2287+
// The referenced content element should exist
2288+
expect(component.find(`#${controls}`).exists()).toBe(true)
2289+
})
2290+
2291+
it('should have no accessibility violations with a subtitle', async () => {
2292+
const component = await mountSuspended(CollapsibleSection, {
2293+
props: {
2294+
title: 'Section Title',
2295+
subtitle: 'A subtitle that describes the section',
2296+
id: 'subtitle-section',
2297+
},
2298+
slots: { default: '<p>Content</p>' },
2299+
})
2300+
const results = await runAxe(component)
2301+
expect(results.violations).toEqual([])
2302+
})
22502303
})
22512304

22522305
describe('TerminalExecute', () => {

0 commit comments

Comments
 (0)