mirror of
https://github.com/vector-im/element-call.git
synced 2026-08-05 19:59:20 +00:00
Use testing library click
This commit is contained in:
@@ -13,6 +13,7 @@ import { afterEach } from "node:test";
|
|||||||
import { deviceStub, MediaDevicesContext } from "./livekit/MediaDevicesContext";
|
import { deviceStub, MediaDevicesContext } from "./livekit/MediaDevicesContext";
|
||||||
import { useAudioContext } from "./useAudioContext";
|
import { useAudioContext } from "./useAudioContext";
|
||||||
import { soundEffectVolumeSetting } from "./settings/settings";
|
import { soundEffectVolumeSetting } from "./settings/settings";
|
||||||
|
import userEvent from "@testing-library/user-event";
|
||||||
|
|
||||||
const TestComponent: FC = () => {
|
const TestComponent: FC = () => {
|
||||||
const audioCtx = useAudioContext({
|
const audioCtx = useAudioContext({
|
||||||
@@ -69,17 +70,19 @@ afterEach(() => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test("can play a single sound", async () => {
|
test("can play a single sound", async () => {
|
||||||
|
const user = userEvent.setup();
|
||||||
vitest.stubGlobal("AudioContext", MockAudioContext);
|
vitest.stubGlobal("AudioContext", MockAudioContext);
|
||||||
const { findByText } = render(<TestComponent />);
|
const { findByText } = render(<TestComponent />);
|
||||||
(await findByText("Valid sound")).click();
|
await user.click(await findByText("Valid sound"));
|
||||||
expect(
|
expect(
|
||||||
MockAudioContext.testContext.createBufferSource,
|
MockAudioContext.testContext.createBufferSource,
|
||||||
).toHaveBeenCalledOnce();
|
).toHaveBeenCalledOnce();
|
||||||
});
|
});
|
||||||
test("will ignore sounds that are not registered", async () => {
|
test("will ignore sounds that are not registered", async () => {
|
||||||
|
const user = userEvent.setup();
|
||||||
vitest.stubGlobal("AudioContext", MockAudioContext);
|
vitest.stubGlobal("AudioContext", MockAudioContext);
|
||||||
const { findByText } = render(<TestComponent />);
|
const { findByText } = render(<TestComponent />);
|
||||||
(await findByText("Invalid sound")).click();
|
await user.click(await findByText("Invalid sound"));
|
||||||
expect(
|
expect(
|
||||||
MockAudioContext.testContext.createBufferSource,
|
MockAudioContext.testContext.createBufferSource,
|
||||||
).not.toHaveBeenCalled();
|
).not.toHaveBeenCalled();
|
||||||
@@ -112,11 +115,12 @@ test("will use the correct device", () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("will use the correct volume", async () => {
|
test("will use the correct volume level", async () => {
|
||||||
|
const user = userEvent.setup();
|
||||||
vitest.stubGlobal("AudioContext", MockAudioContext);
|
vitest.stubGlobal("AudioContext", MockAudioContext);
|
||||||
soundEffectVolumeSetting.setValue(0.33);
|
soundEffectVolumeSetting.setValue(0.33);
|
||||||
const { findByText } = render(<TestComponent />);
|
const { findByText } = render(<TestComponent />);
|
||||||
(await findByText("Valid sound")).click();
|
await user.click(await findByText("Valid sound"));
|
||||||
expect(
|
expect(
|
||||||
MockAudioContext.testContext.gain.gain.setValueAtTime,
|
MockAudioContext.testContext.gain.gain.setValueAtTime,
|
||||||
).toHaveBeenCalledWith(0.33, 0);
|
).toHaveBeenCalledWith(0.33, 0);
|
||||||
|
|||||||
Reference in New Issue
Block a user