From bb56f4205b963e60712db4c12e248355a0bdfed0 Mon Sep 17 00:00:00 2001 From: Hugh Nimmo-Smith Date: Thu, 7 Nov 2024 14:24:20 +0000 Subject: [PATCH] tidy up test init --- src/state/CallViewModel.test.ts | 41 +++++++++++++++------------------ src/utils/test.ts | 11 +++++++-- 2 files changed, 28 insertions(+), 24 deletions(-) diff --git a/src/state/CallViewModel.test.ts b/src/state/CallViewModel.test.ts index 5a20d3b8..9f208112 100644 --- a/src/state/CallViewModel.test.ts +++ b/src/state/CallViewModel.test.ts @@ -49,21 +49,21 @@ import { MockRoom, MockRTCSession } from "../useReactions.test"; vi.mock("@livekit/components-core"); -const alice = mockRoomMember({ userId: "@alice:example.org" }); -const bob = mockRoomMember({ userId: "@bob:example.org" }); -const carol = mockRoomMember({ userId: "@carol:example.org" }); -const dave = mockRoomMember({ userId: "@dave:example.org" }); +const localRtcMember = mockMembership("@carol:example.org", "CCCC"); +const aliceRtcMember = mockMembership("@alice:example.org", "AAAA"); +const bobRtcMember = mockMembership("@bob:example.org", "BBBB"); +const daveRtcMember = mockMembership("@dave:example.org", "DDDD"); -const aliceDev = "AAAA"; -const bobDev = "BBBB"; -const carolDev = "CCCC"; -const daveDev = "DDDD"; -const aliceId = `${alice.userId}:${aliceDev}`; -const bobId = `${bob.userId}:${bobDev}`; -const carolId = `${carol.userId}:${carolDev}`; -const daveId = `${dave.userId}:${daveDev}`; +const alice = mockRoomMember(aliceRtcMember); +const bob = mockRoomMember(bobRtcMember); +const carol = mockRoomMember(localRtcMember); +const dave = mockRoomMember(daveRtcMember); -const localParticipant = mockLocalParticipant({ identity: carolId }); +const aliceId = `${alice.userId}:${aliceRtcMember.deviceId}`; +const bobId = `${bob.userId}:${bobRtcMember.deviceId}`; +const daveId = `${dave.userId}:${daveRtcMember.deviceId}`; + +const localParticipant = mockLocalParticipant({ identity: "" }); const aliceParticipant = mockRemoteParticipant({ identity: aliceId }); const aliceSharingScreen = mockRemoteParticipant({ @@ -77,12 +77,9 @@ const bobSharingScreen = mockRemoteParticipant({ }); const daveParticipant = mockRemoteParticipant({ identity: daveId }); -const members = new Map([alice, bob, carol, dave].map((p) => [p.userId, p])); - -const aliceRtcMember = mockMembership(alice, aliceDev); -const bobRtcMember = mockMembership(bob, bobDev); -const localRtcMember = mockMembership(carol, carolDev); -const daveRtcMember = mockMembership(dave, daveDev); +const roomMembers = new Map( + [alice, bob, carol, dave].map((p) => [p.userId, p]), +); export interface GridLayoutSummary { type: "grid"; @@ -197,10 +194,10 @@ function withCallViewModel( ): void { const room = mockMatrixRoom({ client: { - getUserId: () => carol.userId, - getDeviceId: () => carolDev, + getUserId: () => localRtcMember.sender, + getDeviceId: () => localRtcMember.deviceId, } as Partial as MatrixClient, - getMember: (userId) => members.get(userId) ?? null, + getMember: (userId) => roomMembers.get(userId) ?? null, }); const rtcSession = new MockRTCSession(room as unknown as MockRoom); rtcMembers.subscribe((m) => { diff --git a/src/utils/test.ts b/src/utils/test.ts index b2df1562..2965f991 100644 --- a/src/utils/test.ts +++ b/src/utils/test.ts @@ -122,8 +122,15 @@ export function mockMembership( // Maybe it'd be good to move this to matrix-js-sdk? Our testing needs are // rather simple, but if one util to mock a member is good enough for us, maybe // it's useful for matrix-js-sdk consumers in general. -export function mockRoomMember(member: Partial): RoomMember { - return { ...mockEmitter(), ...member } as RoomMember; +export function mockRoomMember( + rtcMembership: CallMembership, + member: Partial = {}, +): RoomMember { + return { + ...mockEmitter(), + userId: rtcMembership.sender, + ...member, + } as RoomMember; } export function mockMatrixRoom(room: Partial): MatrixRoom {