mirror of
https://github.com/nuxt/ui.git
synced 2026-09-14 19:51:10 +08:00
d3b5f1d3f9
Co-authored-by: Benjamin Canac <canacb1@gmail.com>
76 lines
3.7 KiB
TypeScript
76 lines
3.7 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 ChangelogVersion from '../../src/runtime/components/ChangelogVersion.vue'
|
|
|
|
describe('ChangelogVersion', () => {
|
|
renderEach(ChangelogVersion, [
|
|
// Props
|
|
['with title', { props: { title: 'Title' } }],
|
|
['with description', { props: { description: 'Description' } }],
|
|
['with to', { props: { to: '/changelog' } }],
|
|
['with image', { props: { image: 'https://picsum.photos/640/360' } }],
|
|
['with to & image', { props: { to: '/changelog', image: 'https://picsum.photos/640/360' } }],
|
|
['with date', { props: { date: '2025-01-01' } }],
|
|
['with badge', { props: { badge: 'Badge' } }],
|
|
['with badge object', { props: { badge: { label: 'Badge', color: 'primary' } } }],
|
|
['with authors', { props: { authors: [{ name: 'Benjamin Canac', description: 'benjamincanac', avatar: { src: 'https://github.com/benjamincanac.png', alt: 'benjamincanac' } }] } }],
|
|
['without indicator', { props: { indicator: false } }],
|
|
['with as', { props: { as: 'section' } }],
|
|
['with class', { props: { class: 'absolute' } }],
|
|
['with ui', { props: { ui: { container: 'max-w-xl' } } }],
|
|
// Slots
|
|
['with title slot', { slots: { title: () => 'Title slot' } }],
|
|
['with description slot', { slots: { description: () => 'Description slot' } }],
|
|
['with header slot', { slots: { header: () => 'Header slot' } }],
|
|
['with badge slot', { slots: { badge: () => 'Badge slot' } }],
|
|
['with date slot', { slots: { date: () => 'Date slot' } }],
|
|
['with title slot', { slots: { title: () => 'Title slot' } }],
|
|
['with description slot', { slots: { description: () => 'Description slot' } }],
|
|
['with image slot', { slots: { image: () => 'Image slot' } }],
|
|
['with body slot', { slots: { body: () => 'Body slot' } }],
|
|
['with footer slot', { slots: { footer: () => 'Footer slot' } }],
|
|
['with authors slot', { slots: { authors: () => 'Authors slot' } }],
|
|
['with actions slot', { slots: { actions: () => 'Actions slot' } }],
|
|
['with indicator slot', { slots: { indicator: () => 'Indicator slot' } }]
|
|
])
|
|
|
|
it('passes accessibility tests', async () => {
|
|
const wrapper = await mountSuspended(ChangelogVersion, {
|
|
props: {
|
|
title: 'Version 1.0.0',
|
|
description: 'Initial release',
|
|
date: '2025-01-01',
|
|
badge: 'Badge',
|
|
authors: [{ name: 'Benjamin Canac', description: 'benjamincanac', avatar: { src: 'https://github.com/benjamincanac.png', alt: 'Benjamin Canac' } }],
|
|
indicator: true,
|
|
to: '/changelog',
|
|
image: 'https://picsum.photos/640/360'
|
|
}
|
|
})
|
|
|
|
expect(await axe(wrapper.element)).toHaveNoViolations()
|
|
})
|
|
|
|
it('forwards attrs to root when `to` prop is absent', async () => {
|
|
const wrapper = await mountSuspended(ChangelogVersion, {
|
|
props: { title: 'v1.0.0' },
|
|
attrs: { 'aria-label': 'test-label', 'data-testid': 'test-id' }
|
|
})
|
|
// Root is a fragment (DefineTemplate blocks render leading comments), so target the root element directly
|
|
const root = wrapper.find('[data-slot="root"]')
|
|
expect(root.attributes('aria-label')).toBe('test-label')
|
|
expect(root.attributes('data-testid')).toBe('test-id')
|
|
})
|
|
|
|
it('forwards attrs to link when `to` prop is set', async () => {
|
|
const wrapper = await mountSuspended(ChangelogVersion, {
|
|
props: { title: 'v1.0.0', to: 'https://github.com/benjamincanac' },
|
|
attrs: { 'aria-label': 'test-label' }
|
|
})
|
|
expect(wrapper.find('[data-slot="root"]').attributes('aria-label')).toBeUndefined()
|
|
expect(wrapper.find('a').attributes('aria-label')).toBe('test-label')
|
|
})
|
|
})
|