Files
gods-eye-view/src/ui/radioPresentation.playbackError.test.mjs
T
Sameh Khamis 1072df325e feat(ui): render the Radio directory tuner from a store
RadioTuner renders the band label, readouts, slider and needle from the
Radio store. RadioControls keeps the drag and its slot and publishes what
the tuner shows; the component lays out the tick tape against the dial's
measured width, drawing no ticks before it has one, and lays out the
snapped needle before it drops the drag class so the needle does not
animate from where the drag let go.
2026-10-31 17:15:05 -07:00

72 lines
1.9 KiB
JavaScript

import test from 'node:test';
import assert from 'node:assert/strict';
import { setLocale } from '../i18n/index.js';
import { renderRadioState } from './radioPresentation.js';
function el() {
const classes = new Set();
return {
textContent: '',
classList: {
toggle(name, on) {
on ? classes.add(name) : classes.delete(name);
},
contains: (name) => classes.has(name),
},
};
}
function render(audioError) {
globalThis.document = { getElementById: () => null, activeElement: null };
let shown = null;
const host = {
destroyed: false,
_radioPanel: el(),
store: { publish: (view) => (shown = view), publishTuner() {} },
actions: {
getLifecycle: () => null,
preservePanelStateDuringClear: () => false,
setPanelCollapsed() {},
scheduleLayout() {},
},
};
renderRadioState.call(host, {
enabled: true,
audioState: 'error',
audioError,
filteredCount: 1,
stationCount: 1,
volume: 1,
});
return shown.playback.text;
}
const PLAYBACK_ERRORS = [
'Playback requires a direct click or tap.',
'Broadcaster stream could not be started.',
'Broadcaster stream is unavailable or blocked by the browser.',
];
for (const locale of ['es', 'ru']) {
test(`radio playback errors are localized in ${locale}`, () => {
setLocale(locale);
try {
for (const message of PLAYBACK_ERRORS) {
assert.notEqual(render(message), message, `${locale}: ${message}`);
}
// Control: the fallback (no audioError) is translated.
assert.notEqual(render(null), 'Broadcaster stream unavailable');
} finally {
setLocale('en');
}
});
}
test('radio playback errors stay English', () => {
setLocale('en');
for (const message of PLAYBACK_ERRORS) {
assert.equal(render(message), message);
}
assert.equal(render(null), 'Broadcaster stream unavailable');
});