admin/helpers/numberToPersianWords.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

48 lines
1.9 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import { formatTomanInWords, numberToPersianWords, parseAmountInputValue } from '@/helpers/numberToPersianWords'
describe('numberToPersianWords', () => {
it('handles zero and small numbers', () => {
expect(numberToPersianWords(0)).toBe('صفر')
expect(numberToPersianWords(1)).toBe('یک')
expect(numberToPersianWords(15)).toBe('پانزده')
expect(numberToPersianWords(21)).toBe('بیست و یک')
expect(numberToPersianWords(100)).toBe('صد')
expect(numberToPersianWords(101)).toBe('صد و یک')
expect(numberToPersianWords(250)).toBe('دویست و پنجاه')
})
it('handles thousands and millions', () => {
expect(numberToPersianWords(1000)).toBe('یک هزار')
expect(numberToPersianWords(450_000)).toBe('چهارصد و پنجاه هزار')
expect(numberToPersianWords(1_000_000)).toBe('یک میلیون')
expect(numberToPersianWords(1_250_000)).toBe('یک میلیون و دویست و پنجاه هزار')
})
it('rejects invalid values', () => {
expect(numberToPersianWords(-1)).toBe('')
expect(numberToPersianWords(1.5)).toBe('')
expect(numberToPersianWords(Number.NaN)).toBe('')
})
})
describe('parseAmountInputValue', () => {
it('parses numbers and digit strings', () => {
expect(parseAmountInputValue(1200)).toBe(1200)
expect(parseAmountInputValue('1200')).toBe(1200)
expect(parseAmountInputValue('۱۲۰۰')).toBe(1200)
expect(parseAmountInputValue('')).toBeNull()
expect(parseAmountInputValue(null)).toBeNull()
})
})
describe('formatTomanInWords', () => {
it('appends تومان and hides empty/zero', () => {
expect(formatTomanInWords(0)).toBe('')
expect(formatTomanInWords('')).toBe('')
expect(formatTomanInWords(100_000)).toBe('صد هزار تومان')
expect(formatTomanInWords('۲۵۰۰۰۰')).toBe('دویست و پنجاه هزار تومان')
})
})