|
1 | | -import { describe, it, expect } from 'vitest' |
| 1 | +import { describe, it, expect, vi, afterAll, test } from 'vitest' |
2 | 2 | import { axe } from 'vitest-axe' |
3 | 3 | import { mountSuspended } from '@nuxt/test-utils/runtime' |
4 | 4 | import InputTime from '../../src/runtime/components/InputTime.vue' |
5 | 5 | import type { InputTimeProps, InputTimeSlots } from '../../src/runtime/components/InputTime.vue' |
6 | 6 | import ComponentRender from '../component-render' |
| 7 | +import theme from '#build/ui/input-time' |
| 8 | +import { Time } from '@internationalized/date' |
7 | 9 |
|
8 | 10 | 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 | + }) |
10 | 20 |
|
11 | 21 | it.each([ |
12 | 22 | // 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' } }], |
13 | 41 | ['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' } } }], |
16 | 44 | // Slots |
17 | | - ['with default slot', { props, slots: { default: () => 'Default slot' } }] |
| 45 | + ['with default slot', { slots: { default: () => 'Default slot' } }] |
18 | 46 | ])('renders %s correctly', async (nameOrHtml: string, options: { props?: InputTimeProps, slots?: Partial<InputTimeSlots> }) => { |
19 | 47 | const html = await ComponentRender(nameOrHtml, options, InputTime) |
20 | 48 | expect(html).toMatchSnapshot() |
21 | 49 | }) |
22 | 50 |
|
| 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 | + |
23 | 61 | it('passes accessibility tests', async () => { |
24 | 62 | const wrapper = await mountSuspended(InputTime, { |
25 | | - props |
| 63 | + props: { |
| 64 | + modelValue: new Time(12, 30) |
| 65 | + } |
26 | 66 | }) |
27 | 67 |
|
28 | 68 | expect(await axe(wrapper.element)).toHaveNoViolations() |
|
0 commit comments