admin/lib/birthDate.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

33 lines
1.3 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { describe, expect, it } from 'vitest'
import { clampJalaliDateParts, isAllowedBirthDate, isoDateToJalaliParts, jalaliPartsToIsoDate } from '@/lib/birthDate'
describe('birth date helpers', () => {
it('converts Jalali wheel values to a Gregorian date-only string', () => {
expect(jalaliPartsToIsoDate({ day: '1', month: '1', year: '1370' })).toBe('1991-03-21')
expect(jalaliPartsToIsoDate({ day: '1', month: '1', year: '1330' })).toBe('1951-03-22')
expect(jalaliPartsToIsoDate({ day: '30', month: '12', year: '1395' })).toBe('2017-03-20')
})
it('clamps Esfand days to the selected Jalali year length', () => {
expect(clampJalaliDateParts({ day: '31', month: '12', year: '1395' })).toEqual({
day: '30',
month: '12',
year: '1395',
})
expect(clampJalaliDateParts({ day: '31', month: '7', year: '1370' })).toEqual({
day: '30',
month: '7',
year: '1370',
})
})
it('accepts only ISO dates whose Jalali year is 13301395', () => {
expect(isAllowedBirthDate('1991-03-21')).toBe(true)
expect(isoDateToJalaliParts('1991-03-21')).toEqual({ day: '1', month: '1', year: '1370' })
expect(isAllowedBirthDate('1951-03-21')).toBe(false)
expect(isAllowedBirthDate('2018-01-01')).toBe(false)
expect(isAllowedBirthDate('1991-03-21T00:00:00.000Z')).toBe(false)
})
})