import test from 'node:test' import assert from 'node:assert/strict' import {formatMoney} from '../../src/utils/money-display.js' test('project amounts use grouping and fixed decimal places for numbers and decimal strings',()=>{ for (const value of [1234567.8,'1234567.80']) assert.equal(formatMoney(value),'1,234,567.80') assert.equal(formatMoney(0),'0.00') assert.equal(formatMoney(-12345.67),'-12,345.67') assert.equal(formatMoney('999.999'),'1,000.00') assert.equal(formatMoney(12),'12.00') }) test('unit costs retain six decimal places and formatting leaves source values numeric',()=>{ const project={totalAmount:1234567.8,unitCost:'1234.123456'} assert.equal(formatMoney(project.unitCost,6),'1,234.123456') assert.equal(formatMoney(project.totalAmount),'1,234,567.80') assert.deepEqual(project,{totalAmount:1234567.8,unitCost:'1234.123456'}) }) test('empty totals keep the existing zero fallback and invalid numbers never render NaN or Infinity',()=>{ for(const value of [undefined,null,'']) assert.equal(formatMoney(value),'0.00') for(const value of ['invalid',NaN,Infinity,-Infinity]) assert.equal(formatMoney(value),'—') })