Merge main through #1319 into the renderer seam

Brings in range ring visibility and sonar pulses (#1518, #1519), the
drone airspace layer (#1086), the Houston CCTV pack (#1125), typed chat
(#1507, #1545), in-view ground sampling for infrastructure (#1464) and
the CCTV model specs refresh (#1319).

What main added that reached Cesium or the viewer:
- Drone airspace draws its zones as clamped fills and draped boundary
  lines in draw sets and takes clicks from the input dispatcher, as fire
  perimeters does.
- Infrastructure ground sampling tests the view frustum and the horizon
  from the camera port's pose (geo/frustum, geo/horizon) and reads loaded
  terrain through the height queries.
- The awareness lifecycle reads the canvas, frames and whether the camera
  controls take input through the ports. The sonar echo field measures
  with the geo helpers.
- The range ring's pulses need a disc whose fill is computed per pixel
  from values set each frame, and an outlined line whose opacity changes
  without a rebuild. The draw port has neither, so that code keeps to one
  module, src/layers/awareness/rangeRingCesium.js, which is on the Cesium
  allow-list until the draw port can draw them. It draws only on a viewer
  with a Cesium primitive collection, and takes its primitives out of the
  collection it drew them in. On the stub the layer draws the
  ring without pulses as a haloed line through the draw port.

Also from review of the previous merge: tests that the scene's viewer
hooks install the zoom-out guard, and that an ambiguous area name is
settled by the ground at mid-screen, else where the camera stands.
This commit is contained in:
Sameh Khamis committed 2026-11-09 19:59:26 -08:00
commit b9f8ac1ff0
141 files changed
+16192 -412

No files matched your search

+3 -1
View File
@@ -289,7 +289,9 @@ export function createVoicePanelHost({
signal: session.signal,
...clock,
onExpire: () => {
if (!owns()) return;
// Typed chat has no microphone or audio to time out, and stopping it
// would drop the conversation the chat log still shows.
if (!owns() || session.adapter?.getStartOptions?.().textOnly) return;
const ticket = revision;
session.stop();
closeAfterStop(ticket);
+554 -8
View File
@@ -1,6 +1,7 @@
import '../../testSupport/registerDom.mjs';
import test from 'node:test';
import assert from 'node:assert/strict';
import { readFileSync } from 'node:fs';
import { createPinia } from 'pinia';
import { createVoiceControl } from '../control.js';
import { useVoiceStore } from '../../ui/stores/voice.js';
@@ -195,7 +196,7 @@ test('actual control default remains opt-out; panel markup has unique controlled
);
});
test('actual binder/card has launcher toggle, idempotent tabs, focus and disabled Preview', async (t) => {
test('actual binder/card has launcher toggle, Settings tab toggle, focus and disabled Preview', async (t) => {
const { ui, commands, settle } = mounted(t, { view: true });
await settle();
$('#gev-voice-settings-button').click();
@@ -206,8 +207,9 @@ test('actual binder/card has launcher toggle, idempotent tabs, focus and disable
$('#gev-voice-settings-tab').click();
key($('#gev-voice-settings-tab'), 'End');
assert.equal(commands.voicePanel.snapshot().settingsOpen, true);
// Preview has no visible tab, so the Settings tab toggles back to it.
$('#gev-voice-settings-tab').click();
assert.equal(commands.voicePanel.snapshot().settingsOpen, true);
assert.equal(commands.voicePanel.snapshot().view, 'preview');
commands.voicePanel.select('preview');
commands.voiceCard.handle({
type: 'transcript',
@@ -241,7 +243,7 @@ test('actual binder/card has launcher toggle, idempotent tabs, focus and disable
$('#gev-voice-preview-tab').focus();
key(globalThis.document.activeElement, 'Escape');
await settle();
assert.equal(active(), 'gev-voice-settings-button');
assert.equal(active(), 'gev-chat-button');
commands.voiceCard.handle({
type: 'transcript',
role: 'assistant',
@@ -471,9 +473,52 @@ test('native connecting phases retain output observation; idle starts before fir
assert.equal(adapter.stops, 1);
});
test('a failed typed turn keeps follow-up memory; a stop or voice error clears it', async (t) => {
let resets = 0;
const runner = async () => ({ ok: true });
runner.resetConversation = () => resets++;
const f = mounted(t, { runner });
const adapter = f.instances[0];
adapter.getStartOptions = () => ({ textOnly: true });
await f.commands.session.start({ textOnly: true });
adapter.hooks.emit({ type: 'state', state: 'error', detail: 'Busy' });
assert.equal(resets, 0, 'the typed conversation continues');
f.commands.session.stop();
assert.equal(resets, 1);
adapter.getStartOptions = () => ({});
await f.commands.session.start();
adapter.hooks.emit({ type: 'state', state: 'error', detail: 'Lost' });
assert.equal(resets, 2);
});
test('the voice inactivity timeout never ends a typed chat session', async (t) => {
const f = mounted(t, { native: true });
const adapter = f.instances[0];
adapter.getStartOptions = () => ({ textOnly: true });
await f.commands.session.start({ textOnly: true });
adapter.controller.handleMessage({});
f.clock.advance(600000);
assert.equal(adapter.stops, 0);
assert.equal(f.commands.session.isActive(), true);
// A quiet voice session started afterwards still times out.
f.commands.session.stop();
const stops = adapter.stops;
adapter.getStartOptions = () => ({});
await f.commands.session.start();
adapter.controller.handleMessage({});
f.clock.advance(600000);
assert.equal(adapter.stops, stops + 1);
});
async function directActions(
t,
{ storage = null, delayExit = false, exposePanel = true } = {},
{
storage = null,
delayExit = false,
exposePanel = true,
typed = false,
view = false,
} = {},
) {
let f, releaseExit;
const state = { active: true, exits: 0, visual: [] };
@@ -506,8 +551,13 @@ async function directActions(
readVoicePanelOperation: () =>
exposePanel ? f?.commands.captureVoicePanelOperation() : undefined,
});
f = mounted(t, { native: true, runner, storage });
await f.commands.session.start();
f = mounted(t, { native: true, runner, storage, view });
// A typed chat session starts from chat's first send instead.
if (typed) {
const adapter = f.instances[0];
adapter.getStartOptions = () => ({ textOnly: true });
adapter.sendText = () => true;
} else await f.commands.session.start();
return {
...f,
runner,
@@ -581,6 +631,91 @@ test('named voice settings exits Cockpit directly; Preview stays disabled and vi
);
});
for (const minimized of [false, true])
test(`an explicit voice panel request from ${minimized ? 'minimized ' : ''}typed chat shows the panel and keeps the chat`, async (t) => {
const f = await directActions(t, { typed: true });
const adapter = f.instances[0];
f.ui.emit('chat-button');
f.ui.emit('chat-input', 'Fly to Tokyo');
f.ui.emit('chat-submit');
await new Promise((resolve) => setTimeout(resolve, 0));
assert.equal(f.ui.state.chat.busy, true, 'the typed turn is running');
if (minimized) f.ui.emit('chat-minimize');
assert.equal(f.ui.state.root.chatOpen, true);
for (const [panelId, view] of [
['voice-settings', 'settings'],
['voice-preview', 'preview'],
]) {
const result = await f.run('set_panel_open', { panelId, open: true });
assert.equal(result.ok, true);
// `[data-chat-open='true'] .gev-voice-panel` is display:none.
assert.equal(f.ui.state.root.chatOpen, false, panelId);
assert.equal(f.ui.state.chat.open, false);
assert.equal(f.ui.state.voicePanel.hidden, false);
assert.equal(f.ui.state.voicePanel.view, view);
}
assert.equal(adapter.stops, 0, 'the typed session continues');
assert.equal(f.commands.session.isActive(), true);
assert.equal(f.ui.state.chat.busy, true, 'the turn is not cancelled');
adapter.hooks.emit({
type: 'transcript',
role: 'assistant',
text: 'Flying to Tokyo.',
final: true,
itemId: 'reply',
});
adapter.hooks.emit({ type: 'completion', status: 'completed' });
assert.equal(f.ui.state.chat.busy, false);
f.ui.emit('chat-button');
assert.equal(f.ui.state.root.chatOpen, true);
assert.equal(f.ui.state.voicePanel.hidden, true);
assert.deepEqual(
f.ui.chatMessages.map(({ role }) => role),
['user', 'assistant'],
'reopened chat shows the whole conversation',
);
assert.equal(f.ui.chatMessages[0].text, 'Fly to Tokyo');
assert.equal(adapter.stops, 0);
});
for (const [panelId, target] of [
['voice-settings', 'gev-voice-settings-tab'],
['voice-preview', 'gev-voice-preview-tab'],
])
test(`${panelId} asked for from the chat composer takes focus with it`, async (t) => {
const f = await directActions(t, { typed: true, view: true });
await f.settle();
$('#gev-chat-button').click();
await f.commands.session.start({ textOnly: true });
await f.settle();
$('#gev-chat-input').focus();
assert.equal(active(), 'gev-chat-input');
const result = await f.run('set_panel_open', { panelId, open: true });
assert.equal(result.ok, true);
await f.settle();
assert.equal($('#gev-chat-panel').hidden, true);
assert.equal(active(), target);
assert.equal(f.ui.visible('voicePanel'), true);
});
test('a voice panel asked for from chat leaves unrelated focus alone', async (t) => {
const f = await directActions(t, { typed: true, view: true });
await f.settle();
$('#gev-chat-button').click();
await f.commands.session.start({ textOnly: true });
await f.settle();
const elsewhere = globalThis.document.body.appendChild(
globalThis.document.createElement('button'),
);
elsewhere.id = 'elsewhere';
t.after(() => elsewhere.remove());
elsewhere.focus();
await f.run('set_panel_open', { panelId: 'voice-settings', open: true });
await f.settle();
assert.equal($('#gev-chat-panel').hidden, true);
assert.equal(active(), 'elsewhere');
});
test('canonical exit reveals requested voice UI; newer manual choice or Stop defeats pending reveal', async (t) => {
const f = await directActions(t, { delayExit: true });
const pending = f.run('control_cockpit', {
@@ -722,13 +857,13 @@ test('Preview off and actual Cockpit state suppress automatic presentation witho
window.dispatchEvent(new Event('gev:cockpit-mode-changed'));
assert.equal(f.ui.state.voicePanel.hidden, true);
await f.settle();
assert.equal(active(), 'gev-voice-settings-button');
assert.equal(active(), 'gev-chat-button');
f.commands.voicePanel.select('settings', { focus: true });
await f.settle();
assert.equal(active(), 'gev-voice-settings-tab');
f.commands.voicePanel.select('preview', { focus: true });
await f.settle();
assert.equal(active(), 'gev-voice-settings-button');
assert.equal(active(), 'gev-chat-button');
const outside = document.createElement('button');
outside.id = 'unrelated';
document.body.appendChild(outside);
@@ -827,3 +962,414 @@ test('Provider Settings uses its ready dialog handlers and refuses unavailable o
'provider setup never opens a visual or scene panel',
);
});
// Typed chat, rendered by the real VoiceControl.
const typedChat = (f) => {
f.instances[0].getStartOptions = () => ({ textOnly: true });
f.instances[0].sendText = () => true;
};
const type = (text) => {
const input = $('#gev-chat-input');
input.value = text;
input.dispatchEvent(new Event('input', { bubbles: true }));
};
test('the chat button opens, minimizes and closes chat', async (t) => {
const f = mounted(t, { view: true });
await f.settle();
$('#gev-chat-button').click();
await f.settle();
assert.equal($('#gev-chat-panel').hidden, false);
assert.equal($('#gev-voice-control').dataset.assistantMode, 'chat');
assert.equal(active(), 'gev-chat-input');
$('#gev-chat-button').click();
await f.settle();
assert.equal($('#gev-chat-panel').dataset.minimized, 'true');
$('#gev-chat-restore').click();
await f.settle();
assert.equal($('#gev-chat-panel').dataset.minimized, undefined);
$('#gev-chat-close').click();
await f.settle();
assert.equal($('#gev-chat-panel').hidden, true);
assert.equal($('#gev-voice-control').dataset.assistantMode, 'idle');
});
test('a typed message sends, shows the reply and is recalled with Up', async (t) => {
const f = mounted(t, { view: true });
typedChat(f);
const reduce = globalThis.matchMedia;
globalThis.matchMedia = () => ({ matches: true });
t.after(() => (globalThis.matchMedia = reduce));
await f.settle();
$('#gev-chat-button').click();
await f.settle();
type('Fly to Tokyo');
$('#gev-chat-form').dispatchEvent(new Event('submit', { cancelable: true }));
await f.commands.session.start({ textOnly: true });
for (let i = 0; i < 5; i++) await f.settle();
const messages = () =>
[...globalThis.document.querySelectorAll('.gev-chat-message')].map(
(row) => `${row.dataset.role}:${row.querySelector('span').textContent}`,
);
assert.deepEqual(messages(), ['user:Fly to Tokyo']);
assert.equal($('#gev-chat-input').value, '');
f.instances[0].hooks.emit({
type: 'transcript',
role: 'assistant',
text: 'Flying to Tokyo.',
final: true,
});
await f.settle();
assert.deepEqual(messages(), [
'user:Fly to Tokyo',
'assistant:Flying to Tokyo.',
]);
assert.equal(f.ui.state.voicePanel.hidden, true);
key($('#gev-chat-input'), 'ArrowUp');
await f.settle();
assert.equal($('#gev-chat-input').value, 'Fly to Tokyo');
});
test('chat Settings keep chat context until the panel closes', async (t) => {
const f = mounted(t, { view: true });
await f.settle();
$('#gev-chat-button').click();
await f.settle();
$('#gev-voice-settings-button').click();
await f.settle();
assert.equal(f.ui.state.voicePanel.context, 'chat');
assert.equal($('#gev-chat-panel').hidden, true);
assert.equal($('#gev-voice-control').dataset.assistantMode, 'chat');
assert.equal(active(), 'gev-chat-back');
key($('#gev-chat-back'), 'Escape');
await f.settle();
assert.equal(f.ui.state.voicePanel.context, null);
assert.equal($('#gev-chat-panel').hidden, false);
$('#gev-voice-settings-button').click();
await f.settle();
$('#gev-chat-back').click();
await f.settle();
assert.equal($('#gev-chat-panel').hidden, false);
assert.equal(f.ui.state.chat.backVisible, false);
});
// Shown once neither the element nor an ancestor is hidden by the page's
// chat stylesheet or a hidden attribute.
function shown(selector) {
for (let node = $(selector); node?.nodeType === 1; node = node.parentElement)
if (node.hidden || globalThis.getComputedStyle(node).display === 'none')
return false;
return true;
}
test('with Preview off, chat Settings reach the voice preferences', async (t) => {
const style = globalThis.document.createElement('style');
style.textContent = readFileSync(
new URL('../../ui/styles/ai-chat.css', import.meta.url),
'utf8',
);
globalThis.document.head.append(style);
t.after(() => style.remove());
const f = mounted(t, { view: true });
// The control renders into the command dock, as the page does.
globalThis.document.body.firstElementChild.id = 'command-dock';
f.ui.emit('preview-change', false);
f.commands.voicePanel.close();
await f.settle();
$('#gev-chat-button').click();
await f.settle();
$('#gev-voice-settings-button').click();
await f.settle();
assert.equal(f.ui.state.voicePanel.context, 'chat');
for (const selector of [
'#gev-settings-chat',
'#gev-settings-voice',
'#gev-voice-preview-enabled',
'#gev-voice-timeout-select',
])
assert.equal(shown(selector), true, selector);
// Chat's frame keeps the voice tabs and dock layout buttons away.
assert.equal(shown('.gev-voice-panel-tabs'), false);
const preview = $('#gev-voice-preview-enabled');
preview.checked = true;
preview.dispatchEvent(new Event('change', { bubbles: true }));
assert.equal(f.commands.getVoicePreferences().previewEnabled, true);
const timeout = $('#gev-voice-timeout-select');
timeout.value = '10';
timeout.dispatchEvent(new Event('change', { bubbles: true }));
assert.equal(f.commands.getVoicePreferences().minutes, 10);
f.ui.update('tier', { hidden: false });
await f.settle();
assert.equal(shown('#gev-voice-tier'), true);
let tiers = 0;
t.after(f.ui.on('tier', () => tiers++));
$('#gev-voice-tier').click();
assert.equal(tiers, 1);
assert.equal(f.ui.state.voicePanel.context, 'chat', 'still chat Settings');
});
test('chat Settings keep only the quick commands preference', async (t) => {
const f = mounted(t, { view: true });
await f.settle();
for (const id of [
'typewriter',
'text-color',
'text-size',
'autocomplete',
'recent',
])
assert.equal(exists(`#gev-chat-${id}`), false);
assert.equal(exists('#gev-panel-default-position'), false);
assert.equal(exists('#gev-chat-quick'), true);
});
test('voice Settings step back to Preview with Back and Escape', async (t) => {
const f = mounted(t, { view: true });
await f.settle();
f.commands.voicePanel.select('settings', { focus: true });
await f.settle();
assert.equal(active(), 'gev-voice-settings-tab');
$('#gev-voice-back').click();
await f.settle();
assert.equal(f.commands.voicePanel.snapshot().view, 'preview');
f.commands.voicePanel.select('settings');
key($('#gev-voice-panel'), 'Escape');
await f.settle();
assert.equal(f.commands.voicePanel.snapshot().view, 'preview');
assert.equal(f.commands.voicePanel.snapshot().panelOpen, true);
key($('#gev-voice-panel'), 'Escape');
assert.equal(f.commands.voicePanel.snapshot().panelOpen, false);
});
test('Escape does not minimize chat', async (t) => {
const f = mounted(t, { view: true });
await f.settle();
$('#gev-chat-button').click();
await f.settle();
key($('#gev-chat-input'), 'Escape');
await f.settle();
assert.equal($('#gev-chat-panel').dataset.minimized, undefined);
assert.equal($('#gev-chat-panel').hidden, false);
});
function dockWing(t) {
const doc = globalThis.document;
const wing = doc.createElement('div');
wing.id = 'control-panel';
wing.className = 'panel-collapsible collapsed';
const toggle = doc.createElement('button');
toggle.className = 'dock-tray-toggle';
const tray = doc.createElement('div');
tray.className = 'dock-popover-content';
wing.append(toggle, tray);
doc.body.append(wing);
t.after(() => wing.remove());
return {
wing,
toggle,
open: () => wing.classList.remove('collapsed'),
close: () => wing.classList.add('collapsed'),
};
}
test('reaching for a dock wing minimizes a centred chat or voice panel', async (t) => {
const f = mounted(t, { view: true });
await f.settle();
// The dock can mount after the layouts bind; they find it on use.
const wing = dockWing(t);
$('#gev-chat-button').click();
await f.settle();
wing.toggle.dispatchEvent(new PointerEvent('pointerover', { bubbles: true }));
await f.settle();
assert.equal($('#gev-chat-panel').dataset.minimized, 'true');
// Leaving the wing with no tray open ends the yield.
wing.wing.dispatchEvent(new PointerEvent('pointerleave'));
await f.settle();
assert.equal($('#gev-chat-panel').dataset.minimized, undefined);
$('#gev-chat-button').click();
await f.settle();
$('#gev-chat-button').click();
await f.settle();
f.commands.voicePanel.select('preview');
await f.settle();
assert.equal($('#gev-voice-panel').dataset.minimized, undefined);
wing.toggle.dispatchEvent(new PointerEvent('pointerdown', { bubbles: true }));
await f.settle();
assert.equal($('#gev-voice-panel').dataset.minimized, 'true');
});
test('expanding a panel over an open tray docks it right without saving', async (t) => {
const f = mounted(t, { view: true });
// The view mount resets the body; the layouts bind on the next tick.
const wing = dockWing(t);
await f.settle();
$('#gev-chat-button').click();
await f.settle();
wing.toggle.dispatchEvent(new PointerEvent('pointerover', { bubbles: true }));
wing.open();
await f.settle();
assert.equal($('#gev-chat-panel').dataset.placement, 'compact');
$('#gev-chat-restore').click();
await f.settle();
await f.settle();
assert.equal($('#gev-chat-panel').dataset.minimized, undefined);
assert.equal($('#gev-chat-panel').dataset.placement, 'docked');
assert.notEqual(globalThis.localStorage.getItem('gev.panel.docked'), 'true');
// The dock was only for the tray; it ends once the tray closes.
wing.close();
await f.settle();
await f.settle();
assert.equal(f.ui.state.layout.docked, false);
assert.equal($('#gev-chat-panel').dataset.placement, 'compact');
assert.equal($('#gev-chat-panel').dataset.minimized, undefined);
});
test('yielding to a dock tray leaves keyboard focus where it is', async (t) => {
const f = mounted(t, { view: true });
const wing = dockWing(t);
const field = globalThis.document.createElement('input');
globalThis.document.body.append(field);
t.after(() => field.remove());
await f.settle();
$('#gev-chat-button').click();
await f.settle();
for (const target of [$('#gev-chat-input'), field]) {
target.focus();
wing.toggle.dispatchEvent(
new PointerEvent('pointerover', { bubbles: true }),
);
await f.settle();
assert.equal($('#gev-chat-panel').dataset.minimized, 'true');
assert.equal(globalThis.document.activeElement, target);
wing.wing.dispatchEvent(new PointerEvent('pointerleave'));
await f.settle();
assert.equal($('#gev-chat-panel').dataset.minimized, undefined);
assert.equal(globalThis.document.activeElement, target);
}
});
test('a panel that yielded to a tray expands in the centre once it closes', async (t) => {
const f = mounted(t, { view: true });
const wing = dockWing(t);
await f.settle();
$('#gev-chat-button').click();
await f.settle();
wing.toggle.dispatchEvent(new PointerEvent('pointerdown', { bubbles: true }));
wing.open();
await f.settle();
assert.equal($('#gev-chat-panel').dataset.minimized, 'true');
wing.close();
await f.settle();
assert.equal($('#gev-chat-panel').dataset.minimized, undefined);
assert.equal($('#gev-chat-panel').dataset.placement, 'compact');
assert.equal(f.ui.state.layout.yielded, null);
});
test('switching to voice while chat yields to a tray starts voice as its bar', async (t) => {
const f = mounted(t, { view: true });
const wing = dockWing(t);
await f.settle();
$('#gev-chat-button').click();
await f.settle();
wing.toggle.dispatchEvent(new PointerEvent('pointerover', { bubbles: true }));
await f.settle();
$('#gev-chat-button').click();
await f.settle();
f.commands.voicePanel.select('preview');
await f.settle();
assert.equal($('#gev-voice-panel').dataset.minimized, 'true');
assert.equal(f.ui.state.layout.yielded, 'voicePanel');
});
test('undocking while a tray is open brings the panel back as its bar', async (t) => {
const f = mounted(t, { view: true });
const wing = dockWing(t);
await f.settle();
$('#gev-chat-button').click();
await f.settle();
$('#gev-chat-panel [data-layout-dock]').click();
await f.settle();
assert.equal($('#gev-chat-panel').dataset.placement, 'docked');
wing.open();
await f.settle();
$('#gev-chat-panel [data-layout-dock]').click();
await f.settle();
await f.settle();
assert.equal($('#gev-chat-panel').dataset.minimized, 'true');
assert.equal($('#gev-chat-panel').dataset.placement, 'compact');
});
test('the voice panel close turns voice off', async (t) => {
const f = mounted(t, { view: true });
await f.commands.session.start();
f.commands.voicePanel.select('preview');
await f.settle();
$('#gev-voice-settings-close').click();
assert.equal(f.commands.session.isActive(), false);
assert.equal(f.commands.voicePanel.snapshot().panelOpen, false);
});
test('closing chat Settings ends a typed session', async (t) => {
const f = mounted(t, { view: true });
typedChat(f);
await f.settle();
$('#gev-chat-button').click();
await f.commands.session.start({ textOnly: true });
await f.settle();
$('#gev-voice-settings-button').click();
await f.settle();
$('#gev-voice-settings-close').click();
await f.settle();
assert.equal(f.commands.session.isActive(), false);
assert.equal($('#gev-chat-panel').hidden, true);
});
test('opening chat stops a live voice session', async (t) => {
const f = mounted(t, { view: true });
await f.commands.session.start();
await f.settle();
assert.equal(f.commands.session.isActive(), true);
$('#gev-chat-button').click();
await f.settle();
assert.equal(f.commands.session.isActive(), false);
assert.equal($('#gev-chat-panel').hidden, false);
});
test('the mic button closes chat and minimize collapses voice to a bar', async (t) => {
const f = mounted(t, { view: true });
await f.settle();
$('#gev-chat-button').click();
await f.settle();
$('#gev-voice-button').click();
await f.settle();
assert.equal($('#gev-chat-panel').hidden, true);
assert.equal(f.commands.session.isActive(), true);
f.commands.voicePanel.select('preview');
await f.settle();
$('#gev-voice-panel [data-layout-minimize]').click();
await f.settle();
assert.equal($('#gev-voice-panel').dataset.minimized, 'true');
f.commands.voicePanel.select('preview');
await f.settle();
assert.equal($('#gev-voice-panel').dataset.minimized, undefined);
});
test('teardown inside sendText prevents appending the submitted message', async (t) => {
const f = mounted(t, { view: true });
f.instances[0].getStartOptions = () => ({ textOnly: true });
f.instances[0].sendText = () => {
f.commands.session.destroy();
return true;
};
await f.settle();
$('#gev-chat-button').click();
await f.settle();
type('Hello');
$('#gev-chat-form').dispatchEvent(new Event('submit', { cancelable: true }));
await f.commands.session.start({ textOnly: true });
for (let i = 0; i < 5; i++) await Promise.resolve();
assert.equal(
globalThis.document.querySelectorAll('.gev-chat-message').length,
0,
);
});
+22 -5
View File
@@ -64,7 +64,7 @@ export function createManualVoicePanel({
hidden: ui.state.card.visible,
text: () => (previewOn ? copy.previewEmpty : copy.previewDisabled),
});
if (restoreFocus) void ui.focus(['settingsButton', 'button']);
if (restoreFocus) void ui.focus(['settingsButton', 'chatButton', 'button']);
};
const refuse = (reason) => ({
ok: false,
@@ -79,11 +79,18 @@ export function createManualVoicePanel({
const transferFocus = changed && holdsFocus(panes[view]);
open = true;
view = next;
// An explicit request restores a minimized panel; automatic reveals do not.
if (!automatic && ui.state.voicePanel.minimized)
ui.update('voicePanel', { minimized: false });
onPresentationIntent?.({ automatic });
sync();
// The tab takes focus once it shows, inside a shown panel.
// The view's tab takes focus once it shows, inside a shown panel, or the
// next visible control when the tab is hidden: voice Settings show Back
// instead, and Preview falls to Settings.
if (focus || transferFocus)
void ui.focus([tabs[next === 'preview' ? 0 : 1]]);
void ui.focus(
next === 'preview' ? [tabs[0], tabs[1]] : [tabs[1], 'voiceBack'],
);
return { ok: true, changed, ...snapshot() };
};
const close = (onlyView) => {
@@ -94,6 +101,9 @@ export function createManualVoicePanel({
return { ok: true, changed: false, ...snapshot() };
const changed = open;
open = false;
// A caller's context (Settings opened from chat) ends with the panel.
if (ui.state.voicePanel.minimized || ui.state.voicePanel.context)
ui.update('voicePanel', { minimized: false, context: null });
onPresentationIntent?.();
sync();
return { ok: true, changed, ...snapshot() };
@@ -110,9 +120,13 @@ export function createManualVoicePanel({
};
offs.push(
ui.on('settings-button', toggleSettings),
// Preview has no visible tab; the Settings tab toggles back to it.
ui.on('tab', (index) =>
select(index === 0 ? 'preview' : 'settings', { focus: true }),
index === 1 && open && view === 'settings'
? select('preview', { focus: true })
: select(index === 0 ? 'preview' : 'settings', { focus: true }),
),
ui.on('voice-back', () => select('preview', { focus: true })),
ui.on('tab-keydown', (index, event) => {
const next =
event.key === 'Home'
@@ -130,7 +144,10 @@ export function createManualVoicePanel({
ui.on('panel-keydown', (event) => {
if (event.key !== 'Escape' || !open) return;
event.preventDefault();
close();
// Voice Settings step back to the preview, like chat Settings to chat.
if (view === 'settings' && !ui.state.voicePanel.context)
select('preview', { focus: true });
else close();
}),
ui.on('pointerleave', (event) => {
if (event.pointerType === 'touch') return;
+6 -3
View File
@@ -65,7 +65,7 @@ function key(element, value) {
return event;
}
test('Settings launcher toggles while tab and programmatic selection remain idempotent', async (t) => {
test('Settings launcher and tab toggle while programmatic selection stays idempotent', async (t) => {
const f = fixture(t);
await f.settle();
assert.equal(f.panel.snapshot().panelOpen, false);
@@ -84,8 +84,10 @@ test('Settings launcher toggles while tab and programmatic selection remain idem
assert.equal(f.panel.snapshot().settingsOpen, true);
assert.equal(f.panel.select('settings').changed, false);
assert.equal(f.panel.snapshot().settingsOpen, true);
// Preview has no visible tab, so the Settings tab toggles back to it.
click(f.$('gev-voice-settings-tab'));
assert.equal(f.panel.snapshot().settingsOpen, true);
assert.equal(f.panel.snapshot().view, 'preview');
assert.equal(f.panel.snapshot().panelOpen, true);
assert.equal(f.panel.select('unknown').reason, 'unknown-view');
});
@@ -115,7 +117,8 @@ test('tab keyboard navigation and Escape preserve focus and accessibility state'
assert.equal(key(f.$('gev-voice-panel'), 'Escape').defaultPrevented, true);
await f.settle();
assert.equal(f.panel.snapshot().panelOpen, false);
assert.equal(f.active(), 'gev-voice-settings-button');
// The Settings gear lives in the chat header, so focus returns to Chat.
assert.equal(f.active(), 'gev-chat-button');
assert.equal(key(f.$('gev-voice-panel'), 'Escape').defaultPrevented, false);
});