优化预约作品选择和日期时间选择
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import {
|
||||
buildDatePickerMonth,
|
||||
buildHourOptions,
|
||||
buildMinuteOptions,
|
||||
cancelPickerDraft,
|
||||
confirmPickerDraft,
|
||||
createPickerDraft,
|
||||
joinTimeParts,
|
||||
normalizeTimeParts,
|
||||
updatePickerDraft
|
||||
} from '@/utils/picker-options'
|
||||
|
||||
describe('picker options', () => {
|
||||
it('builds a sunday-first month grid with selected date', () => {
|
||||
const days = buildDatePickerMonth('2026-07-02', '2026-07-02')
|
||||
|
||||
expect(days).toHaveLength(42)
|
||||
expect(days.slice(0, 7).map(item => item.date)).toEqual([
|
||||
'2026-06-28',
|
||||
'2026-06-29',
|
||||
'2026-06-30',
|
||||
'2026-07-01',
|
||||
'2026-07-02',
|
||||
'2026-07-03',
|
||||
'2026-07-04'
|
||||
])
|
||||
expect(days.find(item => item.date === '2026-07-02')?.isSelected).toBe(true)
|
||||
expect(days.find(item => item.date === '2026-06-30')?.isCurrentMonth).toBe(false)
|
||||
})
|
||||
|
||||
it('builds hour and minute options', () => {
|
||||
expect(buildHourOptions()[0]).toBe('00')
|
||||
expect(buildHourOptions()[23]).toBe('23')
|
||||
expect(buildMinuteOptions()[0]).toBe('00')
|
||||
expect(buildMinuteOptions()[59]).toBe('59')
|
||||
})
|
||||
|
||||
it('normalizes and joins time values', () => {
|
||||
expect(normalizeTimeParts('7:5')).toEqual({ hour: '07', minute: '05' })
|
||||
expect(normalizeTimeParts('30:90')).toEqual({ hour: '23', minute: '59' })
|
||||
expect(joinTimeParts('9', '8')).toBe('09:08')
|
||||
})
|
||||
|
||||
it('keeps committed value unchanged until confirm', () => {
|
||||
const draft = createPickerDraft('2026-07-02', '2026-07-01')
|
||||
const changedDraft = updatePickerDraft(draft, '2026-07-08')
|
||||
|
||||
expect(cancelPickerDraft(changedDraft)).toBe('2026-07-02')
|
||||
expect(confirmPickerDraft(changedDraft)).toBe('2026-07-08')
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user