Files
orca/src/shared/currency-format.test.ts
T
Neilandmmarabel 2b0ce17514 Show provider credit balances alongside usage limits (#25408)
Display provider credit and currency balances separately from rate limits. Preserve quotas when balance data is unavailable and translate complete labels.

Supersedes #9363; credit to @mmarabel for the original implementation.

Co-authored-by: mmarabel <166927047+mmarabel@users.noreply.github.com>
2026-10-05 00:07:23 -07:00

31 lines
1.1 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import { formatCurrencyAmount } from './currency-format'
describe('formatCurrencyAmount', () => {
it('formats USD amounts with the dollar symbol', () => {
// Force a stable locale-independent expectation by asserting substrings.
const formatted = formatCurrencyAmount(12.4, 'USD')
expect(formatted).toMatch(/12[.,]40/)
expect(formatted).toContain('$')
})
it('formats EUR amounts with the euro symbol and thousands separator', () => {
const formatted = formatCurrencyAmount(2000, 'EUR')
expect(formatted).toContain('€')
expect(formatted).toMatch(/2[.,]000/)
})
it('falls back to code + amount for a malformed currency code', () => {
// A non-3-letter code makes Intl.NumberFormat throw, exercising the fallback.
expect(formatCurrencyAmount(9.5, 'ZZ')).toBe('ZZ 9.50')
})
it('defaults blank currency codes to USD', () => {
expect(formatCurrencyAmount(1, ' ')).toContain('$')
})
it('treats non-finite amounts as zero', () => {
expect(formatCurrencyAmount(Number.NaN, 'USD')).toMatch(/0[.,]00/)
})
})