Files
shared/src/format.test.js
T
Bastian de Byl 137086109c SEV-329: @switchev/web-shared package — formatters, markdown, waitForImage
Stands up the shared browser-helpers package (consumed by public/vendor/admin
via the Gitea npm registry) to de-duplicate copy-pasted frontend code:
- format.js: formatLabel/formatStatus/formatTimeline/formatBudget (single source
  of truth — these had drifted, see SEV-310).
- markdown.js: renderMarkdown (marked + strict DOMPurify; both peer deps).
- wait-image.js: waitForImage (was byte-identical in public + vendor).

ESM source package (no build step — Vite consumers import directly). publishConfig
points at the Gitea npm registry. node --test green (formatters).

Next: publish v0.1.0, then migrate each site to consume it and delete the copies.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-09 09:42:38 -04:00

27 lines
1009 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { test } from 'node:test';
import assert from 'node:assert/strict';
import { formatLabel, formatStatus, formatTimeline, formatBudget } from './format.js';
test('formatLabel replaces _ and - and title-cases', () => {
assert.equal(formatLabel('contract_pending'), 'Contract Pending');
assert.equal(formatLabel('in-progress'), 'In Progress');
assert.equal(formatLabel(''), '');
assert.equal(formatLabel(null), '');
});
test('formatStatus is formatLabel', () => {
assert.equal(formatStatus('matched'), 'Matched');
});
test('formatTimeline maps known slugs, falls back otherwise', () => {
assert.equal(formatTimeline('6_to_12_months'), '612 months');
assert.equal(formatTimeline('flexible'), 'Flexible');
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(''), '');
});