codeburn/tests/format-mark-estimated.test.ts
Resham Joshi b2be8eba56
feat: mark estimated dollars the same way in every view (#1657)
* Mark estimated costs with the same ~ in every view

The ~ marker and legend that report already used now appear wherever a
dollar figure is mostly a guess: the models and sessions CLI output, the
desktop Models, Overview, Sessions and Settings provider rows, the macOS
menu bar model rows and provider tabs, and the Windows tray.

One rule decides the marker everywhere: the estimated portion is at least
1% of the figure. report, overview and the MCP tables switch to it from
"any estimated cent", so a metered Codex row holding a few text-estimated
turns stays unmarked.

JSON is additive: estimatedCostUSD and isEstimated on models rows,
estimatedCost and isEstimated on sessions rows, estimatedCostUSD on
menubar providerDetails rows. Totals are unchanged.

* Skip the ~ marker on figures that print as zero

A sub-cent row that is fully estimated printed as "~$0.00": nothing visible
to qualify. The shared helper now also requires the amount, as the surface
prints it in the active currency, to show a non-zero digit. CLI, desktop,
macOS and Windows helpers all apply it.
2026-10-06 22:27:13 +02:00

39 lines
1.3 KiB
TypeScript

import { describe, it, expect } from 'vitest'
import { isEstimatedCost, markEstimated } from '../src/format.js'
describe('markEstimated', () => {
it('prefixes the estimated marker when the figure is estimated', () => {
expect(markEstimated('$1.23', true)).toBe('~$1.23')
})
it('leaves a measured figure untouched', () => {
expect(markEstimated('$1.23', false)).toBe('$1.23')
})
})
describe('isEstimatedCost', () => {
it('marks a fully estimated row', () => {
expect(isEstimatedCost(579.13, 579.13)).toBe(true)
})
it('marks a partly estimated row once the estimate reaches 1% of it', () => {
expect(isEstimatedCost(10, 0.1)).toBe(true)
expect(isEstimatedCost(10, 2.5)).toBe(true)
})
it('leaves a metered row with a sub-1% estimated sliver unmarked', () => {
expect(isEstimatedCost(1.4375, 0.0043)).toBe(false)
})
it('leaves a fully estimated figure unmarked when it reads as zero', () => {
expect(isEstimatedCost(0.0003, 0.0003, '$0.00')).toBe(false)
expect(isEstimatedCost(0.0003, 0.0003, '$0.0003')).toBe(true)
})
it('leaves an exact row unmarked', () => {
expect(isEstimatedCost(12, 0)).toBe(false)
expect(isEstimatedCost(12, undefined)).toBe(false)
expect(isEstimatedCost(0, 0)).toBe(false)
})
})