Skip to content

A desktop coding agent with free access to frontier models.

TypeScript

fix: voice dictation switch shows off while voice is unavailable

ogsamratb3fe7b5930e1
diff --git a/apps/app/src/react-app/domains/voice/voice-settings-view.tsx b/apps/app/src/react-app/domains/voice/voice-settings-view.tsx
index 2541b047..4e3d0640 100644
--- a/apps/app/src/react-app/domains/voice/voice-settings-view.tsx
+++ b/apps/app/src/react-app/domains/voice/voice-settings-view.tsx
@@ -131,7 +131,9 @@ export function VoiceSettingsView(props: { client: VoiceClient | null }) {
<Switch
aria-label="Dictation"
data-testid="voice-settings-enabled"
- checked={settings.enabled}
+ // Unavailable: show off and locked, keep the saved choice for when it becomes available.
+ checked={settings.enabled && !availability}
+ disabled={Boolean(availability)}
onCheckedChange={(enabled) => {
settings.update({ enabled });
if (!enabled) releaseMicrophone();
diff --git a/apps/app/tests/voice-settings-availability.test.tsx b/apps/app/tests/voice-settings-availability.test.tsx
new file mode 100644
index 00000000..5470997b
--- /dev/null
+++ b/apps/app/tests/voice-settings-availability.test.tsx
@@ -0,0 +1,60 @@
+/** @jsxImportSource react */
+import { afterAll, describe, expect, test } from "bun:test";
+import { GlobalRegistrator } from "@happy-dom/global-registrator";
+
+const registered = typeof globalThis.window === "undefined";
+if (registered) GlobalRegistrator.register({ url: "http://localhost/" });
+Object.defineProperty(globalThis, "IS_REACT_ACT_ENVIRONMENT", { configurable: true, value: true });
+afterAll(async () => {
+ if (registered) await GlobalRegistrator.unregister();
+});
+
+const { act } = await import("react");
+const { createRoot } = await import("react-dom/client");
+const { VoiceSettingsView } = await import("../src/react-app/domains/voice/voice-settings-view");
+const { useVoiceSettings } = await import("../src/react-app/domains/voice/voice-settings");
+
+const tick = () => new Promise((resolve) => setTimeout(resolve, 0));
+
+async function renderWith(available: boolean | null, baseUrl: string) {
+ const client = {
+ baseUrl,
+ getVoiceStatus: async () => ({ signedIn: true, available, reason: null, repo: null, branch: null }),
+ voiceTranscriptionEndpoint: () => `${baseUrl}/voice`,
+ };
+ const host = document.createElement("div");
+ document.body.append(host);
+ const root = createRoot(host);
+ await act(async () => {
+ root.render(<VoiceSettingsView client={client as never} />);
+ await tick();
+ await tick();
+ });
+ const toggle = host.querySelector<HTMLElement>('[data-testid="voice-settings-enabled"]');
+ const result = {
+ text: host.textContent ?? "",
+ checked: toggle?.getAttribute("aria-checked") ?? toggle?.getAttribute("data-checked"),
+ disabled: toggle?.hasAttribute("disabled") || toggle?.getAttribute("aria-disabled") === "true" || toggle?.hasAttribute("data-disabled"),
+ };
+ await act(async () => root.unmount());
+ host.remove();
+ return result;
+}
+
+describe("voice settings dictation switch", () => {
+ test("unavailable on the account: the switch shows off and locked, the saved choice stays on", async () => {
+ useVoiceSettings.getState().update({ enabled: true });
+ const r = await renderWith(false, "http://voice-off.test");
+ expect(r.text).toContain("isn't available on your account");
+ expect(r.checked).toBe("false");
+ expect(r.disabled).toBe(true);
+ expect(useVoiceSettings.getState().enabled).toBe(true);
+ });
+
+ test("available: the switch follows the saved choice", async () => {
+ useVoiceSettings.getState().update({ enabled: true });
+ const r = await renderWith(true, "http://voice-on.test");
+ expect(r.checked).toBe("true");
+ expect(r.disabled).toBe(false);
+ });
+});