Files
element-call/src/state/CallViewModelWidget.test.ts
T

58 lines
1.8 KiB
TypeScript
Raw Normal View History

2025-10-23 19:20:21 +02:00
/*
Copyright 2025 Element Creations Ltd.
SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
Please see LICENSE in the repository root for full details.
*/
2025-11-14 18:45:07 +01:00
import { it, vi, expect } from "vitest";
2026-09-02 13:23:01 +02:00
import { Subject } from "rxjs";
2025-10-23 19:20:21 +02:00
2025-11-14 18:45:07 +01:00
// import * as ComponentsCore from "@livekit/components-core";
import { withCallViewModel } from "./CallViewModel/CallViewModelTestUtils.ts";
import { type CallViewModel } from "./CallViewModel/CallViewModel.ts";
2025-10-23 19:20:21 +02:00
import { constant } from "./Behavior.ts";
import { aliceParticipant, localRtcMember } from "../utils/test-fixtures.ts";
2026-09-02 13:23:01 +02:00
import {
type HostBridge,
type HostRequest,
nullHostBridge,
} from "../HostBridge.ts";
2025-10-23 19:20:21 +02:00
import { E2eeType } from "../e2ee/e2eeType.ts";
2026-06-05 11:49:43 +02:00
import { MatrixRTCMode } from "../config/ConfigOptions.ts";
2025-11-14 18:45:07 +01:00
vi.mock("@livekit/components-core", { spy: true });
2025-10-23 19:20:21 +02:00
2026-08-26 17:53:06 +02:00
it.each([[MatrixRTCMode.Compatibility], [MatrixRTCMode.Matrix_2_0]])(
2026-09-02 13:23:01 +02:00
"expect leave when the host asks us to hang up (%s mode)",
2025-12-08 22:42:57 -05:00
async (mode) => {
const pr = Promise.withResolvers<string>();
2026-09-02 13:23:01 +02:00
const hangUp$ = new Subject<HostRequest<Record<string, never>>>();
const hostBridge: HostBridge = { ...nullHostBridge, hangUp$ };
const reply = vi.fn();
2025-12-08 22:42:57 -05:00
withCallViewModel(mode)(
{
remoteParticipants$: constant([aliceParticipant]),
rtcMembers$: constant([localRtcMember]),
},
(vm: CallViewModel) => {
vm.leave$.subscribe((s: string) => {
pr.resolve(s);
});
2025-10-23 19:20:21 +02:00
2026-09-02 13:23:01 +02:00
hangUp$.next({ data: {}, reply });
2025-12-08 22:42:57 -05:00
},
{
encryptionSystem: { kind: E2eeType.PER_PARTICIPANT },
2026-09-02 13:23:01 +02:00
hostBridge,
2025-12-08 22:42:57 -05:00
},
);
2025-10-23 19:20:21 +02:00
2025-12-08 22:42:57 -05:00
const source = await pr.promise;
expect(source).toBe("user");
2026-09-02 13:23:01 +02:00
// The host expects to hear back that we acted on its request
expect(reply).toHaveBeenCalledOnce();
2025-12-08 22:42:57 -05:00
},
);