|
1 | 1 | // @vitest-environment jsdom |
2 | 2 | import { afterEach, beforeEach, describe, expect, it, vi, type MockInstance } from "vitest"; |
3 | | -import { loadSettings, saveSettings } from "../../app/settings.ts"; |
| 3 | +import { loadSettings, resetUnpersistedSettingsForTest, saveSettings } from "../../app/settings.ts"; |
4 | 4 | import { |
5 | 5 | attachChatRealtimeActions, |
6 | 6 | createInitialChatRealtimeState, |
@@ -42,13 +42,15 @@ describe("chat realtime actions", () => { |
42 | 42 | let startSpy: MockInstance<RealtimeTalkSession["start"]>; |
43 | 43 |
|
44 | 44 | beforeEach(() => { |
| 45 | + resetUnpersistedSettingsForTest(); |
45 | 46 | vi.stubGlobal("localStorage", window.localStorage); |
46 | 47 | localStorage.clear(); |
47 | 48 | startSpy = vi.spyOn(RealtimeTalkSession.prototype, "start").mockResolvedValue(undefined); |
48 | 49 | vi.spyOn(RealtimeTalkSession.prototype, "stop").mockImplementation(() => undefined); |
49 | 50 | }); |
50 | 51 |
|
51 | 52 | afterEach(() => { |
| 53 | + resetUnpersistedSettingsForTest(); |
52 | 54 | vi.restoreAllMocks(); |
53 | 55 | vi.unstubAllGlobals(); |
54 | 56 | }); |
@@ -77,6 +79,18 @@ describe("chat realtime actions", () => { |
77 | 79 | expect(inspectSession(state).localOptions.inputDeviceId).toBe("usb-mic"); |
78 | 80 | }); |
79 | 81 |
|
| 82 | + it("keeps a microphone picked while storage is blocked for the next launch", async () => { |
| 83 | + vi.spyOn(Storage.prototype, "setItem").mockImplementation(() => { |
| 84 | + throw new DOMException("blocked", "SecurityError"); |
| 85 | + }); |
| 86 | + saveSettings({ ...loadSettings(), realtimeTalkInputDeviceId: "usb-mic" }); |
| 87 | + const state = createState(); |
| 88 | + |
| 89 | + await state.toggleRealtimeTalk(); |
| 90 | + |
| 91 | + expect(inspectSession(state).localOptions.inputDeviceId).toBe("usb-mic"); |
| 92 | + }); |
| 93 | + |
80 | 94 | it("propagates normalized microphone levels and resets them on error", async () => { |
81 | 95 | const state = createState(); |
82 | 96 | await state.toggleRealtimeTalk(); |
|
0 commit comments