From bf53a803f78bc578f4309d875600f5f0cc7184f9 Mon Sep 17 00:00:00 2001 From: Half-Shot Date: Fri, 12 Sep 2025 15:45:43 +0100 Subject: [PATCH] Improve tests --- src/room/CallEventAudioRenderer.test.tsx | 14 ++++++++++++++ src/state/CallViewModel.ts | 10 ++-------- src/utils/test-viewmodel.ts | 7 ++++++- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/room/CallEventAudioRenderer.test.tsx b/src/room/CallEventAudioRenderer.test.tsx index 894d1d24..beae9cae 100644 --- a/src/room/CallEventAudioRenderer.test.tsx +++ b/src/room/CallEventAudioRenderer.test.tsx @@ -105,6 +105,20 @@ test("plays a sound when a user leaves", () => { expect(playSound).toBeCalledWith("left"); }); +test("does not play a sound before the call is successful", () => { + const { vm, rtcMemberships$ } = getBasicCallViewModelEnvironment( + [local, alice], + [localRtcMember], + { waitForCallPickup: true }, + ); + render(); + + act(() => { + rtcMemberships$.next([localRtcMember]); + }); + expect(playSound).not.toBeCalledWith("left"); +}); + test("plays no sound when the participant list is more than the maximum size", () => { const mockRtcMemberships: CallMembership[] = [localRtcMember]; for (let i = 0; i < MAX_PARTICIPANT_COUNT_FOR_SOUND; i++) { diff --git a/src/state/CallViewModel.ts b/src/state/CallViewModel.ts index ff68fa43..1911588f 100644 --- a/src/state/CallViewModel.ts +++ b/src/state/CallViewModel.ts @@ -37,7 +37,6 @@ import { concat, distinctUntilChanged, endWith, - every, filter, forkJoin, fromEvent, @@ -976,17 +975,12 @@ export class CallViewModel extends ViewModel { ) : constant(null); - public readonly callWasSuccessful$ = this.callPickupState$.pipe( - every((x) => x !== "success" && x === null), - map((v) => !v), - ); - public readonly leaveSoundEffect$ = combineLatest([ - this.callWasSuccessful$, + this.callPickupState$, this.userMedia$, ]).pipe( // Until the call is successful, do not play a leave sound. - skipWhile(([c]) => c === false), + skipWhile(([c]) => c !== null && c !== "success"), map(([, userMedia]) => userMedia), pairwise(), filter( diff --git a/src/utils/test-viewmodel.ts b/src/utils/test-viewmodel.ts index e5558ae2..09044e3f 100644 --- a/src/utils/test-viewmodel.ts +++ b/src/utils/test-viewmodel.ts @@ -22,7 +22,10 @@ import { } from "matrix-js-sdk"; import { E2eeType } from "../e2ee/e2eeType"; -import { CallViewModel } from "../state/CallViewModel"; +import { + CallViewModel, + type CallViewModelOptions, +} from "../state/CallViewModel"; import { mockLivekitRoom, mockMatrixRoom, @@ -122,6 +125,7 @@ export function getBasicRTCSession( export function getBasicCallViewModelEnvironment( members: RoomMember[], initialRtcMemberships: CallMembership[] = [localRtcMember, aliceRtcMember], + callViewModelOptions: Partial = {}, ): { vm: CallViewModel; rtcMemberships$: BehaviorSubject; @@ -148,6 +152,7 @@ export function getBasicCallViewModelEnvironment( mockMediaDevices({}), { encryptionSystem: { kind: E2eeType.PER_PARTICIPANT }, + ...callViewModelOptions, }, of(ConnectionState.Connected), handRaisedSubject$,