Preserve accumulated client implementation since v0.1.4, including local identities, multi-server state, chat, administration, audio and streaming controls. Refine official-source layout, original artwork, responsive composer overflow, settings navigation and chat scroll anchoring. Current verification: Node suite passes; isolated packaged chat and responsive control smokes pass without device capture. Native core is reused, not rebuilt in this pass. Strict whole-screen visual parity remains incomplete; no 1:1 or cross-platform acceptance claim. Local checkpoint only; no release or push.
45 lines
3.8 KiB
JavaScript
45 lines
3.8 KiB
JavaScript
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', '<script>').value, '<script>');
|
|
assert.equal(format('future_field', { detail: 2 }).value, '{"detail":2}');
|
|
const fields = { clid: '2', connection_client_ip: '2001:db8::1', connection_ping: null, future_field: 'preserved' };
|
|
for (const kind of ['speech', 'keepalive', 'control', 'total']) for (const direction of ['sent', 'received']) {
|
|
fields[`connection_packets_${direction}_${kind}`] = '1';
|
|
fields[`connection_bytes_${direction}_${kind}`] = '2';
|
|
fields[`connection_bandwidth_${direction}_last_minute_${kind}`] = '3';
|
|
fields[`connection_bandwidth_${direction}_last_second_${kind}`] = '4';
|
|
}
|
|
const grouped = connectionGroups(fields, t, locale).flatMap(group => group.fields);
|
|
assert.equal(grouped.length, 36);
|
|
assert.deepEqual(new Set(grouped.map(field => field.key)), new Set(Object.keys(fields)));
|
|
assert.ok(grouped.every(field => !field.label.startsWith('connectionInfo.')));
|
|
});
|
|
|
|
test('pointer anchors flip at the pointer, then clamp; CSS pixels do not scale with DPI', () => {
|
|
const viewport = { width: 1000, height: 820, top: 40 }, size = { width: 310, height: 500 };
|
|
assert.deepEqual(menuPosition({ left: 850, right: 850, top: 110, bottom: 110 }, size, viewport), { x: 540, y: 110 });
|
|
assert.deepEqual(menuPosition({ left: 15, right: 300, top: 120, bottom: 150 }, size, viewport), { x: 15, y: 150 });
|
|
assert.deepEqual(menuPosition({ left: 700, right: 700, top: 780, bottom: 780 }, size, viewport), { x: 390, y: 280 });
|
|
assert.deepEqual(menuPosition({ left: 0, right: 0, top: 0, bottom: 0 }, size, viewport), { x: 8, y: 40 });
|
|
// Group/volume pages replace the root page; the original member/pointer anchor remains unchanged.
|
|
const anchor = { left: 650, right: 950, top: 680, bottom: 714 };
|
|
assert.deepEqual(menuPosition(anchor, size, viewport), { x: 650, y: 180 });
|
|
assert.deepEqual(menuPosition(anchor, { width: 310, height: 200 }, viewport), { x: 650, y: 480 });
|
|
});
|