mirror of
https://github.com/vector-im/element-call.git
synced 2026-03-22 06:30:25 +00:00
fix tests
This commit is contained in:
@@ -16,15 +16,18 @@ import { type RemoteAudioTrack } from "livekit-client";
|
||||
import { type ReactNode } from "react";
|
||||
import { useTracks } from "@livekit/components-react";
|
||||
|
||||
import { testAudioContext } from "../useAudioContext.test";
|
||||
import {
|
||||
TestAudioConstructor,
|
||||
testAudioContext,
|
||||
TestAudioContextConstructor,
|
||||
} from "../useAudioContext.test";
|
||||
import * as MediaDevicesContext from "./MediaDevicesContext";
|
||||
import { MatrixAudioRenderer } from "./MatrixAudioRenderer";
|
||||
import { mockTrack } from "../utils/test";
|
||||
|
||||
export const TestAudioContextConstructor = vi.fn(() => testAudioContext);
|
||||
|
||||
beforeEach(() => {
|
||||
vi.stubGlobal("AudioContext", TestAudioContextConstructor);
|
||||
vi.stubGlobal("Audio", TestAudioConstructor);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
|
||||
@@ -87,13 +87,19 @@ export const testAudioContext = {
|
||||
createGain: vi.fn().mockReturnValue(gainNode),
|
||||
createStereoPanner: vi.fn().mockReturnValue(panNode),
|
||||
close: vi.fn().mockResolvedValue(undefined),
|
||||
createMediaStreamDestination: vi.fn(),
|
||||
createMediaStreamDestination: vi.fn().mockReturnValue({ stream: undefined }),
|
||||
};
|
||||
export const TestAudioContextConstructor = vi.fn(() => testAudioContext);
|
||||
export const testAudioElement = {
|
||||
setSinkId: vi.fn().mockResolvedValue(null),
|
||||
};
|
||||
export const TestAudioConstructor = vi.fn(() => testAudioElement);
|
||||
|
||||
let user: UserEvent;
|
||||
beforeEach(() => {
|
||||
vi.stubGlobal("AudioContext", TestAudioContextConstructor);
|
||||
vi.stubGlobal("Audio", TestAudioConstructor);
|
||||
|
||||
user = userEvent.setup();
|
||||
});
|
||||
|
||||
@@ -115,6 +121,7 @@ test("will ignore sounds that are not registered", async () => {
|
||||
});
|
||||
|
||||
test("will use the correct device", () => {
|
||||
testAudioElement.setSinkId.mockClear();
|
||||
render(
|
||||
<MediaDevicesContext.Provider
|
||||
value={{
|
||||
@@ -135,7 +142,7 @@ test("will use the correct device", () => {
|
||||
</MediaDevicesContext.Provider>,
|
||||
);
|
||||
expect(testAudioContext.createBufferSource).not.toHaveBeenCalled();
|
||||
expect(testAudioContext.setSinkId).toHaveBeenCalledWith("chosen-device");
|
||||
expect(testAudioElement.setSinkId).toHaveBeenCalledWith("chosen-device");
|
||||
});
|
||||
|
||||
test("will use the correct volume level", async () => {
|
||||
|
||||
@@ -59,6 +59,7 @@ interface Props<S extends string> {
|
||||
|
||||
interface UseAudioContext<S> {
|
||||
playSound(soundName: S): Promise<void>;
|
||||
htmlAudioElement: HTMLAudioElement;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -140,5 +141,6 @@ export function useAudioContext<S extends string>(
|
||||
earpiecePan,
|
||||
);
|
||||
},
|
||||
htmlAudioElement,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user