diff options
Diffstat (limited to 'apps/web/src/voiceover/__tests__/devices.test.ts')
| -rw-r--r-- | apps/web/src/voiceover/__tests__/devices.test.ts | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/apps/web/src/voiceover/__tests__/devices.test.ts b/apps/web/src/voiceover/__tests__/devices.test.ts new file mode 100644 index 00000000..524e8c3f --- /dev/null +++ b/apps/web/src/voiceover/__tests__/devices.test.ts @@ -0,0 +1,72 @@ +import { describe, expect, test } from "bun:test"; +import { + DEFAULT_AUDIO_INPUT_DEVICE_ID, + buildVoiceOverAudioConstraints, + normalizeSelectedDeviceId, + type VoiceOverInputDevice, +} from "@/voiceover/devices"; + +const devices: VoiceOverInputDevice[] = [ + { + deviceId: DEFAULT_AUDIO_INPUT_DEVICE_ID, + label: "System default microphone", + isDefault: true, + }, + { + deviceId: "blue-yeti-snowball", + label: "Blue Snowball", + isDefault: false, + }, +]; + +describe("buildVoiceOverAudioConstraints", () => { + test("uses default processing constraints without an exact device", () => { + const constraints = buildVoiceOverAudioConstraints({ deviceId: null }); + expect(constraints.audio).toEqual({ + echoCancellation: true, + noiseSuppression: true, + autoGainControl: true, + }); + }); + + test("adds an exact device constraint for a selected microphone", () => { + const constraints = buildVoiceOverAudioConstraints({ + deviceId: "blue-yeti-snowball", + }); + expect(constraints.audio).toEqual({ + deviceId: { exact: "blue-yeti-snowball" }, + echoCancellation: true, + noiseSuppression: true, + autoGainControl: true, + }); + }); +}); + +describe("normalizeSelectedDeviceId", () => { + test("keeps the selected device when it is still present", () => { + expect( + normalizeSelectedDeviceId({ + deviceId: "blue-yeti-snowball", + devices, + }), + ).toBe("blue-yeti-snowball"); + }); + + test("clears a selected device when it is no longer present", () => { + expect( + normalizeSelectedDeviceId({ + deviceId: "missing", + devices, + }), + ).toBeNull(); + }); + + test("keeps the browser default device id", () => { + expect( + normalizeSelectedDeviceId({ + deviceId: DEFAULT_AUDIO_INPUT_DEVICE_ID, + devices: [], + }), + ).toBe(DEFAULT_AUDIO_INPUT_DEVICE_ID); + }); +}); |
