mirror of
https://github.com/nuxt/ui.git
synced 2026-09-14 19:51:10 +08:00
f2d73e5bee
Co-authored-by: Jakub <jakub.michalek@freelo.io> Co-authored-by: Benjamin Canac <canacb1@gmail.com>
54 lines
2.0 KiB
TypeScript
54 lines
2.0 KiB
TypeScript
import { describe, it, expect } from 'vitest'
|
|
import { axe } from 'vitest-axe'
|
|
import { mountSuspended } from '@nuxt/test-utils/runtime'
|
|
import Popover from '../../src/runtime/components/Popover.vue'
|
|
import type { PopoverProps, PopoverSlots } from '../../src/runtime/components/Popover.vue'
|
|
import ComponentRender from '../component-render'
|
|
|
|
describe('Popover', () => {
|
|
const props = { open: true, portal: false }
|
|
|
|
it.each([
|
|
// Props
|
|
['with open', { props }],
|
|
['with arrow', { props: { ...props, arrow: true } }],
|
|
['with class', { props: { ...props, class: 'shadow-xl' } }],
|
|
['with ui', { props: { ...props, ui: { content: 'shadow-xl' } } }],
|
|
// Slots
|
|
['with default slot', { props, slots: { default: () => 'Default slot' } }],
|
|
['with content slot', { props, slots: { content: () => 'Content slot' } }],
|
|
['with anchor slot', { props, slots: { anchor: () => 'Anchor slot' } }]
|
|
])('renders %s correctly', async (nameOrHtml: string, options: { props?: PopoverProps, slots?: Partial<PopoverSlots> }) => {
|
|
const html = await ComponentRender(nameOrHtml, options, Popover)
|
|
expect(html).toMatchSnapshot()
|
|
})
|
|
|
|
it('passes accessibility tests', async () => {
|
|
const wrapper = await mountSuspended(Popover, {
|
|
props: {
|
|
open: true,
|
|
portal: false,
|
|
arrow: true
|
|
|
|
},
|
|
slots: {
|
|
default: () => 'Default Slot',
|
|
content: () => 'Content Slot',
|
|
anchor: () => 'Anchor Slot'
|
|
}
|
|
})
|
|
|
|
expect(await axe(wrapper.element, {
|
|
rules: {
|
|
// "ARIA dialog and alertdialog nodes should have an accessible name (aria-dialog-name)"
|
|
|
|
// Fix any of the following:
|
|
// aria-label attribute does not exist or is empty
|
|
// aria-labelledby attribute does not exist, references elements that do not exist or references elements that are empty
|
|
// Element has no title attribute
|
|
'aria-dialog-name': { enabled: false }
|
|
}
|
|
})).toHaveNoViolations()
|
|
})
|
|
})
|