From d9fe31039ff1bdbb2ffb4ea470e7d9289fe71afe Mon Sep 17 00:00:00 2001 From: Timo K Date: Fri, 19 Sep 2025 18:01:45 +0200 Subject: [PATCH] start fixing CallViewModel tests. Signed-off-by: Timo K --- src/room/InCallView.tsx | 1 + src/room/VideoPreview.test.tsx | 13 +++---------- src/state/CallViewModel.test.ts | 12 +++--------- src/utils/test.ts | 8 ++++++++ 4 files changed, 15 insertions(+), 19 deletions(-) diff --git a/src/room/InCallView.tsx b/src/room/InCallView.tsx index 2f720148..daf5034a 100644 --- a/src/room/InCallView.tsx +++ b/src/room/InCallView.tsx @@ -210,6 +210,7 @@ export const InCallView: FC = ({ // annoyingly we don't get the disconnection reason this way, // only by listening for the emitted event // This needs to be done differential. with the vm connection state we start with Disconnected. + // TODO-MULTI-SFU decide how to handle this properly // if (connectionState === ConnectionState.Disconnected) // throw new ConnectionLostError(); diff --git a/src/room/VideoPreview.test.tsx b/src/room/VideoPreview.test.tsx index 3bbb6ad5..717333ee 100644 --- a/src/room/VideoPreview.test.tsx +++ b/src/room/VideoPreview.test.tsx @@ -9,15 +9,8 @@ import { expect, describe, it, vi, beforeAll } from "vitest"; import { render } from "@testing-library/react"; import { type MatrixInfo, VideoPreview } from "./VideoPreview"; -import { type MuteStates } from "./MuteStates"; import { E2eeType } from "../e2ee/e2eeType"; - -function mockMuteStates({ audio = true, video = true } = {}): MuteStates { - return { - audio: { enabled: audio, setEnabled: vi.fn() }, - video: { enabled: video, setEnabled: vi.fn() }, - }; -} +import { mockMuteStates } from "../utils/test"; describe("VideoPreview", () => { const matrixInfo: MatrixInfo = { @@ -49,7 +42,7 @@ describe("VideoPreview", () => { const { queryByRole } = render( } />, @@ -61,7 +54,7 @@ describe("VideoPreview", () => { const { queryByRole } = render( } />, diff --git a/src/state/CallViewModel.test.ts b/src/state/CallViewModel.test.ts index ef4ef762..b736b780 100644 --- a/src/state/CallViewModel.test.ts +++ b/src/state/CallViewModel.test.ts @@ -53,7 +53,6 @@ import { type Layout, } from "./CallViewModel"; import { - mockLivekitRoom, mockLocalParticipant, mockMatrixRoom, mockMatrixRoomMember, @@ -62,6 +61,7 @@ import { mockRtcMembership, MockRTCSession, mockMediaDevices, + mockMuteStates, } from "../utils/test"; import { ECAddonConnectionState, @@ -340,21 +340,15 @@ function withCallViewModel( const roomEventSelectorSpy = vi .spyOn(ComponentsCore, "roomEventSelector") .mockImplementation((_room, _eventType) => of()); - - const livekitRoom = mockLivekitRoom( - { localParticipant }, - { remoteParticipants$ }, - ); - + const muteStates = mockMuteStates(); const raisedHands$ = new BehaviorSubject>({}); const vm = new CallViewModel( rtcSession as unknown as MatrixRTCSession, room, - livekitRoom, mediaDevices, + muteStates, options, - connectionState$, raisedHands$, new BehaviorSubject({}), ); diff --git a/src/utils/test.ts b/src/utils/test.ts index 31c6068a..53b6d0ee 100644 --- a/src/utils/test.ts +++ b/src/utils/test.ts @@ -53,6 +53,7 @@ import { Config } from "../config/Config"; import { type MediaDevices } from "../state/MediaDevices"; import { type Behavior, constant } from "../state/Behavior"; import { ObservableScope } from "../state/ObservableScope"; +import { Handler, MuteStates } from "../state/MuteStates"; export function withFakeTimers(continuation: () => void): void { vi.useFakeTimers(); @@ -417,3 +418,10 @@ export function mockMediaDevices(data: Partial): MediaDevices { ...data, } as MediaDevices; } + +export function mockMuteStates( + joined$: Observable = of(true), +): MuteStates { + const observableScope = new ObservableScope(); + return new MuteStates(observableScope, mockMediaDevices({}), joined$); +}