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>
63 lines
1.9 KiB
TypeScript
63 lines
1.9 KiB
TypeScript
import { describe, it, expect } from 'vitest'
|
|
import { axe } from 'vitest-axe'
|
|
import { mountSuspended } from '@nuxt/test-utils/runtime'
|
|
import FieldGroup from '../../src/runtime/components/FieldGroup.vue'
|
|
import type { FieldGroupProps, FieldGroupSlots } from '../../src/runtime/components/FieldGroup.vue'
|
|
import ComponentRender from '../component-render'
|
|
import buttonTheme from '#build/ui/button'
|
|
import { UInput, UButton } from '#components'
|
|
|
|
describe('FieldGroup', () => {
|
|
const sizes = Object.keys(buttonTheme.variants.size) as any
|
|
|
|
it.each([
|
|
// Props
|
|
['with as', { props: { as: 'section' } }],
|
|
['with class', { props: { class: 'absolute' } }],
|
|
// Slots
|
|
['with default slot', {
|
|
slots: {
|
|
default: {
|
|
components: { UInput, UButton },
|
|
template: `<UInput /> <UButton> Click me! </UButton>`
|
|
}
|
|
}
|
|
}],
|
|
['orientation vertical with default slot', {
|
|
props: { orientation: 'vertical' },
|
|
slots: {
|
|
default: {
|
|
components: { UInput, UButton },
|
|
template: `<UInput /> <UButton> Click me! </UButton>`
|
|
}
|
|
}
|
|
}],
|
|
...sizes.map((size: string) =>
|
|
[`with size ${size}`, {
|
|
props: { size },
|
|
slots: {
|
|
default: {
|
|
components: { UInput, UButton },
|
|
template: `<UInput /> <UButton> Click me! </UButton>`
|
|
}
|
|
}
|
|
}]
|
|
)
|
|
])('renders %s correctly', async (nameOrHtml: string, options: { props?: FieldGroupProps, slots?: Partial<FieldGroupSlots> }) => {
|
|
const html = await ComponentRender(nameOrHtml, options, FieldGroup)
|
|
expect(html).toMatchSnapshot()
|
|
})
|
|
|
|
it('passes accessibility tests', async () => {
|
|
const wrapper = await mountSuspended(FieldGroup, {
|
|
slots: {
|
|
default: {
|
|
template: `<UInput /> <UButton> Click me! </UButton>`
|
|
}
|
|
}
|
|
})
|
|
|
|
expect(await axe(wrapper.element)).toHaveNoViolations()
|
|
})
|
|
})
|