mirror of
https://github.com/tiennm99/gsd-framework.git
synced 2026-05-23 00:25:26 +00:00
e4152a3dae
- Add package.json with Vitest, jsdom, Vite, and Preact dependencies - Configure Vitest with jsdom environment for component testing - Create test stubs for billStore (PEOPLE-01, PEOPLE-02, PEOPLE-03, PEOPLE-04) - Create test stubs for currency utilities (dollarsToCents, centsToDollars, formatCurrency) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
52 lines
1.3 KiB
JavaScript
52 lines
1.3 KiB
JavaScript
import { describe, it, expect } from 'vitest';
|
|
import { dollarsToCents, centsToDollars, formatCurrency } from '../src/utils/currency.js';
|
|
|
|
describe('currency utilities', () => {
|
|
describe('dollarsToCents', () => {
|
|
it('converts decimal string to cents', () => {
|
|
expect(dollarsToCents('15.99')).toBe(1599);
|
|
});
|
|
|
|
it('converts integer string to cents', () => {
|
|
expect(dollarsToCents('20')).toBe(2000);
|
|
});
|
|
|
|
it('handles single decimal place', () => {
|
|
expect(dollarsToCents('10.5')).toBe(1050);
|
|
});
|
|
|
|
it('handles zero', () => {
|
|
expect(dollarsToCents('0')).toBe(0);
|
|
});
|
|
|
|
it('rounds floating point precision', () => {
|
|
// 10.99 * 100 = 1098.9999... in JS
|
|
expect(dollarsToCents('10.99')).toBe(1099);
|
|
});
|
|
});
|
|
|
|
describe('centsToDollars', () => {
|
|
it('converts cents to dollar string', () => {
|
|
expect(centsToDollars(1599)).toBe('15.99');
|
|
});
|
|
|
|
it('handles zero', () => {
|
|
expect(centsToDollars(0)).toBe('0.00');
|
|
});
|
|
|
|
it('pads single digit cents', () => {
|
|
expect(centsToDollars(1050)).toBe('10.50');
|
|
});
|
|
});
|
|
|
|
describe('formatCurrency', () => {
|
|
it('formats cents as dollar string with $ prefix', () => {
|
|
expect(formatCurrency(1599)).toBe('$15.99');
|
|
});
|
|
|
|
it('formats zero', () => {
|
|
expect(formatCurrency(0)).toBe('$0.00');
|
|
});
|
|
});
|
|
});
|