Improve tests

This commit is contained in:
Half-Shot
2025-09-12 15:45:43 +01:00
parent 7d6d11a195
commit bf53a803f7
3 changed files with 22 additions and 9 deletions

View File

@@ -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(<CallEventAudioRenderer vm={vm} />);
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++) {

View File

@@ -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(

View File

@@ -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<CallViewModelOptions> = {},
): {
vm: CallViewModel;
rtcMemberships$: BehaviorSubject<CallMembership[]>;
@@ -148,6 +152,7 @@ export function getBasicCallViewModelEnvironment(
mockMediaDevices({}),
{
encryptionSystem: { kind: E2eeType.PER_PARTICIPANT },
...callViewModelOptions,
},
of(ConnectionState.Connected),
handRaisedSubject$,