mirror of
https://github.com/vector-im/element-call.git
synced 2026-04-03 07:10:26 +00:00
Adapt reactions test
This commit is contained in:
@@ -27,29 +27,15 @@ import {
|
|||||||
import { useAudioContext } from "../useAudioContext";
|
import { useAudioContext } from "../useAudioContext";
|
||||||
import { GenericReaction, ReactionSet } from "../reactions";
|
import { GenericReaction, ReactionSet } from "../reactions";
|
||||||
import { prefetchSounds } from "../soundUtils";
|
import { prefetchSounds } from "../soundUtils";
|
||||||
import { ConnectionState } from "livekit-client";
|
|
||||||
import { CallMembership, MatrixRTCSession } from "matrix-js-sdk/src/matrixrtc";
|
|
||||||
import { BehaviorSubject, of } from "rxjs";
|
|
||||||
import { E2eeType } from "../e2ee/e2eeType";
|
|
||||||
import { CallViewModel } from "../state/CallViewModel";
|
import { CallViewModel } from "../state/CallViewModel";
|
||||||
|
import { getBasicCallViewModelEnvironment } from "../utils/test-viewmodel";
|
||||||
import {
|
import {
|
||||||
mockLivekitRoom,
|
alice,
|
||||||
mockLocalParticipant,
|
aliceRtcMember,
|
||||||
mockMatrixRoom,
|
bobRtcMember,
|
||||||
mockMatrixRoomMember,
|
local,
|
||||||
mockRemoteParticipant,
|
localRtcMember,
|
||||||
mockRtcMembership,
|
} from "../utils/test-fixtures";
|
||||||
MockRTCSession,
|
|
||||||
} from "../utils/test";
|
|
||||||
import { MatrixClient } from "matrix-js-sdk/src/client";
|
|
||||||
|
|
||||||
const localRtcMember = mockRtcMembership("@carol:example.org", "CCCC");
|
|
||||||
const local = mockMatrixRoomMember(localRtcMember);
|
|
||||||
const aliceRtcMember = mockRtcMembership("@alice:example.org", "AAAA");
|
|
||||||
const alice = mockMatrixRoomMember(aliceRtcMember);
|
|
||||||
const localParticipant = mockLocalParticipant({ identity: "" });
|
|
||||||
const aliceId = `${alice.userId}:${aliceRtcMember.deviceId}`;
|
|
||||||
const aliceParticipant = mockRemoteParticipant({ identity: aliceId });
|
|
||||||
|
|
||||||
function TestComponent({ vm }: { vm: CallViewModel }): ReactNode {
|
function TestComponent({ vm }: { vm: CallViewModel }): ReactNode {
|
||||||
return (
|
return (
|
||||||
@@ -58,42 +44,6 @@ function TestComponent({ vm }: { vm: CallViewModel }): ReactNode {
|
|||||||
</TooltipProvider>
|
</TooltipProvider>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
function testEnv(): CallViewModel {
|
|
||||||
const matrixRoomMembers = new Map([local, alice].map((p) => [p.userId, p]));
|
|
||||||
const remoteParticipants = of([aliceParticipant]);
|
|
||||||
const liveKitRoom = mockLivekitRoom(
|
|
||||||
{ localParticipant },
|
|
||||||
{ remoteParticipants },
|
|
||||||
);
|
|
||||||
const matrixRoom = mockMatrixRoom({
|
|
||||||
client: {
|
|
||||||
getUserId: () => localRtcMember.sender,
|
|
||||||
getDeviceId: () => localRtcMember.deviceId,
|
|
||||||
on: vitest.fn(),
|
|
||||||
off: vitest.fn(),
|
|
||||||
} as Partial<MatrixClient> as MatrixClient,
|
|
||||||
getMember: (userId) => matrixRoomMembers.get(userId) ?? null,
|
|
||||||
});
|
|
||||||
|
|
||||||
const remoteRtcMemberships = new BehaviorSubject<CallMembership[]>([
|
|
||||||
aliceRtcMember,
|
|
||||||
]);
|
|
||||||
|
|
||||||
const session = new MockRTCSession(
|
|
||||||
matrixRoom,
|
|
||||||
localRtcMember,
|
|
||||||
).withMemberships(remoteRtcMemberships);
|
|
||||||
|
|
||||||
const vm = new CallViewModel(
|
|
||||||
session as unknown as MatrixRTCSession,
|
|
||||||
liveKitRoom,
|
|
||||||
{
|
|
||||||
kind: E2eeType.PER_PARTICIPANT,
|
|
||||||
},
|
|
||||||
of(ConnectionState.Connected),
|
|
||||||
);
|
|
||||||
return vm;
|
|
||||||
}
|
|
||||||
|
|
||||||
vitest.mock("../useAudioContext");
|
vitest.mock("../useAudioContext");
|
||||||
vitest.mock("../soundUtils");
|
vitest.mock("../soundUtils");
|
||||||
@@ -123,14 +73,17 @@ beforeEach(() => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test("preloads all audio elements", () => {
|
test("preloads all audio elements", () => {
|
||||||
const vm = testEnv();
|
const { vm } = getBasicCallViewModelEnvironment([local, alice]);
|
||||||
playReactionsSound.setValue(true);
|
playReactionsSound.setValue(true);
|
||||||
render(<TestComponent vm={vm} />);
|
render(<TestComponent vm={vm} />);
|
||||||
expect(prefetchSounds).toHaveBeenCalledOnce();
|
expect(prefetchSounds).toHaveBeenCalledOnce();
|
||||||
});
|
});
|
||||||
|
|
||||||
test("will play an audio sound when there is a reaction", () => {
|
test("will play an audio sound when there is a reaction", () => {
|
||||||
const vm = testEnv();
|
const { vm, reactionsSubject } = getBasicCallViewModelEnvironment([
|
||||||
|
local,
|
||||||
|
alice,
|
||||||
|
]);
|
||||||
playReactionsSound.setValue(true);
|
playReactionsSound.setValue(true);
|
||||||
render(<TestComponent vm={vm} />);
|
render(<TestComponent vm={vm} />);
|
||||||
|
|
||||||
@@ -142,18 +95,18 @@ test("will play an audio sound when there is a reaction", () => {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
act(() => {
|
act(() => {
|
||||||
vm.updateReactions({
|
reactionsSubject.next({
|
||||||
raisedHands: {},
|
[aliceRtcMember.deviceId]: { reactionOption: chosenReaction, ttl: 0 },
|
||||||
reactions: {
|
|
||||||
memberEventAlice: chosenReaction,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
expect(playSound).toHaveBeenCalledWith(chosenReaction.name);
|
expect(playSound).toHaveBeenCalledWith(chosenReaction.name);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("will play the generic audio sound when there is soundless reaction", () => {
|
test("will play the generic audio sound when there is soundless reaction", () => {
|
||||||
const vm = testEnv();
|
const { vm, reactionsSubject } = getBasicCallViewModelEnvironment([
|
||||||
|
local,
|
||||||
|
alice,
|
||||||
|
]);
|
||||||
playReactionsSound.setValue(true);
|
playReactionsSound.setValue(true);
|
||||||
render(<TestComponent vm={vm} />);
|
render(<TestComponent vm={vm} />);
|
||||||
|
|
||||||
@@ -165,18 +118,18 @@ test("will play the generic audio sound when there is soundless reaction", () =>
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
act(() => {
|
act(() => {
|
||||||
vm.updateReactions({
|
reactionsSubject.next({
|
||||||
raisedHands: {},
|
[aliceRtcMember.deviceId]: { reactionOption: chosenReaction, ttl: 0 },
|
||||||
reactions: {
|
|
||||||
memberEventAlice: chosenReaction,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
expect(playSound).toHaveBeenCalledWith(GenericReaction.name);
|
expect(playSound).toHaveBeenCalledWith(GenericReaction.name);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("will play multiple audio sounds when there are multiple different reactions", () => {
|
test("will play multiple audio sounds when there are multiple different reactions", () => {
|
||||||
const vm = testEnv();
|
const { vm, reactionsSubject } = getBasicCallViewModelEnvironment([
|
||||||
|
local,
|
||||||
|
alice,
|
||||||
|
]);
|
||||||
playReactionsSound.setValue(true);
|
playReactionsSound.setValue(true);
|
||||||
render(<TestComponent vm={vm} />);
|
render(<TestComponent vm={vm} />);
|
||||||
|
|
||||||
@@ -188,13 +141,10 @@ test("will play multiple audio sounds when there are multiple different reaction
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
act(() => {
|
act(() => {
|
||||||
vm.updateReactions({
|
reactionsSubject.next({
|
||||||
raisedHands: {},
|
[aliceRtcMember.deviceId]: { reactionOption: reaction1, ttl: 0 },
|
||||||
reactions: {
|
[bobRtcMember.deviceId]: { reactionOption: reaction2, ttl: 0 },
|
||||||
memberEventAlice: reaction1,
|
[localRtcMember.deviceId]: { reactionOption: reaction1, ttl: 0 },
|
||||||
memberEventBob: reaction2,
|
|
||||||
memberEventCharlie: reaction1,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
expect(playSound).toHaveBeenCalledWith(reaction1.name);
|
expect(playSound).toHaveBeenCalledWith(reaction1.name);
|
||||||
|
|||||||
Reference in New Issue
Block a user