mirror of
https://github.com/nuxt/ui.git
synced 2026-09-14 19:51:10 +08:00
7d1e8631ea
Co-authored-by: Benjamin Canac <canacb1@gmail.com>
73 lines
4.3 KiB
TypeScript
73 lines
4.3 KiB
TypeScript
import { describe, it, expect } from 'vitest'
|
|
import { axe } from 'vitest-axe'
|
|
import { mountSuspended } from '@nuxt/test-utils/runtime'
|
|
import { renderEach } from '../component-render'
|
|
import Accordion from '../../src/runtime/components/Accordion.vue'
|
|
|
|
describe('Accordion', () => {
|
|
const items = [{
|
|
label: 'Getting Started',
|
|
icon: 'i-lucide-info',
|
|
content: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed neque elit, tristique placerat feugiat ac, facilisis vitae arcu. Proin eget egestas augue. Praesent ut sem nec arcu pellentesque aliquet. Duis dapibus diam vel metus tempus vulputate.'
|
|
}, {
|
|
label: 'Installation',
|
|
icon: 'i-lucide-download',
|
|
disabled: true,
|
|
content: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed neque elit, tristique placerat feugiat ac, facilisis vitae arcu. Proin eget egestas augue. Praesent ut sem nec arcu pellentesque aliquet. Duis dapibus diam vel metus tempus vulputate.'
|
|
}, {
|
|
label: 'Theming',
|
|
icon: 'i-lucide-pipette',
|
|
content: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed neque elit, tristique placerat feugiat ac, facilisis vitae arcu. Proin eget egestas augue. Praesent ut sem nec arcu pellentesque aliquet. Duis dapibus diam vel metus tempus vulputate.'
|
|
}, {
|
|
label: 'Layouts',
|
|
icon: 'i-lucide-layout-dashboard',
|
|
content: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed neque elit, tristique placerat feugiat ac, facilisis vitae arcu. Proin eget egestas augue. Praesent ut sem nec arcu pellentesque aliquet. Duis dapibus diam vel metus tempus vulputate.'
|
|
}, {
|
|
label: 'Components',
|
|
icon: 'i-lucide-layers-3',
|
|
content: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed neque elit, tristique placerat feugiat ac, facilisis vitae arcu. Proin eget egestas augue. Praesent ut sem nec arcu pellentesque aliquet. Duis dapibus diam vel metus tempus vulputate.'
|
|
}, {
|
|
label: 'Utilities',
|
|
icon: 'i-lucide-wrench',
|
|
trailingIcon: 'i-lucide-sun',
|
|
content: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed neque elit, tristique placerat feugiat ac, facilisis vitae arcu. Proin eget egestas augue. Praesent ut sem nec arcu pellentesque aliquet. Duis dapibus diam vel metus tempus vulputate.',
|
|
slot: 'custom' as const
|
|
}]
|
|
|
|
const props = { items }
|
|
|
|
renderEach(Accordion<typeof items[number]>, [
|
|
// Props
|
|
['with items', { props }],
|
|
['with modelValue', { props: { ...props, modelValue: '1' } }],
|
|
['with defaultValue', { props: { ...props, defaultValue: '1' } }],
|
|
['with valueKey', { props: { ...props, valueKey: 'label', defaultValue: 'Getting Started' } }],
|
|
['with labelKey', { props: { ...props, labelKey: 'icon' } }],
|
|
['with as', { props: { ...props, as: 'section' } }],
|
|
['with type', { props: { ...props, type: 'multiple' } }],
|
|
['with disabled', { props: { ...props, disabled: true } }],
|
|
['with collapsible', { props: { ...props, collapsible: false } }],
|
|
['with unmountOnHide', { props: { ...props, unmountOnHide: false } }],
|
|
['with trailingIcon', { props: { ...props, trailingIcon: 'i-lucide-plus' } }],
|
|
['with as', { props: { ...props, as: 'section' } }],
|
|
['with class', { props: { ...props, class: 'w-96' } }],
|
|
['with ui', { props: { ...props, ui: { item: 'border-accented' } } }],
|
|
// Slots
|
|
['with leading slot', { props: { ...props, modelValue: '1' }, slots: { leading: () => 'Leading slot' } }],
|
|
['with default slot', { props: { ...props, modelValue: '1' }, slots: { default: () => 'Default slot' } }],
|
|
['with trailing slot', { props: { ...props, modelValue: '1' }, slots: { trailing: () => 'Trailing slot' } }],
|
|
['with content slot', { props: { ...props, modelValue: '1' }, slots: { content: () => 'Content slot' } }],
|
|
['with body slot', { props: { ...props, modelValue: '1' }, slots: { body: () => 'Body slot' } }],
|
|
['with custom slot', { props: { ...props, modelValue: '5' }, slots: { custom: () => 'Custom slot' } }],
|
|
['with custom body slot', { props: { ...props, modelValue: '5' }, slots: { 'custom-body': () => 'Custom body slot' } }]
|
|
])
|
|
|
|
it('passes accessibility tests', async () => {
|
|
const wrapper = await mountSuspended(Accordion, {
|
|
props: { items, modelValue: '1' }
|
|
})
|
|
|
|
expect(await axe(wrapper.element)).toHaveNoViolations()
|
|
})
|
|
})
|