Files
gods-eye-view/src/testSupport/voiceView.mjs
T
Sameh Khamis 1de4f635ca 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.
2026-10-31 19:22:03 -07:00

40 lines
1.4 KiB
JavaScript

import { createApp, h, nextTick } from 'vue';
import { createPinia, storeToRefs } from 'pinia';
import { useVoiceStore } from '../ui/stores/voice.js';
import VoiceControl from '../ui/views/panels/VoiceControl.vue';
/**
* Render whichever voice control the store presents, as the command dock
* does, into the current document. Import registerDom.mjs first.
* @param {import('node:test').TestContext} t
* @returns {{pinia: import('pinia').Pinia, settle: () => Promise<void>}}
*/
export function mountVoiceView(t) {
const doc = globalThis.document;
// happy-dom lacks the browser's `[hidden]` rule, which visibility checks
// and focus moves rely on.
if (!doc.getElementById('test-ua-hidden')) {
const style = doc.head.appendChild(doc.createElement('style'));
style.id = 'test-ua-hidden';
style.textContent = '[hidden] { display: none; }';
}
doc.body.replaceChildren();
const host = doc.body.appendChild(doc.createElement('div'));
const pinia = createPinia();
const { view } = storeToRefs(useVoiceStore(pinia));
const app = createApp({
render: () =>
view.value
? h(VoiceControl, { key: view.value.id, view: view.value })
: null,
}).use(pinia);
app.mount(host);
t.after(() => app.unmount());
// Renders, then any focus the owners asked for after it.
const settle = async () => {
await nextTick();
await nextTick();
};
return { pinia, settle };
}