Files
gods-eye-view/src/ui/radioPresentationTransition.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

65 lines
1.8 KiB
JavaScript

import assert from 'node:assert/strict';
import { test } from 'node:test';
import { renderRadioState } from './radioPresentation.js';
function el() {
const attrs = new Map();
return {
textContent: '',
hidden: false,
disabled: false,
style: {},
dataset: {},
classList: { toggle() {}, add() {}, remove() {}, contains: () => false },
setAttribute: (k, v) => attrs.set(k, String(v)),
getAttribute: (k) => attrs.get(k),
attrs,
};
}
for (const lifecycleState of ['enabling', 'disabling']) {
test(`Radio render survives the ${lifecycleState} transition`, () => {
const prior = globalThis.document;
globalThis.document = { getElementById: () => null };
try {
let shown = null;
const ctx = {
destroyed: false,
_radioPanel: el(),
store: { publish: (view) => (shown = view), publishTuner() {} },
actions: {
getLifecycle: () => ({
lifecycleState,
enabled: lifecycleState === 'disabling',
uncertain: false,
}),
},
};
const state = {
enabled: false,
categories: [],
filteredCount: 0,
stationCount: 0,
audioState: 'idle',
};
try {
renderRadioState.call(ctx, state);
} catch (error) {
// Anything thrown after the transitional label is a different
// missing fixture field, not the bug under test.
assert.ok(
!(
error instanceof ReferenceError &&
/lifecycleLabel/.test(error.message)
),
`render threw: ${error.message}`,
);
}
assert.equal(shown.enable.busy, true);
assert.equal(shown.enable.text, lifecycleState.toUpperCase());
} finally {
globalThis.document = prior;
}
});
}