@@ -26,6 +26,8 @@ import {
2626 SyncState ,
2727} from "matrix-js-sdk/src/matrix" ;
2828import { waitFor } from "@testing-library/react" ;
29+ // eslint-disable-next-line no-restricted-imports
30+ import { MatrixRTCSession } from "matrix-js-sdk/src/matrixrtc/MatrixRTCSession" ;
2931
3032import BasePlatform from "../src/BasePlatform" ;
3133import Notifier from "../src/Notifier" ;
@@ -53,6 +55,8 @@ import { Action } from "../src/dispatcher/actions";
5355import { VoiceBroadcastChunkEventType , VoiceBroadcastInfoState } from "../src/voice-broadcast" ;
5456import { mkVoiceBroadcastInfoStateEvent } from "./voice-broadcast/utils/test-utils" ;
5557import { addReplyToMessageContent } from "../src/utils/Reply" ;
58+ import { CallStore } from "../src/stores/CallStore" ;
59+ import { Call , ElementCall } from "../src/models/Call" ;
5660
5761jest . mock ( "../src/utils/notifications" , ( ) => ( {
5862 // @ts -ignore
@@ -139,6 +143,11 @@ describe("Notifier", () => {
139143 getRoom : jest . fn ( ) ,
140144 getPushActionsForEvent : jest . fn ( ) ,
141145 supportsThreads : jest . fn ( ) . mockReturnValue ( false ) ,
146+ matrixRTC : {
147+ on : jest . fn ( ) ,
148+ off : jest . fn ( ) ,
149+ getRoomSession : jest . fn ( ) ,
150+ } ,
142151 } ) ;
143152
144153 mockClient . pushRules = {
@@ -455,6 +464,23 @@ describe("Notifier", () => {
455464 expect ( ToastStore . sharedInstance ( ) . addOrReplaceToast ) . not . toHaveBeenCalled ( ) ;
456465 } ) ;
457466
467+ it ( "should not show toast when group call is already connected" , ( ) => {
468+ setGroupCallsEnabled ( true ) ;
469+ const roomSession = MatrixRTCSession . roomSessionForRoom ( mockClient , testRoom ) ;
470+ const spyCallId = jest . spyOn ( roomSession , "callId" , "get" ) . mockReturnValue ( "abc123" ) ;
471+
472+ mockClient . matrixRTC . getRoomSession . mockReturnValue ( roomSession ) ;
473+ ElementCall . create ( testRoom ) ;
474+ const mockedElementCall = Call . get ( testRoom ) ! ;
475+ const spyConnectedCalls = jest
476+ . spyOn ( CallStore . instance , "connectedCalls" , "get" )
477+ . mockReturnValue ( new Set ( [ mockedElementCall ] ) ) ;
478+ emitCallNotifyEvent ( ) ;
479+ expect ( ToastStore . sharedInstance ( ) . addOrReplaceToast ) . not . toHaveBeenCalled ( ) ;
480+ spyCallId . mockRestore ( ) ;
481+ spyConnectedCalls . mockRestore ( ) ;
482+ } ) ;
483+
458484 it ( "should not show toast when calling with non-group call event" , ( ) => {
459485 setGroupCallsEnabled ( true ) ;
460486
0 commit comments