Skip to content

Commit 9c5a94e

Browse files
committed
test: add CopyToClipboardButton aria-label and touch visibility regression tests
1 parent f029ccb commit 9c5a94e

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import { describe, expect, it } from 'vitest'
2+
import { mountSuspended } from '@nuxt/test-utils/runtime'
3+
import CopyToClipboardButton from '~/components/CopyToClipboardButton.vue'
4+
5+
describe('CopyToClipboardButton', () => {
6+
it('aria-label matches visible copy text when copyText is provided', async () => {
7+
const wrapper = await mountSuspended(CopyToClipboardButton, {
8+
props: {
9+
copied: false,
10+
copyText: 'Copy package name',
11+
},
12+
})
13+
14+
const button = wrapper.find('button')
15+
expect(button.attributes('aria-label')).toBe('Copy package name')
16+
expect(button.text()).toContain('Copy package name')
17+
})
18+
19+
it('aria-label uses ariaLabelCopy when explicitly provided', async () => {
20+
const wrapper = await mountSuspended(CopyToClipboardButton, {
21+
props: {
22+
copied: false,
23+
copyText: 'Copy package name',
24+
ariaLabelCopy: 'Copy the package name to clipboard',
25+
},
26+
})
27+
28+
const button = wrapper.find('button')
29+
expect(button.attributes('aria-label')).toBe('Copy the package name to clipboard')
30+
})
31+
32+
it('aria-label reflects copiedText when copied is true', async () => {
33+
const wrapper = await mountSuspended(CopyToClipboardButton, {
34+
props: {
35+
copied: true,
36+
copyText: 'Copy package name',
37+
copiedText: 'Copied!',
38+
},
39+
})
40+
41+
const button = wrapper.find('button')
42+
expect(button.attributes('aria-label')).toBe('Copied!')
43+
expect(button.text()).toContain('Copied!')
44+
})
45+
46+
it('aria-label matches visible text - no label/content mismatch', async () => {
47+
const wrapper = await mountSuspended(CopyToClipboardButton, {
48+
props: {
49+
copied: false,
50+
copyText: 'Copy install command',
51+
},
52+
})
53+
54+
const button = wrapper.find('button')
55+
const ariaLabel = button.attributes('aria-label') ?? ''
56+
const visibleText = button.text()
57+
// The aria-label should equal the visible text (not some other string)
58+
expect(visibleText).toContain(ariaLabel)
59+
})
60+
})

0 commit comments

Comments
 (0)