SEV-362: format v0.2.0 — boundary spacing, acronyms, formatRange, numeric budget

- formatLabel: letter→digit boundary spacing ("level2" → "Level 2"),
  acronym casing (DCFC/EV/SUV/VIN/DC/A\C), bare numeric ranges pass
  through untouched
- new formatRange: "150-200" → "150–200 mi", "200-plus"/"200+" →
  "200+ mi"; empty → '' (callers render their own placeholder)
- formatBudget is now the numeric (min, max) dollar formatter matching
  the API payload; the wizard's slug map moves to formatBudgetBucket
- new vehicleName({year, make, model, commissioned})

Breaking rename of formatBudget is safe: no frontend consumes 0.1.0.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Bastian de Byl
2026-06-09 21:08:03 -04:00
parent 50379c1868
commit 65889b6487
4 changed files with 121 additions and 16 deletions
+49 -5
View File
@@ -1,6 +1,9 @@
import { test } from 'node:test';
import assert from 'node:assert/strict';
import { formatLabel, formatStatus, formatTimeline, formatBudget } from './format.js';
import {
formatLabel, formatStatus, formatTimeline, formatRange,
formatBudget, formatBudgetBucket, vehicleName,
} from './format.js';
test('formatLabel replaces _ and - and title-cases', () => {
assert.equal(formatLabel('contract_pending'), 'Contract Pending');
@@ -9,6 +12,22 @@ test('formatLabel replaces _ and - and title-cases', () => {
assert.equal(formatLabel(null), '');
});
test('formatLabel spaces letter→digit boundaries (SEV-362)', () => {
assert.equal(formatLabel('level2'), 'Level 2');
assert.equal(formatLabel('level1'), 'Level 1');
});
test('formatLabel applies acronym casing (SEV-362)', () => {
assert.equal(formatLabel('dcfc'), 'DCFC');
assert.equal(formatLabel('dc_fast'), 'DC Fast');
assert.equal(formatLabel('keep_original_ac'), 'Keep Original A/C');
});
test('formatLabel leaves bare numeric ranges intact (SEV-362)', () => {
assert.equal(formatLabel('100-150'), '100-150');
assert.equal(formatLabel('200+'), '200+');
});
test('formatStatus is formatLabel', () => {
assert.equal(formatStatus('matched'), 'Matched');
});
@@ -19,8 +38,33 @@ test('formatTimeline maps known slugs, falls back otherwise', () => {
assert.equal(formatTimeline('something_else'), 'Something Else');
});
test('formatBudget maps known ranges', () => {
assert.equal(formatBudget('25k-50k'), '$25,000 $50,000');
assert.equal(formatBudget('100k-plus'), '$100,000+');
assert.equal(formatBudget(''), '');
test('formatRange formats wizard range slugs (SEV-362)', () => {
assert.equal(formatRange('150-200'), '150200 mi');
assert.equal(formatRange('100-150'), '100150 mi');
assert.equal(formatRange('200+'), '200+ mi');
assert.equal(formatRange('200-plus'), '200+ mi');
assert.equal(formatRange('250'), '250 mi');
assert.equal(formatRange(''), '');
assert.equal(formatRange(null), '');
});
test('formatBudget formats numeric dollar ranges (SEV-362)', () => {
assert.equal(formatBudget(30000, 60000), '$30,000 $60,000');
assert.equal(formatBudget(30000, 0), '$30,000+');
assert.equal(formatBudget(0, 60000), 'Up to $60,000');
assert.equal(formatBudget(0, 0), 'Flexible');
assert.equal(formatBudget(undefined, undefined), 'Flexible');
});
test('formatBudgetBucket keeps the wizard slug labels', () => {
assert.equal(formatBudgetBucket('25k-50k'), '$25,000 $50,000');
assert.equal(formatBudgetBucket(''), '');
});
test('vehicleName handles commissioned and sparse vehicles', () => {
assert.equal(vehicleName({ year: 1980, make: 'BMW', model: 'E30' }), '1980 BMW E30');
assert.equal(vehicleName({ commissioned: true }), 'Commissioned build');
assert.equal(vehicleName({}), 'Project');
assert.equal(vehicleName({ make: 'BMW' }, 'Lead'), 'BMW');
assert.equal(vehicleName(undefined), 'Project');
});