From 02a49928b00f92938693d9f3795a601869be6773 Mon Sep 17 00:00:00 2001 From: fkwp Date: Wed, 23 Sep 2026 20:48:07 +0200 Subject: [PATCH] Use the shared audio capture stub in the lobby test - Drop the lobby test's own stub, which left the analyser buffer zeroed and so read as full scale rather than silence. Co-Authored-By: Claude Opus 5.5 (1M context) --- src/room/LobbyView.test.tsx | 50 +++++++------------------------------ 1 file changed, 9 insertions(+), 41 deletions(-) diff --git a/src/room/LobbyView.test.tsx b/src/room/LobbyView.test.tsx index 3aa4f136f..aedd9fdd5 100644 --- a/src/room/LobbyView.test.tsx +++ b/src/room/LobbyView.test.tsx @@ -20,7 +20,12 @@ import { import { LobbyView } from "./LobbyView"; import { E2eeType } from "../e2ee/e2eeType"; -import { mockMediaDevices, mockMuteStates } from "../utils/test"; +import { + mockMediaDevices, + mockMuteStates, + restoreAudioCapture, + stubAudioCapture, +} from "../utils/test"; import { type MediaDevices } from "../state/MediaDevices"; import { MediaDevicesContext } from "../MediaDevicesContext"; import { type ProcessorState } from "../livekit/TrackProcessorContext"; @@ -184,48 +189,11 @@ describe("LobbyView", () => { }); describe("LobbyView microphone level", () => { - const realMediaDevices = Object.getOwnPropertyDescriptor( - navigator, - "mediaDevices", - ); - - afterEach(() => { - vi.unstubAllGlobals(); - if (realMediaDevices === undefined) { - Reflect.deleteProperty(navigator, "mediaDevices"); - } else { - Object.defineProperty(navigator, "mediaDevices", realMediaDevices); - } - }); - - function stubAudioCapture(): void { - vi.stubGlobal( - "AudioContext", - class { - public readonly state = "running"; - public createAnalyser(): object { - return { - fftSize: 1024, - getByteTimeDomainData: (): void => {}, - }; - } - public createMediaStreamSource(): object { - return { connect: (): void => {} }; - } - public close(): void {} - }, - ); - // Only this property: replacing navigator loses getters like userAgent. - Object.defineProperty(navigator, "mediaDevices", { - configurable: true, - value: { - getUserMedia: vi.fn().mockResolvedValue({ getTracks: () => [] }), - }, - }); - } + afterEach(restoreAudioCapture); it("shows the microphone level meter", async () => { - stubAudioCapture(); + const capture = stubAudioCapture(); + capture.grant(); const user = userEvent.setup(); const { getByRole } = renderLobbyView({}, false, "desktop", { requestDeviceNames: (): void => {},