import test from 'node:test'; import assert from 'node:assert/strict'; import { connectionField, connectionGroups } from '../app/renderer/js/connection-info.js'; import { menuPosition } from '../app/renderer/js/menu-position.js'; import { t, setLanguage } from '../app/renderer/js/i18n.js'; for (const locale of ['en', 'ru']) test(`connection fields preserve actual units, missing values and all records (${locale})`, () => { setLanguage(locale); const format = (key, value) => connectionField(key, value, t, locale); assert.equal(format('connection_ping', '12.5').value, new Intl.NumberFormat(locale, { style: 'unit', unit: 'millisecond', unitDisplay: 'short', maximumFractionDigits: 6 }).format(12.5)); assert.equal(format('connection_connected_time', '123456').value, new Intl.NumberFormat(locale, { style: 'unit', unit: 'second', unitDisplay: 'short', maximumFractionDigits: 3 }).format(123.456)); assert.equal(format('connection_packetloss_total', '0.025').value, new Intl.NumberFormat(locale, { style: 'percent', maximumFractionDigits: 4 }).format(0.025)); assert.equal(format('connection_packetloss_total', '2.5').value, '2.5'); // out-of-range is not silently rescaled for (const empty of [null, undefined, '']) assert.equal(format('connection_ping', empty).value, t('connectionInfo.notReported')); assert.notEqual(format('connection_ping', '0').value, t('connectionInfo.notReported')); assert.equal(format('connection_bytes_sent_total', '9007199254740993').value, new Intl.NumberFormat(locale, { style: 'unit', unit: 'byte', unitDisplay: 'short' }).format(9007199254740993n)); assert.equal(format('connection_bandwidth_sent_last_minute_total', '2048').value, new Intl.NumberFormat(locale, { style: 'unit', unit: 'byte-per-second', unitDisplay: 'short' }).format(2048)); assert.equal(format('connection_future_custom_metric', '123').value, '123'); assert.equal(format('future_field', '