Extract admin dashboard from ghabilee-frontend2 into a dedicated Next.js app for backoffice.ghabilee.ir (no SEO indexing / Clarity).
56 lines
1.9 KiB
TypeScript
56 lines
1.9 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
||
|
||
import { formatIranianMobile, formatPersianDate, truncateValue } from '@/lib/formatters'
|
||
|
||
describe('formatPersianDate', () => {
|
||
it('returns the fallback for empty and invalid values', () => {
|
||
expect(formatPersianDate(null)).toBe('—')
|
||
expect(formatPersianDate('not-a-date')).toBe('—')
|
||
expect(formatPersianDate('not-a-date', { dateStyle: 'medium' }, 'نامعتبر')).toBe('نامعتبر')
|
||
})
|
||
|
||
it('formats valid dates using the Persian locale and requested options', () => {
|
||
const value = formatPersianDate('2025-01-01T12:30:00.000Z', { dateStyle: 'medium' })
|
||
|
||
expect(value).toMatch(/[۰-۹]/)
|
||
})
|
||
|
||
it('uses Asia/Tehran so SSR (UTC) and client timezones match', () => {
|
||
const utcEnv = new Intl.DateTimeFormat('fa-IR', { dateStyle: 'medium', timeStyle: 'short', timeZone: 'UTC' }).format(
|
||
new Date('2026-08-27T08:00:00.000Z')
|
||
)
|
||
const display = formatPersianDate('2026-08-27T08:00:00.000Z')
|
||
|
||
expect(display).not.toBe(utcEnv)
|
||
expect(display).toBe(
|
||
new Intl.DateTimeFormat('fa-IR', {
|
||
dateStyle: 'medium',
|
||
timeStyle: 'short',
|
||
timeZone: 'Asia/Tehran',
|
||
}).format(new Date('2026-08-27T08:00:00.000Z'))
|
||
)
|
||
})
|
||
})
|
||
|
||
describe('formatIranianMobile', () => {
|
||
it('normalizes an Iranian country-code number', () => {
|
||
expect(formatIranianMobile('989121234567')).toBe('09121234567')
|
||
})
|
||
|
||
it('keeps other strings and handles missing values', () => {
|
||
expect(formatIranianMobile('09121234567')).toBe('09121234567')
|
||
expect(formatIranianMobile(undefined)).toBe('—')
|
||
})
|
||
})
|
||
|
||
describe('truncateValue', () => {
|
||
it('truncates long text with a single ellipsis character', () => {
|
||
expect(truncateValue('abcdefgh', 5)).toBe('abcde…')
|
||
})
|
||
|
||
it('keeps short text and handles blank values', () => {
|
||
expect(truncateValue('short', 5)).toBe('short')
|
||
expect(truncateValue(' ')).toBe('—')
|
||
})
|
||
})
|