|
| 1 | +/* |
| 2 | +Copyright 2025 Element Creations Ltd. |
| 3 | +
|
| 4 | + SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial |
| 5 | +Please see LICENSE in the repository root for full details. |
| 6 | +*/ |
| 7 | + |
| 8 | +import { test, vi, expect } from "vitest"; |
| 9 | +import EventEmitter from "events"; |
| 10 | + |
| 11 | +import { constant } from "./Behavior.ts"; |
| 12 | +import { withCallViewModel } from "./CallViewModel.test.ts"; |
| 13 | +import { aliceParticipant, localRtcMember } from "../utils/test-fixtures.ts"; |
| 14 | +import { ElementWidgetActions, widget } from "../widget.ts"; |
| 15 | +import { E2eeType } from "../e2ee/e2eeType.ts"; |
| 16 | +import { type CallViewModel } from "./CallViewModel.ts"; |
| 17 | + |
| 18 | +vi.mock("../widget", () => ({ |
| 19 | + ElementWidgetActions: { |
| 20 | + HangupCall: "HangupCall", |
| 21 | + // Add other actions if needed |
| 22 | + }, |
| 23 | + widget: { |
| 24 | + api: { |
| 25 | + transport: { |
| 26 | + send: vi.fn().mockResolvedValue(undefined), |
| 27 | + reply: vi.fn().mockResolvedValue(undefined), |
| 28 | + }, |
| 29 | + }, |
| 30 | + lazyActions: new EventEmitter(), |
| 31 | + }, |
| 32 | +})); |
| 33 | + |
| 34 | +test("expect leave when ElementWidgetActions.HangupCall is called", async () => { |
| 35 | + const pr = Promise.withResolvers<string>(); |
| 36 | + withCallViewModel( |
| 37 | + { |
| 38 | + remoteParticipants$: constant([aliceParticipant]), |
| 39 | + rtcMembers$: constant([localRtcMember]), |
| 40 | + }, |
| 41 | + (vm: CallViewModel) => { |
| 42 | + vm.leave$.subscribe((s: string) => { |
| 43 | + pr.resolve(s); |
| 44 | + }); |
| 45 | + |
| 46 | + widget!.lazyActions!.emit( |
| 47 | + ElementWidgetActions.HangupCall, |
| 48 | + new CustomEvent(ElementWidgetActions.HangupCall, { |
| 49 | + detail: { |
| 50 | + action: "im.vector.hangup", |
| 51 | + api: "toWidget", |
| 52 | + data: {}, |
| 53 | + requestId: "widgetapi-1761237395918", |
| 54 | + widgetId: "mrUjS9T6uKUOWHMxXvLbSv0F", |
| 55 | + }, |
| 56 | + }), |
| 57 | + ); |
| 58 | + }, |
| 59 | + { |
| 60 | + encryptionSystem: { kind: E2eeType.PER_PARTICIPANT }, |
| 61 | + }, |
| 62 | + ); |
| 63 | + |
| 64 | + const source = await pr.promise; |
| 65 | + expect(source).toBe("user"); |
| 66 | +}); |
0 commit comments