style: format Radio component boundary

This commit is contained in:
Sameh Khamis committed 2026-09-12 23:25:09 -07:00
1 parent 7b9aca8597
commit bd6cc5abe8
7 files changed
+1393 -883

No files matched your search

+84 -28
View File
@@ -13,13 +13,22 @@ class Element extends EventTarget {
add: (...names) => names.forEach((n) => this.classes.add(n)),
remove: (...names) => names.forEach((n) => this.classes.delete(n)),
contains: (name) => this.classes.has(name),
toggle: (name, enabled) => enabled ? this.classes.add(name) : this.classes.delete(name),
toggle: (name, enabled) =>
enabled ? this.classes.add(name) : this.classes.delete(name),
};
}
setAttribute(name, value) { this.attrs.set(name, String(value)); }
getAttribute(name) { return this.attrs.get(name); }
querySelector() { return null; }
focus() { this.focusCount++; }
setAttribute(name, value) {
this.attrs.set(name, String(value));
}
getAttribute(name) {
return this.attrs.get(name);
}
querySelector() {
return null;
}
focus() {
this.focusCount++;
}
}
function fixture() {
@@ -34,25 +43,54 @@ function fixture() {
const calls = [];
const subscribers = [];
const radio = {
subscribe(callback) { subscribers.push(callback); calls.push('subscribe'); return () => calls.push('unsubscribe'); },
endTuning() { calls.push('endTuning'); },
cycleStation(direction) { calls.push(['cycle', direction]); return true; },
subscribe(callback) {
subscribers.push(callback);
calls.push('subscribe');
return () => calls.push('unsubscribe');
},
endTuning() {
calls.push('endTuning');
},
cycleStation(direction) {
calls.push(['cycle', direction]);
return true;
},
};
const actions = {
isRegistered: () => true, isEnabled: () => false,
isRegistered: () => true,
isEnabled: () => false,
runUserAction: (operation) => operation(),
setEnabled: async () => true,
setPanelCollapsed: (...args) => calls.push(['panel', ...args]),
layoutCockpit() {}, isCockpitActive: () => false,
scheduleLayout() {}, getLifecycle: () => null,
layoutCockpit() {},
isCockpitActive: () => false,
scheduleLayout() {},
getLifecycle: () => null,
preservePanelStateDuringClear: () => false,
};
const controls = new RadioControls({
elements: { _radioPanel: panel, _radioEnableBtn: enable, _radioNextBtn: next },
radio, actions, canvas: new Element(),
elements: {
_radioPanel: panel,
_radioEnableBtn: enable,
_radioNextBtn: next,
},
radio,
actions,
canvas: new Element(),
});
return { controls, enable, next, actions, calls, subscribers, document,
cleanup() { controls.destroy(); Object.assign(globalThis, prior); } };
return {
controls,
enable,
next,
actions,
calls,
subscribers,
document,
cleanup() {
controls.destroy();
Object.assign(globalThis, prior);
},
};
}
test('Radio listeners and subscriptions are revoked once before tuning teardown', () => {
@@ -61,7 +99,8 @@ test('Radio listeners and subscriptions are revoked once before tuning teardown'
f.controls.connect();
f.next.dispatchEvent(new Event('click'));
assert.deepEqual(f.calls, ['subscribe', ['cycle', 1]]);
f.controls.destroy(); f.controls.destroy();
f.controls.destroy();
f.controls.destroy();
const snapshot = structuredClone(f.calls);
f.next.dispatchEvent(new Event('click'));
f.document.dispatchEvent(new Event('gev:radio-selected'));
@@ -69,21 +108,28 @@ test('Radio listeners and subscriptions are revoked once before tuning teardown'
f.controls.connect();
assert.deepEqual(f.calls, snapshot);
assert.deepEqual(f.calls.slice(-2), ['unsubscribe', 'endTuning']);
} finally { f.cleanup(); }
} finally {
f.cleanup();
}
});
test('Radio reconnect removes its previous state subscription', () => {
const f = fixture();
try {
f.controls.connect(); f.controls.connect();
f.controls.connect();
f.controls.connect();
assert.deepEqual(f.calls, ['subscribe', 'unsubscribe', 'subscribe']);
} finally { f.cleanup(); }
} finally {
f.cleanup();
}
});
test('a delayed Radio enable cannot reveal or refocus controls after destruction', async () => {
const f = fixture();
let resolve;
const pending = new Promise((done) => { resolve = done; });
const pending = new Promise((done) => {
resolve = done;
});
try {
f.actions.setEnabled = () => pending;
f.enable.dispatchEvent(new Event('click'));
@@ -91,26 +137,36 @@ test('a delayed Radio enable cannot reveal or refocus controls after destruction
f.controls.destroy();
const attrs = new Map(f.enable.attrs);
resolve(true);
await pending; await new Promise((done) => setImmediate(done));
await pending;
await new Promise((done) => setImmediate(done));
assert.deepEqual(f.enable.attrs, attrs);
assert.equal(f.enable.focusCount, 0);
assert.equal(f.calls.some((call) => Array.isArray(call) && call[0] === 'panel'), false);
} finally { f.cleanup(); }
assert.equal(
f.calls.some((call) => Array.isArray(call) && call[0] === 'panel'),
false,
);
} finally {
f.cleanup();
}
});
test('destruction releases an active tuner pointer after revoking listeners', () => {
const f = fixture();
try {
const released = [];
f.controls._radioTunerSlider = { releasePointerCapture(id) {
assert.equal(f.controls.listeners.signal.aborted, true);
released.push(id);
} };
f.controls._radioTunerSlider = {
releasePointerCapture(id) {
assert.equal(f.controls.listeners.signal.aborted, true);
released.push(id);
},
};
f.controls._radioTunerPointerId = 7;
f.controls._radioTunerDragging = true;
f.controls.destroy();
assert.deepEqual(released, [7]);
assert.equal(f.controls._radioTunerDragging, false);
assert.equal(f.controls._radioTunerPointerId, null);
} finally { f.cleanup(); }
} finally {
f.cleanup();
}
});