/* Copyright (C) 2025 QuantumNous This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see . For commercial licensing, please contact support@quantumnous.com */ import assert from 'node:assert/strict'; import test from 'node:test'; import { formatPercent, formatRatioPercent, formatIdReference, formatUserReference, toFiniteNumber, } from '../../src/helpers/safeDisplay.js'; test('toFiniteNumber rejects missing and non-finite display values', () => { assert.equal(toFiniteNumber(undefined), null); assert.equal(toFiniteNumber(''), null); assert.equal(toFiniteNumber('not-a-number'), null); assert.equal(toFiniteNumber('12.5'), 12.5); assert.equal(toFiniteNumber(Infinity), null); }); test('percent formatters never expose invalid values', () => { assert.equal(formatPercent(undefined), '-'); assert.equal(formatPercent('12.5'), '12.5%'); assert.equal(formatRatioPercent(undefined, 10), '-'); assert.equal(formatRatioPercent(2, 0), '-'); assert.equal(formatRatioPercent(2, 4), '50.0%'); }); test('user references never interpolate an undefined id', () => { assert.equal(formatUserReference('Alice', undefined), 'Alice'); assert.equal(formatUserReference('', 42), 'User#42'); assert.equal(formatUserReference(undefined, undefined), '-'); assert.equal( formatUserReference(undefined, 'bad', 'Unknown user'), 'Unknown user', ); }); test('id references never expose a missing identifier', () => { assert.equal(formatIdReference(undefined), '-'); assert.equal(formatIdReference(''), '-'); assert.equal(formatIdReference(42), '#42'); });