mirror of
https://github.com/vector-im/element-call.git
synced 2026-08-29 21:15:19 +00:00
adapt tests (wip)
This commit is contained in:
@@ -14,6 +14,11 @@ import {
|
|||||||
RemoteParticipant,
|
RemoteParticipant,
|
||||||
} from "livekit-client";
|
} from "livekit-client";
|
||||||
import * as ComponentsCore from "@livekit/components-core";
|
import * as ComponentsCore from "@livekit/components-core";
|
||||||
|
import {
|
||||||
|
CallMembership,
|
||||||
|
MatrixRTCSession,
|
||||||
|
MatrixRTCSessionEvent,
|
||||||
|
} from "matrix-js-sdk/src/matrixrtc";
|
||||||
|
|
||||||
import { CallViewModel, Layout } from "./CallViewModel";
|
import { CallViewModel, Layout } from "./CallViewModel";
|
||||||
import {
|
import {
|
||||||
@@ -30,25 +35,33 @@ import {
|
|||||||
ECConnectionState,
|
ECConnectionState,
|
||||||
} from "../livekit/useECConnectionState";
|
} from "../livekit/useECConnectionState";
|
||||||
import { E2eeType } from "../e2ee/e2eeType";
|
import { E2eeType } from "../e2ee/e2eeType";
|
||||||
|
import { MockRoom, MockRTCSession } from "../useReactions.test";
|
||||||
|
|
||||||
vi.mock("@livekit/components-core");
|
vi.mock("@livekit/components-core");
|
||||||
|
|
||||||
const aliceId = "@alice:example.org:AAAA";
|
const carolId = "@carol:example.org";
|
||||||
const bobId = "@bob:example.org:BBBB";
|
const carolDev = "CCCC";
|
||||||
|
const aliceId = "@alice:example.org";
|
||||||
|
const aliceDev = "AAAA";
|
||||||
|
const aliceRTCId = aliceId + ":" + aliceDev;
|
||||||
|
|
||||||
const alice = mockMember({ userId: "@alice:example.org" });
|
const bobId = "@bob:example.org";
|
||||||
const bob = mockMember({ userId: "@bob:example.org" });
|
const bobDev = "BBBB";
|
||||||
const carol = mockMember({ userId: "@carol:example.org" });
|
const bobRTCId = bobId + ":" + bobDev;
|
||||||
|
|
||||||
|
const alice = mockMember({ userId: aliceId });
|
||||||
|
const bob = mockMember({ userId: bobId });
|
||||||
|
const carol = mockMember({ userId: carolId });
|
||||||
|
|
||||||
const localParticipant = mockLocalParticipant({ identity: "" });
|
const localParticipant = mockLocalParticipant({ identity: "" });
|
||||||
const aliceParticipant = mockRemoteParticipant({ identity: aliceId });
|
const aliceParticipant = mockRemoteParticipant({ identity: aliceRTCId });
|
||||||
const aliceSharingScreen = mockRemoteParticipant({
|
const aliceSharingScreen = mockRemoteParticipant({
|
||||||
identity: aliceId,
|
identity: aliceRTCId,
|
||||||
isScreenShareEnabled: true,
|
isScreenShareEnabled: true,
|
||||||
});
|
});
|
||||||
const bobParticipant = mockRemoteParticipant({ identity: bobId });
|
const bobParticipant = mockRemoteParticipant({ identity: bobRTCId });
|
||||||
const bobSharingScreen = mockRemoteParticipant({
|
const bobSharingScreen = mockRemoteParticipant({
|
||||||
identity: bobId,
|
identity: bobRTCId,
|
||||||
isScreenShareEnabled: true,
|
isScreenShareEnabled: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -58,6 +71,9 @@ const members = new Map([
|
|||||||
[carol.userId, carol],
|
[carol.userId, carol],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
const rtcMemberAlice = { sender: aliceId, deviceId: aliceDev };
|
||||||
|
const rtcMemberBob = { sender: bobId, deviceId: bobDev };
|
||||||
|
const rtcMemberCarol = { sender: carolId, deviceId: carolDev };
|
||||||
export interface GridLayoutSummary {
|
export interface GridLayoutSummary {
|
||||||
type: "grid";
|
type: "grid";
|
||||||
spotlight?: string[];
|
spotlight?: string[];
|
||||||
@@ -132,9 +148,22 @@ function summarizeLayout(l: Layout): LayoutSummary {
|
|||||||
function withCallViewModel(
|
function withCallViewModel(
|
||||||
{ cold }: OurRunHelpers,
|
{ cold }: OurRunHelpers,
|
||||||
remoteParticipants: Observable<RemoteParticipant[]>,
|
remoteParticipants: Observable<RemoteParticipant[]>,
|
||||||
|
rtcMembers: Observable<Partial<CallMembership>[]>,
|
||||||
connectionState: Observable<ECConnectionState>,
|
connectionState: Observable<ECConnectionState>,
|
||||||
continuation: (vm: CallViewModel) => void,
|
continuation: (vm: CallViewModel) => void,
|
||||||
): void {
|
): void {
|
||||||
|
const room = mockMatrixRoom({
|
||||||
|
client: {
|
||||||
|
getUserId: () => carolId,
|
||||||
|
getDeviceId: () => carolDev,
|
||||||
|
} as Partial<MatrixClient> as MatrixClient,
|
||||||
|
getMember: (userId) => members.get(userId) ?? null,
|
||||||
|
});
|
||||||
|
const rtcSession = new MockRTCSession(room as unknown as MockRoom);
|
||||||
|
rtcMembers.subscribe((m) => {
|
||||||
|
rtcSession.memberships = m;
|
||||||
|
rtcSession.emit(MatrixRTCSessionEvent.MembershipsChanged);
|
||||||
|
});
|
||||||
const participantsSpy = vi
|
const participantsSpy = vi
|
||||||
.spyOn(ComponentsCore, "connectedParticipantsObserver")
|
.spyOn(ComponentsCore, "connectedParticipantsObserver")
|
||||||
.mockReturnValue(remoteParticipants);
|
.mockReturnValue(remoteParticipants);
|
||||||
@@ -152,12 +181,7 @@ function withCallViewModel(
|
|||||||
.mockImplementation((p) => cold("a", { a: p }));
|
.mockImplementation((p) => cold("a", { a: p }));
|
||||||
|
|
||||||
const vm = new CallViewModel(
|
const vm = new CallViewModel(
|
||||||
mockMatrixRoom({
|
rtcSession as unknown as MatrixRTCSession,
|
||||||
client: {
|
|
||||||
getUserId: () => "@carol:example.org",
|
|
||||||
} as Partial<MatrixClient> as MatrixClient,
|
|
||||||
getMember: (userId) => members.get(userId) ?? null,
|
|
||||||
}),
|
|
||||||
mockLivekitRoom({ localParticipant }),
|
mockLivekitRoom({ localParticipant }),
|
||||||
{
|
{
|
||||||
kind: E2eeType.PER_PARTICIPANT,
|
kind: E2eeType.PER_PARTICIPANT,
|
||||||
@@ -180,6 +204,8 @@ test("participants are retained during a focus switch", () => {
|
|||||||
const { hot, expectObservable } = helpers;
|
const { hot, expectObservable } = helpers;
|
||||||
// Participants disappear on frame 2 and come back on frame 3
|
// Participants disappear on frame 2 and come back on frame 3
|
||||||
const partMarbles = "a-ba";
|
const partMarbles = "a-ba";
|
||||||
|
// The RTC members never disappear
|
||||||
|
const rtcMemberMarbles = "a---";
|
||||||
// Start switching focus on frame 1 and reconnect on frame 3
|
// Start switching focus on frame 1 and reconnect on frame 3
|
||||||
const connMarbles = "ab-a";
|
const connMarbles = "ab-a";
|
||||||
// The visible participants should remain the same throughout the switch
|
// The visible participants should remain the same throughout the switch
|
||||||
@@ -191,6 +217,9 @@ test("participants are retained during a focus switch", () => {
|
|||||||
a: [aliceParticipant, bobParticipant],
|
a: [aliceParticipant, bobParticipant],
|
||||||
b: [],
|
b: [],
|
||||||
}),
|
}),
|
||||||
|
hot(rtcMemberMarbles, {
|
||||||
|
a: [rtcMemberAlice, rtcMemberBob, rtcMemberCarol],
|
||||||
|
}),
|
||||||
hot(connMarbles, {
|
hot(connMarbles, {
|
||||||
a: ConnectionState.Connected,
|
a: ConnectionState.Connected,
|
||||||
b: ECAddonConnectionState.ECSwitchingFocus,
|
b: ECAddonConnectionState.ECSwitchingFocus,
|
||||||
@@ -202,7 +231,7 @@ test("participants are retained during a focus switch", () => {
|
|||||||
a: {
|
a: {
|
||||||
type: "grid",
|
type: "grid",
|
||||||
spotlight: undefined,
|
spotlight: undefined,
|
||||||
grid: ["local:0", `${aliceId}:0`, `${bobId}:0`],
|
grid: ["local:0", `${aliceRTCId}:0`, `${bobRTCId}:0`],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import {
|
|||||||
} from "matrix-js-sdk/src/matrix";
|
} from "matrix-js-sdk/src/matrix";
|
||||||
import EventEmitter from "events";
|
import EventEmitter from "events";
|
||||||
import { randomUUID } from "crypto";
|
import { randomUUID } from "crypto";
|
||||||
|
import { CallMembership } from "matrix-js-sdk/src/matrixrtc";
|
||||||
|
|
||||||
import { ReactionsProvider, useReactions } from "./useReactions";
|
import { ReactionsProvider, useReactions } from "./useReactions";
|
||||||
|
|
||||||
@@ -74,10 +75,12 @@ const TestComponentWrapper = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
export class MockRTCSession extends EventEmitter {
|
export class MockRTCSession extends EventEmitter {
|
||||||
public memberships = Object.entries(membership).map(([eventId, sender]) => ({
|
public memberships: Partial<CallMembership>[] = Object.entries(
|
||||||
|
membership,
|
||||||
|
).map(([eventId, sender]) => ({
|
||||||
sender,
|
sender,
|
||||||
eventId,
|
eventId,
|
||||||
createdTs: (): Date => new Date(),
|
createdTs: (): number => Date.now(),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
public constructor(public readonly room: MockRoom) {
|
public constructor(public readonly room: MockRoom) {
|
||||||
@@ -93,7 +96,7 @@ export class MockRTCSession extends EventEmitter {
|
|||||||
this.memberships.push({
|
this.memberships.push({
|
||||||
sender,
|
sender,
|
||||||
eventId: `!fake-${randomUUID()}:event`,
|
eventId: `!fake-${randomUUID()}:event`,
|
||||||
createdTs: (): Date => new Date(),
|
createdTs: (): number => Date.now(),
|
||||||
});
|
});
|
||||||
this.emit(MatrixRTCSessionEvent.MembershipsChanged);
|
this.emit(MatrixRTCSessionEvent.MembershipsChanged);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user