admin/components/events/schedule/eventScheduleConstraints.test.ts
alisaza e1eaf5eff5 feat: initial ghabilee-admin backoffice app
Extract admin dashboard from ghabilee-frontend2 into a dedicated Next.js
app for backoffice.ghabilee.ir (no SEO indexing / Clarity).
2026-09-05 13:12:59 +03:30

56 lines
1.7 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import { getEventScheduleConstraints } from '@/components/events/schedule/eventScheduleConstraints'
const localIso = (year: number, month: number, day: number) => new Date(year, month, day).toISOString()
describe('getEventScheduleConstraints', () => {
it('uses the next minute for a start today and start + 1 for a same-day end', () => {
const today = localIso(2026, 7, 11)
const result = getEventScheduleConstraints({
now: new Date(2026, 7, 11, 10, 30),
startDate: today,
startTime: 12 * 60,
endDate: today,
})
expect(result.startMinimumTime).toBe(10 * 60 + 31)
expect(result.endMinimumTime).toBe(12 * 60 + 1)
})
it('does not constrain a future start or an end on a later day', () => {
const result = getEventScheduleConstraints({
now: new Date(2026, 7, 11, 10, 30),
startDate: localIso(2026, 7, 12),
startTime: 12 * 60,
endDate: localIso(2026, 7, 13),
})
expect(result.startMinimumTime).toBe(0)
expect(result.endMinimumTime).toBe(0)
})
it('caps the next-minute boundary at the end of the day', () => {
const today = localIso(2026, 7, 11)
const result = getEventScheduleConstraints({
now: new Date(2026, 7, 11, 23, 59),
startDate: today,
endDate: today,
})
expect(result.startMinimumTime).toBe(1440)
expect(result.endMinimumTime).toBe(1)
})
it('ignores invalid or missing date values', () => {
const result = getEventScheduleConstraints({
now: new Date(2026, 7, 11, 10, 30),
startDate: 'invalid',
endDate: undefined,
})
expect(result.startMinimumTime).toBe(0)
expect(result.endMinimumTime).toBe(0)
})
})