diff --git a/src/toasts/IncomingCallToast.tsx b/src/toasts/IncomingCallToast.tsx index 419e4d365c63..5ac81cc4ed70 100644 --- a/src/toasts/IncomingCallToast.tsx +++ b/src/toasts/IncomingCallToast.tsx @@ -123,15 +123,15 @@ export function IncomingCallToast({ notifyEvent }: Props): JSX.Element { (e: ButtonEvent): void => { e.stopPropagation(); + // The toast will be automatically dismissed by the dispatcher callback above defaultDispatcher.dispatch({ action: Action.ViewRoom, room_id: room?.roomId, view_call: true, metricsTrigger: undefined, }); - dismissToast(); }, - [room, dismissToast], + [room], ); // Dismiss on closing toast. diff --git a/test/toasts/IncomingCallToast-test.tsx b/test/toasts/IncomingCallToast-test.tsx index 3023f3f0c311..c02eb29d10b6 100644 --- a/test/toasts/IncomingCallToast-test.tsx +++ b/test/toasts/IncomingCallToast-test.tsx @@ -37,6 +37,7 @@ import { WidgetMessagingStore } from "../../src/stores/widgets/WidgetMessagingSt import DMRoomMap from "../../src/utils/DMRoomMap"; import ToastStore from "../../src/stores/ToastStore"; import { getIncomingCallToastKey, IncomingCallToast } from "../../src/toasts/IncomingCallToast"; +import { AudioID } from "../../src/LegacyCallHandler"; describe("IncomingCallEvent", () => { useMockedCalls(); @@ -59,6 +60,10 @@ describe("IncomingCallEvent", () => { stubClient(); client = mocked(MatrixClientPeg.safeGet()); + const audio = document.createElement("audio"); + audio.id = AudioID.Ring; + document.body.appendChild(audio); + room = new Room("!1:example.org", client, "@alice:example.org"); alice = mkRoomMember(room.roomId, "@alice:example.org"); @@ -96,7 +101,12 @@ describe("IncomingCallEvent", () => { jest.restoreAllMocks(); }); + const notifyContent = { + call_id: "", + }; const renderToast = () => { + call.event.getContent = () => notifyContent as any; + render(); }; @@ -141,7 +151,9 @@ describe("IncomingCallEvent", () => { }), ); await waitFor(() => - expect(toastStore.dismissToast).toHaveBeenCalledWith(getIncomingCallToastKey(call.event.getStateKey()!)), + expect(toastStore.dismissToast).toHaveBeenCalledWith( + getIncomingCallToastKey(notifyContent.call_id, room.roomId), + ), ); defaultDispatcher.unregister(dispatcherRef); @@ -155,7 +167,9 @@ describe("IncomingCallEvent", () => { fireEvent.click(screen.getByRole("button", { name: "Close" })); await waitFor(() => - expect(toastStore.dismissToast).toHaveBeenCalledWith(getIncomingCallToastKey(call.event.getStateKey()!)), + expect(toastStore.dismissToast).toHaveBeenCalledWith( + getIncomingCallToastKey(notifyContent.call_id, room.roomId), + ), ); defaultDispatcher.unregister(dispatcherRef); @@ -171,7 +185,9 @@ describe("IncomingCallEvent", () => { }); await waitFor(() => - expect(toastStore.dismissToast).toHaveBeenCalledWith(getIncomingCallToastKey(call.event.getStateKey()!)), + expect(toastStore.dismissToast).toHaveBeenCalledWith( + getIncomingCallToastKey(notifyContent.call_id, room.roomId), + ), ); }); @@ -182,7 +198,9 @@ describe("IncomingCallEvent", () => { event.emit(MatrixEventEvent.BeforeRedaction, event, {} as unknown as MatrixEvent); await waitFor(() => - expect(toastStore.dismissToast).toHaveBeenCalledWith(getIncomingCallToastKey(call.event.getStateKey()!)), + expect(toastStore.dismissToast).toHaveBeenCalledWith( + getIncomingCallToastKey(notifyContent.call_id, room.roomId), + ), ); }); });