dont import withCallViewModel in Lifecycle test

This commit is contained in:
Timo K
2025-11-14 16:53:43 +01:00
parent da85e74596
commit b731c2e9fd

View File

@@ -5,25 +5,16 @@ SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
Please see LICENSE in the repository root for full details. Please see LICENSE in the repository root for full details.
*/ */
import { ConnectionState } from "livekit-client";
import {
EventType,
MatrixEvent,
type IEvent,
type IRoomTimelineData,
} from "matrix-js-sdk";
import { import {
type ICallNotifyContent, type ICallNotifyContent,
type IRTCNotificationContent, type IRTCNotificationContent,
MatrixRTCSessionEvent, MatrixRTCSessionEvent,
} from "matrix-js-sdk/lib/matrixrtc"; } from "matrix-js-sdk/lib/matrixrtc";
import { BehaviorSubject } from "rxjs";
import { describe, it } from "vitest"; import { describe, it } from "vitest";
import { E2eeType } from "../../e2ee/e2eeType"; import { E2eeType } from "../../e2ee/e2eeType";
import { withTestScheduler } from "../../utils/test"; import { withTestScheduler } from "../../utils/test";
import { import {
alice,
aliceParticipant, aliceParticipant,
aliceRtcMember, aliceRtcMember,
local, local,
@@ -33,7 +24,7 @@ import {
createCallNotificationLifecycle$, createCallNotificationLifecycle$,
type Props as CallNotificationLifecycleProps, type Props as CallNotificationLifecycleProps,
} from "./CallNotificationLifecycle"; } from "./CallNotificationLifecycle";
import { withCallViewModel } from "./CallViewModel.test"; // import { withCallViewModel } from "./CallViewModel.test";
import { trackEpoch } from "../ObservableScope"; import { trackEpoch } from "../ObservableScope";
const mockLegacyRingEvent = {} as { event_id: string } & ICallNotifyContent; const mockLegacyRingEvent = {} as { event_id: string } & ICallNotifyContent;
@@ -69,9 +60,7 @@ describe("waitForCallPickup$", () => {
}, },
localUser: localRtcMember, localUser: localRtcMember,
}; };
const lifecycle = createCallNotificationLifecycle$(props); const lifecycle = createCallNotificationLifecycle$(props);
expectObservable(lifecycle.callPickupState$).toBe("a 9ms b 29ms c", { expectObservable(lifecycle.callPickupState$).toBe("a 9ms b 29ms c", {
a: "unknown", a: "unknown",
b: "ringing", b: "ringing",
@@ -79,13 +68,11 @@ describe("waitForCallPickup$", () => {
}); });
}); });
}); });
it("ringing -> success if someone joins before timeout is reached", () => { it("ringing -> success if someone joins before timeout is reached", () => {
withTestScheduler(({ scope, hot, behavior, expectObservable }) => { withTestScheduler(({ scope, hot, behavior, expectObservable }) => {
// Someone joins at 20ms (both LiveKit participant and MatrixRTC member) // Someone joins at 20ms (both LiveKit participant and MatrixRTC member)
const props: CallNotificationLifecycleProps = { const props: CallNotificationLifecycleProps = {
scope, scope,
memberships$: scope.behavior( memberships$: scope.behavior(
behavior("a 19ms b", { behavior("a 19ms b", {
a: [localRtcMember], a: [localRtcMember],
@@ -103,7 +90,6 @@ describe("waitForCallPickup$", () => {
localUser: localRtcMember, localUser: localRtcMember,
}; };
const lifecycle = createCallNotificationLifecycle$(props); const lifecycle = createCallNotificationLifecycle$(props);
expectObservable(lifecycle.callPickupState$).toBe("a 4ms b 14ms c", { expectObservable(lifecycle.callPickupState$).toBe("a 4ms b 14ms c", {
a: "unknown", a: "unknown",
b: "ringing", b: "ringing",
@@ -111,13 +97,11 @@ describe("waitForCallPickup$", () => {
}); });
}); });
}); });
it("success when someone joins before we notify", () => { it("success when someone joins before we notify", () => {
withTestScheduler(({ scope, hot, behavior, expectObservable }) => { withTestScheduler(({ scope, hot, behavior, expectObservable }) => {
// Someone joins at 20ms (both LiveKit participant and MatrixRTC member) // Someone joins at 20ms (both LiveKit participant and MatrixRTC member)
const props: CallNotificationLifecycleProps = { const props: CallNotificationLifecycleProps = {
scope, scope,
memberships$: scope.behavior( memberships$: scope.behavior(
behavior("a 9ms b", { behavior("a 9ms b", {
a: [localRtcMember], a: [localRtcMember],
@@ -135,20 +119,17 @@ describe("waitForCallPickup$", () => {
localUser: localRtcMember, localUser: localRtcMember,
}; };
const lifecycle = createCallNotificationLifecycle$(props); const lifecycle = createCallNotificationLifecycle$(props);
expectObservable(lifecycle.callPickupState$).toBe("a 9ms b", { expectObservable(lifecycle.callPickupState$).toBe("a 9ms b", {
a: "unknown", a: "unknown",
b: "success", b: "success",
}); });
}); });
}); });
it("notify without lifetime -> immediate timeout", () => { it("notify without lifetime -> immediate timeout", () => {
withTestScheduler(({ scope, hot, behavior, expectObservable }) => { withTestScheduler(({ scope, hot, behavior, expectObservable }) => {
// Someone joins at 20ms (both LiveKit participant and MatrixRTC member) // Someone joins at 20ms (both LiveKit participant and MatrixRTC member)
const props: CallNotificationLifecycleProps = { const props: CallNotificationLifecycleProps = {
scope, scope,
memberships$: scope.behavior( memberships$: scope.behavior(
behavior("a", { behavior("a", {
a: [localRtcMember], a: [localRtcMember],
@@ -165,7 +146,6 @@ describe("waitForCallPickup$", () => {
localUser: localRtcMember, localUser: localRtcMember,
}; };
const lifecycle = createCallNotificationLifecycle$(props); const lifecycle = createCallNotificationLifecycle$(props);
expectObservable(lifecycle.callPickupState$).toBe("a 9ms b", { expectObservable(lifecycle.callPickupState$).toBe("a 9ms b", {
a: "unknown", a: "unknown",
b: "timeout", b: "timeout",
@@ -208,149 +188,145 @@ describe("waitForCallPickup$", () => {
}); });
}); });
it("decline before timeout window ends -> decline", () => { // it("decline before timeout window ends -> decline", () => {
withTestScheduler(({ schedule, expectObservable }) => { // withTestScheduler(({ schedule, expectObservable }) => {
withCallViewModel( // withCallViewModel(
{}, // {},
(vm, rtcSession) => { // (vm, rtcSession) => {
// Notify at 10ms with 50ms lifetime, decline at 40ms with matching id // // Notify at 10ms with 50ms lifetime, decline at 40ms with matching id
schedule(" 10ms r 29ms d", { // schedule(" 10ms r 29ms d", {
r: () => { // r: () => {
rtcSession.emit( // rtcSession.emit(
MatrixRTCSessionEvent.DidSendCallNotification, // MatrixRTCSessionEvent.DidSendCallNotification,
mockRingEvent("$decl1", 50), // mockRingEvent("$decl1", 50),
mockLegacyRingEvent, // mockLegacyRingEvent,
); // );
}, // },
d: () => { // d: () => {
// Emit decline timeline event with id matching the notification // // Emit decline timeline event with id matching the notification
rtcSession.room.emit( // rtcSession.room.emit(
MatrixRoomEvent.Timeline, // MatrixRoomEvent.Timeline,
new MatrixEvent({ // new MatrixEvent({
type: EventType.RTCDecline, // type: EventType.RTCDecline,
content: { // content: {
"m.relates_to": { // "m.relates_to": {
rel_type: "m.reference", // rel_type: "m.reference",
event_id: "$decl1", // event_id: "$decl1",
}, // },
}, // },
}), // }),
rtcSession.room, // rtcSession.room,
undefined, // undefined,
false, // false,
{} as IRoomTimelineData, // {} as IRoomTimelineData,
); // );
}, // },
}); // });
expectObservable(vm.callPickupState$).toBe("a 9ms b 29ms e", { // expectObservable(vm.callPickupState$).toBe("a 9ms b 29ms e", {
a: "unknown", // a: "unknown",
b: "ringing", // b: "ringing",
e: "decline", // e: "decline",
}); // });
}, // },
{ // {
waitForCallPickup: true, // waitForCallPickup: true,
encryptionSystem: { kind: E2eeType.PER_PARTICIPANT }, // encryptionSystem: { kind: E2eeType.PER_PARTICIPANT },
}, // },
); // );
}); // });
}); // });
// it("decline after timeout window ends -> stays timeout", () => {
it("decline after timeout window ends -> stays timeout", () => { // withTestScheduler(({ schedule, expectObservable }) => {
withTestScheduler(({ schedule, expectObservable }) => { // withCallViewModel(
withCallViewModel( // {},
{}, // (vm, rtcSession) => {
(vm, rtcSession) => { // // Notify at 10ms with 20ms lifetime (timeout at 30ms), decline at 40ms
// Notify at 10ms with 20ms lifetime (timeout at 30ms), decline at 40ms // schedule(" 10ms r 20ms t 10ms d", {
schedule(" 10ms r 20ms t 10ms d", { // r: () => {
r: () => { // rtcSession.emit(
rtcSession.emit( // MatrixRTCSessionEvent.DidSendCallNotification,
MatrixRTCSessionEvent.DidSendCallNotification, // mockRingEvent("$decl2", 20),
mockRingEvent("$decl2", 20), // mockLegacyRingEvent,
mockLegacyRingEvent, // );
); // },
}, // t: () => {},
t: () => {}, // d: () => {
d: () => { // rtcSession.room.emit(
rtcSession.room.emit( // MatrixRoomEvent.Timeline,
MatrixRoomEvent.Timeline, // new MatrixEvent({
new MatrixEvent({ // event_id: "$decl2",
event_id: "$decl2", // type: "m.rtc.decline",
type: "m.rtc.decline", // }),
}), // rtcSession.room,
rtcSession.room, // undefined,
undefined, // false,
false, // {} as IRoomTimelineData,
{} as IRoomTimelineData, // );
); // },
}, // });
}); // expectObservable(vm.callPickupState$).toBe("a 9ms b 19ms c", {
expectObservable(vm.callPickupState$).toBe("a 9ms b 19ms c", { // a: "unknown",
a: "unknown", // b: "ringing",
b: "ringing", // c: "timeout",
c: "timeout", // });
}); // },
}, // {
{ // waitForCallPickup: true,
waitForCallPickup: true, // encryptionSystem: { kind: E2eeType.PER_PARTICIPANT },
encryptionSystem: { kind: E2eeType.PER_PARTICIPANT }, // },
}, // );
); // });
}); // });
}); // function testStaysRinging(declineEvent: Partial<IEvent>): void {
// withTestScheduler(({ schedule, expectObservable }) => {
function testStaysRinging(declineEvent: Partial<IEvent>): void { // withCallViewModel(
withTestScheduler(({ schedule, expectObservable }) => { // {},
withCallViewModel( // (vm, rtcSession) => {
{}, // // Notify at 10ms with id A, decline arrives at 20ms with id B
(vm, rtcSession) => { // schedule(" 10ms r 10ms d", {
// Notify at 10ms with id A, decline arrives at 20ms with id B // r: () => {
schedule(" 10ms r 10ms d", { // rtcSession.emit(
r: () => { // MatrixRTCSessionEvent.DidSendCallNotification,
rtcSession.emit( // mockRingEvent("$right", 50),
MatrixRTCSessionEvent.DidSendCallNotification, // mockLegacyRingEvent,
mockRingEvent("$right", 50), // );
mockLegacyRingEvent, // },
); // d: () => {
}, // rtcSession.room.emit(
d: () => { // MatrixRoomEvent.Timeline,
rtcSession.room.emit( // new MatrixEvent(declineEvent),
MatrixRoomEvent.Timeline, // rtcSession.room,
new MatrixEvent(declineEvent), // undefined,
rtcSession.room, // false,
undefined, // {} as IRoomTimelineData,
false, // );
{} as IRoomTimelineData, // },
); // });
}, // // We assert up to 21ms to see the ringing at 10ms and no change at 20ms
}); // expectObservable(vm.callPickupState$, "21ms !").toBe("a 9ms b", {
// We assert up to 21ms to see the ringing at 10ms and no change at 20ms // a: "unknown",
expectObservable(vm.callPickupState$, "21ms !").toBe("a 9ms b", { // b: "ringing",
a: "unknown", // });
b: "ringing", // },
}); // {
}, // waitForCallPickup: true,
{ // encryptionSystem: { kind: E2eeType.PER_PARTICIPANT },
waitForCallPickup: true, // },
encryptionSystem: { kind: E2eeType.PER_PARTICIPANT }, // );
}, // });
); // }
}); // it("decline with wrong id is ignored (stays ringing)", () => {
} // testStaysRinging({
// event_id: "$wrong",
it("decline with wrong id is ignored (stays ringing)", () => { // type: "m.rtc.decline",
testStaysRinging({ // sender: local.userId,
event_id: "$wrong", // });
type: "m.rtc.decline", // });
sender: local.userId, // it("decline with sender being the local user is ignored (stays ringing)", () => {
}); // testStaysRinging({
}); // event_id: "$right",
// type: "m.rtc.decline",
it("decline with sender being the local user is ignored (stays ringing)", () => { // sender: alice.userId,
testStaysRinging({ // });
event_id: "$right", // });
type: "m.rtc.decline",
sender: alice.userId,
});
});
}); });