feat(voice): render the voice control from a presenter

createVoiceControl now returns a presenter instead of building the
control with innerHTML: the session, cost, input, card and panel owners
write its state by part and listen for interactions, and VoiceControl.vue
renders it in the command dock, between the location bar and the visual
presets as before. Focus moves wait for the render; the waveform's bars
publish apart from the control and only when they change; the minutes
field keeps a draft until its owner writes it. Owner tests use a real
presenter on their own store, and view tests render the control.
This commit is contained in:
Sameh Khamis committed 2026-10-31 19:22:03 -07:00
1 parent 2ffd7a4afd
commit 1de4f635ca
47 files changed
+1691 -1645

No files matched your search

+97 -86
View File
@@ -1,54 +1,25 @@
import '../../testSupport/registerDom.mjs';
import test from 'node:test';
import assert from 'node:assert/strict';
import { createManualVoicePanel } from './manualPanel.js';
import { createTestVoiceUi } from '../../testSupport/voiceUi.mjs';
import { mountVoiceView } from '../../testSupport/voiceView.mjs';
function fixture(t) {
const doc = { activeElement: null };
const node = () =>
Object.assign(new EventTarget(), {
hidden: false,
isConnected: true,
dataset: {},
attributes: {},
ownerDocument: doc,
setAttribute(name, value) {
this.attributes[name] = value;
},
focus() {
doc.activeElement = this;
},
contains(other) {
return other === this;
},
checkVisibility() {
return !this.hidden;
},
});
const ui = Object.fromEntries(
[
'root',
'voicePanel',
'previewPanel',
'voiceSettingsPanel',
'previewTab',
'settingsTab',
'voiceSettingsButton',
'voiceSettingsClose',
'previewEmpty',
'card',
'button',
].map((key) => [key, node()]),
);
ui.voicePanel.contains = (element) =>
Object.values(ui).includes(element) &&
![ui.root, ui.voiceSettingsButton, ui.button].includes(element);
const { pinia, settle } = mountVoiceView(t);
const ui = createTestVoiceUi({ panel: true, pinia });
t.after(() => ui.remove());
let enabled = true,
content = false,
intents = 0;
// The card shows when presented, with Preview on and something to show.
const card = {
setPresented(value) {
this.presented = value;
ui.card.hidden = !(value && enabled && content);
ui.replace('card', {
...ui.state.card,
visible: Boolean(value && enabled && content),
});
},
};
const copy = {
@@ -63,12 +34,15 @@ function fixture(t) {
onPresentationIntent: () => intents++,
});
t.after(() => panel.destroy());
const $ = (id) => document.getElementById(id);
return {
ui,
panel,
doc,
card,
copy,
settle,
$,
active: () => document.activeElement?.id ?? null,
intents: () => intents,
enabled(value) {
enabled = value;
@@ -80,119 +54,156 @@ function fixture(t) {
},
};
}
const click = (element) => element.dispatchEvent(new Event('click'));
const click = (element) => element.click();
function key(element, value) {
const event = new Event('keydown', { cancelable: true });
Object.defineProperty(event, 'key', { value });
const event = new KeyboardEvent('keydown', {
key: value,
bubbles: true,
cancelable: true,
});
element.dispatchEvent(event);
return event;
}
test('Settings launcher toggles while tab and programmatic selection remain idempotent', (t) => {
test('Settings launcher toggles while tab and programmatic selection remain idempotent', async (t) => {
const f = fixture(t);
await f.settle();
assert.equal(f.panel.snapshot().panelOpen, false);
click(f.ui.voiceSettingsButton);
click(f.$('gev-voice-settings-button'));
await f.settle();
assert.equal(f.panel.snapshot().settingsOpen, true);
assert.equal(f.doc.activeElement, f.ui.settingsTab);
assert.equal(f.ui.voiceSettingsButton.attributes['aria-expanded'], 'true');
click(f.ui.voiceSettingsButton);
assert.equal(f.active(), 'gev-voice-settings-tab');
assert.equal(
f.$('gev-voice-settings-button').getAttribute('aria-expanded'),
'true',
);
click(f.$('gev-voice-settings-button'));
await f.settle();
assert.equal(f.panel.snapshot().panelOpen, false);
click(f.ui.settingsTab);
click(f.$('gev-voice-settings-tab'));
assert.equal(f.panel.snapshot().settingsOpen, true);
assert.equal(f.panel.select('settings').changed, false);
assert.equal(f.panel.snapshot().settingsOpen, true);
click(f.ui.settingsTab);
click(f.$('gev-voice-settings-tab'));
assert.equal(f.panel.snapshot().settingsOpen, true);
assert.equal(f.panel.select('unknown').reason, 'unknown-view');
});
test('tab keyboard navigation and Escape preserve focus and accessibility state', (t) => {
test('tab keyboard navigation and Escape preserve focus and accessibility state', async (t) => {
const f = fixture(t);
click(f.ui.voiceSettingsButton);
assert.equal(key(f.ui.settingsTab, 'ArrowLeft').defaultPrevented, true);
await f.settle();
click(f.$('gev-voice-settings-button'));
await f.settle();
assert.equal(
key(f.$('gev-voice-settings-tab'), 'ArrowLeft').defaultPrevented,
true,
);
await f.settle();
assert.equal(f.panel.snapshot().view, 'preview');
assert.equal(f.doc.activeElement, f.ui.previewTab);
assert.equal(f.ui.previewTab.tabIndex, 0);
assert.equal(f.ui.settingsTab.tabIndex, -1);
assert.equal(f.ui.previewTab.attributes['aria-selected'], 'true');
key(f.ui.previewTab, 'End');
assert.equal(f.active(), 'gev-voice-preview-tab');
assert.equal(f.$('gev-voice-preview-tab').tabIndex, 0);
assert.equal(f.$('gev-voice-settings-tab').tabIndex, -1);
assert.equal(
f.$('gev-voice-preview-tab').getAttribute('aria-selected'),
'true',
);
key(f.$('gev-voice-preview-tab'), 'End');
assert.equal(f.panel.snapshot().view, 'settings');
key(f.ui.settingsTab, 'Home');
key(f.$('gev-voice-settings-tab'), 'Home');
await f.settle();
assert.equal(f.panel.snapshot().view, 'preview');
assert.equal(key(f.ui.voicePanel, 'Escape').defaultPrevented, true);
assert.equal(key(f.$('gev-voice-panel'), 'Escape').defaultPrevented, true);
await f.settle();
assert.equal(f.panel.snapshot().panelOpen, false);
assert.equal(f.doc.activeElement, f.ui.voiceSettingsButton);
assert.equal(key(f.ui.voicePanel, 'Escape').defaultPrevented, false);
assert.equal(f.active(), 'gev-voice-settings-button');
assert.equal(key(f.$('gev-voice-panel'), 'Escape').defaultPrevented, false);
});
test('manual switching transfers hidden-panel focus without stealing unrelated focus', (t) => {
test('manual switching transfers hidden-panel focus without stealing unrelated focus', async (t) => {
const f = fixture(t);
f.panel.select('settings');
f.ui.voiceSettingsPanel.focus();
await f.settle();
// Focus inside the Settings pane moves to the Preview tab with the switch.
f.$('gev-voice-timeout-select').focus();
f.panel.select('preview');
assert.equal(f.doc.activeElement, f.ui.previewTab);
const unrelated = (f.doc.activeElement = {});
await f.settle();
assert.equal(f.active(), 'gev-voice-preview-tab');
const unrelated = document.body.appendChild(document.createElement('button'));
unrelated.id = 'unrelated';
unrelated.focus();
f.panel.select('settings');
assert.equal(f.doc.activeElement, unrelated);
await f.settle();
assert.equal(f.active(), 'unrelated');
assert.equal(f.panel.close('preview').changed, false);
assert.equal(f.panel.snapshot().settingsOpen, true);
});
test('manual Preview selection never enables a disabled preference and uses injected copy', (t) => {
test('manual Preview selection never enables a disabled preference and uses injected copy', async (t) => {
const f = fixture(t);
await f.settle();
f.enabled(false);
f.content(true);
f.panel.select('preview');
await f.settle();
const empty = f.$('gev-voice-preview-empty');
assert.equal(f.panel.snapshot().previewEnabled, false);
assert.equal(f.panel.snapshot().previewVisible, false);
assert.equal(f.ui.previewEmpty.textContent, f.copy.previewDisabled);
assert.equal(f.ui.previewEmpty.hidden, false);
assert.equal(empty.textContent, f.copy.previewDisabled);
assert.equal(empty.hidden, false);
f.enabled(true);
await f.settle();
assert.equal(f.panel.snapshot().previewVisible, true);
assert.equal(f.ui.previewEmpty.hidden, true);
assert.equal(empty.hidden, true);
assert.equal(f.$('gev-voice-card').hidden, false);
f.content(false);
assert.equal(f.ui.previewEmpty.textContent, f.copy.previewEmpty);
await f.settle();
assert.equal(empty.textContent, f.copy.previewEmpty);
});
test('disposal hides owned presentation and removes listeners without destroying the card', (t) => {
test('disposal hides owned presentation and removes listeners without destroying the card', async (t) => {
const f = fixture(t);
f.panel.select('settings');
await f.settle();
const count = f.intents();
f.panel.destroy();
f.panel.destroy();
click(f.ui.voiceSettingsButton);
click(f.ui.settingsTab);
click(f.$('gev-voice-settings-button'));
click(f.$('gev-voice-settings-tab'));
await f.settle();
assert.equal(f.intents(), count);
assert.equal(f.ui.voicePanel.hidden, true);
assert.equal(f.$('gev-voice-panel').hidden, true);
assert.equal(f.card.presented, false);
assert.equal(f.panel.select('preview').reason, 'disposed');
assert.equal(f.panel.close().reason, 'disposed');
});
test('pointer grace expires, resets on reentry, ignores touch and clears on disposal', (t) => {
test('pointer grace expires, resets on reentry, ignores touch and clears on disposal', async (t) => {
t.mock.timers.enable({ apis: ['setTimeout'] });
const f = fixture(t);
await f.settle();
const root = f.$('gev-voice-control');
const pointer = (type, pointerType = 'mouse') => {
const event = new Event(type);
Object.defineProperty(event, 'pointerType', { value: pointerType });
f.ui.root.dispatchEvent(event);
root.dispatchEvent(event);
};
pointer('pointerleave');
t.mock.timers.tick(699);
assert.equal(f.ui.root.dataset.rowGrace, 'true');
await f.settle();
assert.equal(root.dataset.rowGrace, 'true');
pointer('pointerenter');
assert.equal(f.ui.root.dataset.rowGrace, undefined);
assert.equal(f.ui.state.root.rowGrace ? 'true' : undefined, undefined);
pointer('pointerleave');
t.mock.timers.tick(699);
assert.equal(f.ui.root.dataset.rowGrace, 'true');
assert.equal(f.ui.state.root.rowGrace ? 'true' : undefined, 'true');
t.mock.timers.tick(1);
assert.equal(f.ui.root.dataset.rowGrace, undefined);
assert.equal(f.ui.state.root.rowGrace ? 'true' : undefined, undefined);
pointer('pointerleave', 'touch');
assert.equal(f.ui.root.dataset.rowGrace, undefined);
assert.equal(f.ui.state.root.rowGrace ? 'true' : undefined, undefined);
pointer('pointerleave');
f.panel.destroy();
assert.equal(f.ui.root.dataset.rowGrace, undefined);
assert.equal(f.ui.state.root.rowGrace ? 'true' : undefined, undefined);
pointer('pointerleave');
t.mock.timers.tick(700);
assert.equal(f.ui.root.dataset.rowGrace, undefined);
assert.equal(f.ui.state.root.rowGrace ? 'true' : undefined, undefined);
});