From 8b09e7d65ea94f776689cfc142fc05d8e25eb1d5 Mon Sep 17 00:00:00 2001 From: Timo Date: Tue, 9 Jul 2024 14:35:14 +0200 Subject: [PATCH] add test --- test/Notifier-test.ts | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/test/Notifier-test.ts b/test/Notifier-test.ts index a47b6cf5a4d2..7619c8c34190 100644 --- a/test/Notifier-test.ts +++ b/test/Notifier-test.ts @@ -26,6 +26,8 @@ import { SyncState, } from "matrix-js-sdk/src/matrix"; import { waitFor } from "@testing-library/react"; +// eslint-disable-next-line no-restricted-imports +import { MatrixRTCSession } from "matrix-js-sdk/src/matrixrtc/MatrixRTCSession"; import BasePlatform from "../src/BasePlatform"; import Notifier from "../src/Notifier"; @@ -53,6 +55,8 @@ import { Action } from "../src/dispatcher/actions"; import { VoiceBroadcastChunkEventType, VoiceBroadcastInfoState } from "../src/voice-broadcast"; import { mkVoiceBroadcastInfoStateEvent } from "./voice-broadcast/utils/test-utils"; import { addReplyToMessageContent } from "../src/utils/Reply"; +import { CallStore } from "../src/stores/CallStore"; +import { Call, ElementCall } from "../src/models/Call"; jest.mock("../src/utils/notifications", () => ({ // @ts-ignore @@ -139,6 +143,11 @@ describe("Notifier", () => { getRoom: jest.fn(), getPushActionsForEvent: jest.fn(), supportsThreads: jest.fn().mockReturnValue(false), + matrixRTC: { + on: jest.fn(), + off: jest.fn(), + getRoomSession: jest.fn(), + }, }); mockClient.pushRules = { @@ -455,6 +464,23 @@ describe("Notifier", () => { expect(ToastStore.sharedInstance().addOrReplaceToast).not.toHaveBeenCalled(); }); + it("should not show toast when group call is already connected", () => { + setGroupCallsEnabled(true); + const roomSession = MatrixRTCSession.roomSessionForRoom(mockClient, testRoom); + const spyCallId = jest.spyOn(roomSession, "callId", "get").mockReturnValue("abc123"); + + mockClient.matrixRTC.getRoomSession.mockReturnValue(roomSession); + ElementCall.create(testRoom); + const mockedElementCall = Call.get(testRoom)!; + const spyConnectedCalls = jest + .spyOn(CallStore.instance, "connectedCalls", "get") + .mockReturnValue(new Set([mockedElementCall])); + emitCallNotifyEvent(); + expect(ToastStore.sharedInstance().addOrReplaceToast).not.toHaveBeenCalled(); + spyCallId.mockRestore(); + spyConnectedCalls.mockRestore(); + }); + it("should not show toast when calling with non-group call event", () => { setGroupCallsEnabled(true);