Skip to content

Commit 74bd137

Browse files
committed
test(InputTime): expand test cases for InputTime component with various props and accessibility checks
1 parent dce8077 commit 74bd137

File tree

3 files changed

+938
-6
lines changed

3 files changed

+938
-6
lines changed

test/components/InputTime.spec.ts

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,68 @@
1-
import { describe, it, expect } from 'vitest'
1+
import { describe, it, expect, vi, afterAll, test } from 'vitest'
22
import { axe } from 'vitest-axe'
33
import { mountSuspended } from '@nuxt/test-utils/runtime'
44
import InputTime from '../../src/runtime/components/InputTime.vue'
55
import type { InputTimeProps, InputTimeSlots } from '../../src/runtime/components/InputTime.vue'
66
import ComponentRender from '../component-render'
7+
import theme from '#build/ui/input-time'
8+
import { Time } from '@internationalized/date'
79

810
describe('InputTime', () => {
9-
const props = {}
11+
const sizes = Object.keys(theme.variants.size) as any
12+
const variants = Object.keys(theme.variants.variant) as any
13+
const date = new Date('2025-01-01')
14+
15+
vi.setSystemTime(date)
16+
17+
afterAll(() => {
18+
vi.useRealTimers()
19+
})
1020

1121
it.each([
1222
// Props
23+
['with modelValue', { props: { modelValue: new Time(12, 30) } }],
24+
['with default value', { props: { defaultValue: new Time(12, 30) } }],
25+
['with placeholder', { props: { placeholder: new Time(12, 30) } }],
26+
['with disabled', { props: { disabled: true, modelValue: new Time(12, 30) } }],
27+
['with required', { props: { required: true, modelValue: new Time(12, 30) } }],
28+
['with readonly', { props: { readonly: true, modelValue: new Time(12, 30) } }],
29+
['with hour cycle 24', { props: { hourCycle: 24 as const } }],
30+
['with hour cycle 12', { props: { hourCycle: 12 as const } }],
31+
['with granularity', { props: { granularity: 'minute' as const } }],
32+
['with hide time zone', { props: { hideTimeZone: true } }],
33+
['with max value', { props: { maxValue: new Time(12, 30) } }],
34+
['with min value', { props: { minValue: new Time(12, 30) } }],
35+
['with icon', { props: { icon: 'i-lucide-clock' } }],
36+
['with leadingIcon', { props: { leadingIcon: 'i-lucide-arrow-left' } }],
37+
['with trailingIcon', { props: { trailingIcon: 'i-lucide-arrow-right' } }],
38+
...sizes.map((size: string) => [`with size ${size}`, { props: { size } }]),
39+
...variants.map((variant: string) => [`with variant ${variant}`, { props: { variant, defaultValue: new Time(12, 30) } }]),
40+
['with color neutral', { props: { color: 'neutral' } }],
1341
['with as', { props: { as: 'section' } }],
14-
['with class', { props: { class: '' } }],
15-
['with ui', { props: { ui: {} } }],
42+
['with class', { props: { class: 'max-w-sm' } }],
43+
['with ui', { props: { ui: { base: 'rounded-full' } } }],
1644
// Slots
17-
['with default slot', { props, slots: { default: () => 'Default slot' } }]
45+
['with default slot', { slots: { default: () => 'Default slot' } }]
1846
])('renders %s correctly', async (nameOrHtml: string, options: { props?: InputTimeProps, slots?: Partial<InputTimeSlots> }) => {
1947
const html = await ComponentRender(nameOrHtml, options, InputTime)
2048
expect(html).toMatchSnapshot()
2149
})
2250

51+
describe('emits', () => {
52+
test('update:modelValue event', async () => {
53+
const wrapper = await mountSuspended(InputTime)
54+
const time = new Time(12, 30)
55+
56+
await wrapper.setValue(time)
57+
expect(wrapper.emitted()).toMatchObject({ 'update:modelValue': [[time]] })
58+
})
59+
})
60+
2361
it('passes accessibility tests', async () => {
2462
const wrapper = await mountSuspended(InputTime, {
25-
props
63+
props: {
64+
modelValue: new Time(12, 30)
65+
}
2666
})
2767

2868
expect(await axe(wrapper.element)).toHaveNoViolations()

0 commit comments

Comments
 (0)