mirror of
https://github.com/vector-im/element-call.git
synced 2026-08-08 20:09:19 +00:00
fix tests
This commit is contained in:
@@ -9,6 +9,7 @@ import { expect, vi, afterEach, beforeEach, test } from "vitest";
|
|||||||
import { type FC } from "react";
|
import { type FC } from "react";
|
||||||
import { render } from "@testing-library/react";
|
import { render } from "@testing-library/react";
|
||||||
import userEvent, { type UserEvent } from "@testing-library/user-event";
|
import userEvent, { type UserEvent } from "@testing-library/user-event";
|
||||||
|
import { BrowserRouter } from "react-router-dom";
|
||||||
|
|
||||||
import { deviceStub, MediaDevicesContext } from "./livekit/MediaDevicesContext";
|
import { deviceStub, MediaDevicesContext } from "./livekit/MediaDevicesContext";
|
||||||
import { useAudioContext } from "./useAudioContext";
|
import { useAudioContext } from "./useAudioContext";
|
||||||
@@ -38,6 +39,13 @@ const TestComponent: FC = () => {
|
|||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
const TestComponentWrapper: FC = () => {
|
||||||
|
return (
|
||||||
|
<BrowserRouter>
|
||||||
|
<TestComponent />
|
||||||
|
</BrowserRouter>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
const gainNode = vi.mocked(
|
const gainNode = vi.mocked(
|
||||||
{
|
{
|
||||||
@@ -94,13 +102,13 @@ afterEach(() => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test("can play a single sound", async () => {
|
test("can play a single sound", async () => {
|
||||||
const { findByText } = render(<TestComponent />);
|
const { findByText } = render(<TestComponentWrapper />);
|
||||||
await user.click(await findByText("Valid sound"));
|
await user.click(await findByText("Valid sound"));
|
||||||
expect(testAudioContext.createBufferSource).toHaveBeenCalledOnce();
|
expect(testAudioContext.createBufferSource).toHaveBeenCalledOnce();
|
||||||
});
|
});
|
||||||
|
|
||||||
test("will ignore sounds that are not registered", async () => {
|
test("will ignore sounds that are not registered", async () => {
|
||||||
const { findByText } = render(<TestComponent />);
|
const { findByText } = render(<TestComponentWrapper />);
|
||||||
await user.click(await findByText("Invalid sound"));
|
await user.click(await findByText("Invalid sound"));
|
||||||
expect(testAudioContext.createBufferSource).not.toHaveBeenCalled();
|
expect(testAudioContext.createBufferSource).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
@@ -122,7 +130,7 @@ test("will use the correct device", () => {
|
|||||||
stopUsingDeviceNames: () => {},
|
stopUsingDeviceNames: () => {},
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<TestComponent />
|
<TestComponentWrapper />
|
||||||
</MediaDevicesContext.Provider>,
|
</MediaDevicesContext.Provider>,
|
||||||
);
|
);
|
||||||
expect(testAudioContext.createBufferSource).not.toHaveBeenCalled();
|
expect(testAudioContext.createBufferSource).not.toHaveBeenCalled();
|
||||||
@@ -131,7 +139,7 @@ test("will use the correct device", () => {
|
|||||||
|
|
||||||
test("will use the correct volume level", async () => {
|
test("will use the correct volume level", async () => {
|
||||||
soundEffectVolumeSetting.setValue(0.33);
|
soundEffectVolumeSetting.setValue(0.33);
|
||||||
const { findByText } = render(<TestComponent />);
|
const { findByText } = render(<TestComponentWrapper />);
|
||||||
await user.click(await findByText("Valid sound"));
|
await user.click(await findByText("Valid sound"));
|
||||||
expect(testAudioContext.gain.gain.setValueAtTime).toHaveBeenCalledWith(
|
expect(testAudioContext.gain.gain.setValueAtTime).toHaveBeenCalledWith(
|
||||||
0.33,
|
0.33,
|
||||||
@@ -157,7 +165,7 @@ test("will use the pan if earpiece is selected", async () => {
|
|||||||
stopUsingDeviceNames: () => {},
|
stopUsingDeviceNames: () => {},
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<TestComponent />
|
<TestComponentWrapper />
|
||||||
</MediaDevicesContext.Provider>,
|
</MediaDevicesContext.Provider>,
|
||||||
);
|
);
|
||||||
await user.click(await findByText("Valid sound"));
|
await user.click(await findByText("Valid sound"));
|
||||||
|
|||||||
Reference in New Issue
Block a user