Files
gods-eye-view/src/ui/radioPanelActions.test.mjs
T
Sameh Khamis 5019bd9e8a feat(kit): render the sliders with UiSlider
UiSlider takes v-model, min, max, step and disabled
over Core's native range input, emits numbers, and with `hold` never
rewrites a focused handle and takes the model back on blur. It is a
functional render function, so the portable style parameter rows use it
too. The Display, Radio, RTL-SDR, Cockpit, mission replay and style
parameter sliders render with it; server-rendered markup keeps their
default values.
2026-11-01 11:27:52 -08:00

81 lines
2.3 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// src/ui/radioPanelActions.test.mjs — the Radio panel's controls call
// RadioControls through the radio store, and a refused station tag puts the
// select back on the tag the directory keeps.
import '../testSupport/registerDom.mjs';
import test from 'node:test';
import assert from 'node:assert/strict';
import { createApp } from 'vue';
import { createPinia } from 'pinia';
import { useRadioStore } from './stores/radio.js';
import RadioPanel from './views/panels/RadioPanel.vue';
function mount(t, { filter = (tag) => tag } = {}) {
document.body.replaceChildren();
const pinia = createPinia();
const calls = [];
useRadioStore(pinia).connect(
new Proxy(
{},
{
get:
(_, name) =>
(...args) => {
calls.push([name, ...args]);
return name === 'setRadioFilter' ? filter(...args) : undefined;
},
},
),
);
const app = createApp(RadioPanel).use(pinia);
app.mount(document.body.appendChild(document.createElement('div')));
t.after(() => app.unmount());
return calls;
}
const $ = (id) => document.getElementById(id);
const pickTag = (tag) => {
const select = $('radio-filter');
select.disabled = false;
const option = document.createElement('option');
option.value = tag;
select.append(option);
select.value = tag;
select.dispatchEvent(new Event('change', { bubbles: true }));
return select.value;
};
test('the panel’s Enable, transport and volume call RadioControls', (t) => {
const calls = mount(t);
for (const id of [
'radio-enable-btn',
'radio-prev-btn',
'radio-play-btn',
'radio-next-btn',
'radio-stop-btn',
]) {
$(id).disabled = false;
$(id).click();
}
$('radio-volume').disabled = false;
$('radio-volume').value = '35';
$('radio-volume').dispatchEvent(new Event('input', { bubbles: true }));
assert.deepEqual(calls, [
['toggleRadio', 'panel'],
['cycleRadio', -1],
['toggleRadioPlayback'],
['cycleRadio', 1],
['stopRadio'],
['setRadioVolume', 35],
]);
});
test('an accepted station tag stays picked', (t) => {
const calls = mount(t);
assert.equal(pickTag('jazz'), 'jazz');
assert.deepEqual(calls, [['setRadioFilter', 'jazz']]);
});
test('a refused station tag puts the select back on the kept tag', (t) => {
mount(t, { filter: () => 'all' });
assert.equal(pickTag('jazz'), 'all');
});