Files
gods-eye-view/src/ui/statusText.test.mjs
T
German KhokhlovandClaude Opus 5.5 20f4cf3763 i18n: fix the LGTM review findings and tidy the branch texts
- i18n scanner: lastError sink, no false sinks on defaults and ternaries
- shared src/i18n/marker.js for modules that only mark strings
- wind field messages move to wind/fields.js; CITY_POIS imports from cityPois.js
- drop review IDs, change history and stale references from comments and docs

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-16 21:00:28 +04:00

78 lines
2.4 KiB
JavaScript

// Layer status texts arrive as English data and show in the UI language by
// their shape; English shows exactly as it came.
import assert from 'node:assert/strict';
import test from 'node:test';
import { setLocale, t } from '../i18n/index.js';
import { translateFeedError, translateStatusLine } from './statusText.js';
function inLocale(locale, run) {
setLocale(locale);
try {
return run();
} finally {
setLocale('en');
}
}
const STATUS_LINES = [
'feed 1090 unreachable',
'feeds 1090, entry 2 invalid',
'3 heard · USB 5.8 msg/s · feed 1090 stale',
'2 feeds live · 14 heard',
'TTC 0 (95s old)',
'TTC 0 · GO Transit 4 (95s old)',
'Loading TTC, MiWay',
];
test('en: status lines and errors show as they came', () => {
setLocale('en');
for (const text of [
...STATUS_LINES,
'ECCC HTTP 503',
'GNSS feed unavailable (HTTP 503)',
'Upstream response too large',
]) {
assert.equal(translateFeedError(text), text);
assert.equal(translateStatusLine(text), text);
}
});
for (const locale of ['es', 'ru']) {
test(`${locale}: a lone feed problem translates like a joined one`, () => {
inLocale(locale, () => {
const lone = translateFeedError('feed 1090 unreachable');
assert.doesNotMatch(lone, /unreachable/, lone);
assert.equal(
translateFeedError('feed 1090 unreachable · 2 heard').split(' · ')[0],
lone,
);
});
});
test(`${locale}: a feed with no band is named in the UI language`, () => {
inLocale(locale, () => {
const shown = translateFeedError('feeds 1090, entry 2 invalid');
assert.doesNotMatch(shown, /\b(entry|invalid)\b/, shown);
assert.ok(shown.includes(t('entry {n}', { n: 2 })), shown);
assert.ok(shown.includes('1090'), shown);
});
});
test(`${locale}: a quiet transit feed keeps its name and numbers`, () => {
inLocale(locale, () => {
const shown = translateStatusLine('TTC 0 · GO Transit 4 (95s old)');
assert.doesNotMatch(shown, /\bold\b/, shown);
assert.ok(shown.startsWith('TTC 0 · GO Transit 4 '), shown);
assert.ok(shown.includes('95'), shown);
});
});
test(`${locale}: a known error shows its catalog entry`, () => {
inLocale(locale, () => {
const text = 'Upstream response too large';
assert.notEqual(t(text), text, 'the catalog has the entry');
assert.equal(translateFeedError(text), t(text));
});
});
}