import { describe, expect, it } from 'vitest' import { toJalaali } from 'jalaali-js' import { constrainEventDatePickerValue, eventDatePickerValueToIso, getEventDatePickerValue, getEventTimePickerValue, } from '@/components/events/schedule/EventScheduleFieldControl' describe('EventScheduleFieldControl helpers', () => { it('keeps the hidden Jalaali year when changing day and month', () => { const previousValue = new Date(2026, 2, 21, 12).toISOString() const previousYear = toJalaali(new Date(previousValue)).jy const nextValue = eventDatePickerValueToIso({ day: '12', month: '8', year: String(previousYear) }, previousValue) expect(toJalaali(new Date(nextValue))).toEqual({ jy: previousYear, jm: 8, jd: 12 }) }) it('clamps an invalid day to the selected Jalaali month length', () => { const previousValue = new Date(2026, 2, 21, 12).toISOString() const previousYear = toJalaali(new Date(previousValue)).jy const nextValue = eventDatePickerValueToIso({ day: '31', month: '7', year: String(previousYear) }, previousValue) expect(getEventDatePickerValue(nextValue)).toEqual({ day: '30', month: '7', year: String(previousYear) }) }) it('moves an empty or past value to the minimum selectable date', () => { const minimum = new Date(2026, 6, 30, 12) const expected = getEventDatePickerValue(minimum.toISOString()) expect(constrainEventDatePickerValue('', minimum.toISOString())).toEqual(expected) expect(constrainEventDatePickerValue(new Date(2026, 6, 29, 12).toISOString(), minimum.toISOString())).toEqual(expected) }) it('normalizes event minutes to a valid wheel time', () => { expect(getEventTimePickerValue(1500)).toEqual({ hour: '23', minute: '59' }) expect(getEventTimePickerValue(-10)).toEqual({ hour: '0', minute: '0' }) }) })