Skip to content

Commit 9fb44c4

Browse files
committed
feat: add a11y tests for background theming
1 parent 627c819 commit 9fb44c4

1 file changed

Lines changed: 133 additions & 0 deletions

File tree

test/nuxt/a11y.spec.ts

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ import {
106106
ProvenanceBadge,
107107
Readme,
108108
SettingsAccentColorPicker,
109+
SettingsBgThemePicker,
109110
SettingsToggle,
110111
TerminalExecute,
111112
TerminalInstall,
@@ -1413,6 +1414,14 @@ describe('component accessibility audits', () => {
14131414
})
14141415
})
14151416

1417+
describe('SettingsBgThemePicker', () => {
1418+
it('should have no accessibility violations', async () => {
1419+
const component = await mountSuspended(SettingsBgThemePicker)
1420+
const results = await runAxe(component)
1421+
expect(results.violations).toEqual([])
1422+
})
1423+
})
1424+
14161425
describe('TooltipBase', () => {
14171426
it('should have no accessibility violations when hidden', async () => {
14181427
const component = await mountSuspended(TooltipBase, {
@@ -1788,3 +1797,127 @@ describe('component accessibility audits', () => {
17881797
})
17891798
})
17901799
})
1800+
1801+
describe('background theme accessibility', () => {
1802+
const pairs = [
1803+
['light', 'neutral'],
1804+
['dark', 'neutral'],
1805+
['light', 'stone'],
1806+
['dark', 'stone'],
1807+
['light', 'zinc'],
1808+
['dark', 'zinc'],
1809+
['light', 'slate'],
1810+
['dark', 'slate'],
1811+
] as const
1812+
1813+
function applyTheme(colorMode: string, bgTheme: string | null) {
1814+
document.documentElement.dataset.theme = colorMode
1815+
document.documentElement.classList.add(colorMode)
1816+
if (bgTheme) document.documentElement.dataset.bgTheme = bgTheme
1817+
}
1818+
1819+
afterEach(() => {
1820+
document.documentElement.removeAttribute('data-theme')
1821+
document.documentElement.removeAttribute('data-bg-theme')
1822+
document.documentElement.classList.remove('light', 'dark')
1823+
})
1824+
1825+
const packageResult = {
1826+
package: {
1827+
name: 'vue',
1828+
version: '3.5.0',
1829+
description: 'Framework',
1830+
date: '2024-01-15T00:00:00.000Z',
1831+
keywords: [],
1832+
links: {},
1833+
publisher: { username: 'evan' },
1834+
},
1835+
score: { final: 0.9, detail: { quality: 0.9, popularity: 0.9, maintenance: 0.9 } },
1836+
searchScore: 100000,
1837+
}
1838+
1839+
const components = [
1840+
{ name: 'AppHeader', mount: () => mountSuspended(AppHeader) },
1841+
{ name: 'AppFooter', mount: () => mountSuspended(AppFooter) },
1842+
{ name: 'HeaderSearchBox', mount: () => mountSuspended(HeaderSearchBox) },
1843+
{
1844+
name: 'LoadingSpinner',
1845+
mount: () => mountSuspended(LoadingSpinner, { props: { text: 'Loading...' } }),
1846+
},
1847+
{
1848+
name: 'SettingsToggle',
1849+
mount: () =>
1850+
mountSuspended(SettingsToggle, { props: { label: 'Feature', description: 'Desc' } }),
1851+
},
1852+
{ name: 'SettingsBgThemePicker', mount: () => mountSuspended(SettingsBgThemePicker) },
1853+
{
1854+
name: 'ProvenanceBadge',
1855+
mount: () =>
1856+
mountSuspended(ProvenanceBadge, {
1857+
props: { provider: 'github', packageName: 'vue', version: '3.0.0' },
1858+
}),
1859+
},
1860+
{
1861+
name: 'TerminalInstall',
1862+
mount: () => mountSuspended(TerminalInstall, { props: { packageName: 'vue' } }),
1863+
},
1864+
{
1865+
name: 'LicenseDisplay',
1866+
mount: () => mountSuspended(LicenseDisplay, { props: { license: 'MIT' } }),
1867+
},
1868+
{
1869+
name: 'DateTime',
1870+
mount: () => mountSuspended(DateTime, { props: { datetime: '2024-01-15T12:00:00.000Z' } }),
1871+
},
1872+
{
1873+
name: 'ViewModeToggle',
1874+
mount: () => mountSuspended(ViewModeToggle, { props: { modelValue: 'cards' } }),
1875+
},
1876+
{
1877+
name: 'TooltipApp',
1878+
mount: () =>
1879+
mountSuspended(TooltipApp, {
1880+
props: { text: 'Tooltip' },
1881+
slots: { default: '<button>Trigger</button>' },
1882+
}),
1883+
},
1884+
{
1885+
name: 'CollapsibleSection',
1886+
mount: () =>
1887+
mountSuspended(CollapsibleSection, {
1888+
props: { title: 'Title', id: 'section' },
1889+
slots: { default: '<p>Content</p>' },
1890+
}),
1891+
},
1892+
{
1893+
name: 'FilterChips',
1894+
mount: () =>
1895+
mountSuspended(FilterChips, {
1896+
props: {
1897+
chips: [{ id: 'text', type: 'text', label: 'Search', value: 'react' }] as FilterChip[],
1898+
},
1899+
}),
1900+
},
1901+
{
1902+
name: 'PackageCard',
1903+
mount: () => mountSuspended(PackageCard, { props: { result: packageResult } }),
1904+
},
1905+
{
1906+
name: 'PackageList',
1907+
mount: () => mountSuspended(PackageList, { props: { results: [packageResult] } }),
1908+
},
1909+
]
1910+
1911+
for (const { name, mount } of components) {
1912+
describe(`${name} colors`, () => {
1913+
for (const [colorMode, bgTheme] of pairs) {
1914+
it(`${colorMode}/${bgTheme}`, async () => {
1915+
applyTheme(colorMode, bgTheme)
1916+
const results = await runAxe(await mount())
1917+
await new Promise(resolve => setTimeout(resolve, 2000))
1918+
expect(results.violations).toEqual([])
1919+
})
1920+
}
1921+
})
1922+
}
1923+
})

0 commit comments

Comments
 (0)