Files
nuxt__ui/test/components/ChatPrompt.spec.ts
Jakub Michálek f2d73e5bee test(components): add a11y tests (#5181)
Co-authored-by: Jakub <jakub.michalek@freelo.io>
Co-authored-by: Benjamin Canac <canacb1@gmail.com>
2025-10-14 13:56:06 +02:00

38 lines
1.5 KiB
TypeScript

import { describe, it, expect } from 'vitest'
import { axe } from 'vitest-axe'
import { mountSuspended } from '@nuxt/test-utils/runtime'
import ChatPrompt from '../../src/runtime/components/ChatPrompt.vue'
import type { ChatPromptProps, ChatPromptSlots } from '../../src/runtime/components/ChatPrompt.vue'
import ComponentRender from '../component-render'
import theme from '#build/ui/chat-prompt'
describe('ChatPrompt', () => {
const variants = Object.keys(theme.variants.variant) as any
it.each([
// Props
['with placeholder', { props: { placeholder: 'Placeholder' } }],
['with error', { props: { error: new Error('Error') } }],
...variants.map((variant: string) => [`with variant ${variant}`, { props: { variant } }]),
['with as', { props: { as: 'section' } }],
['with class', { props: { class: 'p-5' } }],
['with ui', { props: { ui: { footer: 'justify-end' } } }],
// Slots
['with header slot', { slots: { header: () => 'Header slot' } }],
['with footer slot', { slots: { footer: () => 'Footer slot' } }]
])('renders %s correctly', async (nameOrHtml: string, options: { props?: ChatPromptProps, slots?: Partial<ChatPromptSlots> }) => {
const html = await ComponentRender(nameOrHtml, options, ChatPrompt)
expect(html).toMatchSnapshot()
})
it('passes accessibility tests', async () => {
const wrapper = await mountSuspended(ChatPrompt, {
props: {
placeholder: 'Placeholder'
}
})
expect(await axe(wrapper.element)).toHaveNoViolations()
})
})