fixup tests / comments

This commit is contained in:
Half-Shot
2024-12-05 10:15:48 +00:00
parent a5c3d5c29d
commit d8857283bb
9 changed files with 164 additions and 141 deletions
+27 -21
View File
@@ -6,9 +6,18 @@ Please see LICENSE in the repository root for full details.
*/
import { render } from "@testing-library/react";
import { afterAll, expect, test, vitest } from "vitest";
import {
afterAll,
beforeEach,
expect,
test,
vitest,
MockedFunction,
Mock,
} from "vitest";
import { TooltipProvider } from "@vector-im/compound-web";
import { act, ReactNode } from "react";
import { afterEach } from "node:test";
import {
MockRoom,
@@ -20,14 +29,8 @@ import {
playReactionsSound,
soundEffectVolumeSetting,
} from "../settings/settings";
import {
prefetchSounds,
// We're using this from our mock, but it doesn't exist in the actual module.
//@ts-ignore
playSound,
} from "../useAudioContext";
import { prefetchSounds, useAudioContext } from "../useAudioContext";
import { GenericReaction, ReactionSet } from "../reactions";
import { afterEach } from "node:test";
const memberUserIdAlice = "@alice:example.org";
const memberUserIdBob = "@bob:example.org";
@@ -56,21 +59,10 @@ function TestComponent({
);
}
vitest.mock("../useAudioContext", async () => {
const playSound = vitest.fn();
return {
prefetchSounds: vitest.fn().mockReturnValueOnce({
sound: new ArrayBuffer(0),
}),
playSound,
useAudioContext: () => ({
playSound,
}),
};
});
vitest.mock("../useAudioContext");
afterEach(() => {
vitest.clearAllMocks();
vitest.resetAllMocks();
playReactionsSound.setValue(playReactionsSound.defaultValue);
soundEffectVolumeSetting.setValue(soundEffectVolumeSetting.defaultValue);
});
@@ -79,6 +71,20 @@ afterAll(() => {
vitest.restoreAllMocks();
});
let playSound: Mock<
NonNullable<ReturnType<typeof useAudioContext>>["playSound"]
>;
beforeEach(() => {
(prefetchSounds as MockedFunction<typeof prefetchSounds>).mockResolvedValue({
sound: new ArrayBuffer(0),
});
playSound = vitest.fn();
(useAudioContext as MockedFunction<typeof useAudioContext>).mockReturnValue({
playSound,
});
});
test("preloads all audio elements", () => {
playReactionsSound.setValue(true);
const rtcSession = new MockRTCSession(