Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 556af0d

Browse files
committed
update tests
Signed-off-by: Timo K <[email protected]>
1 parent 1573b1b commit 556af0d

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

src/toasts/IncomingCallToast.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -123,15 +123,15 @@ export function IncomingCallToast({ notifyEvent }: Props): JSX.Element {
123123
(e: ButtonEvent): void => {
124124
e.stopPropagation();
125125

126+
// The toast will be automatically dismissed by the dispatcher callback above
126127
defaultDispatcher.dispatch<ViewRoomPayload>({
127128
action: Action.ViewRoom,
128129
room_id: room?.roomId,
129130
view_call: true,
130131
metricsTrigger: undefined,
131132
});
132-
dismissToast();
133133
},
134-
[room, dismissToast],
134+
[room],
135135
);
136136

137137
// Dismiss on closing toast.

test/toasts/IncomingCallToast-test.tsx

+22-4
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import { WidgetMessagingStore } from "../../src/stores/widgets/WidgetMessagingSt
3737
import DMRoomMap from "../../src/utils/DMRoomMap";
3838
import ToastStore from "../../src/stores/ToastStore";
3939
import { getIncomingCallToastKey, IncomingCallToast } from "../../src/toasts/IncomingCallToast";
40+
import { AudioID } from "../../src/LegacyCallHandler";
4041

4142
describe("IncomingCallEvent", () => {
4243
useMockedCalls();
@@ -59,6 +60,10 @@ describe("IncomingCallEvent", () => {
5960
stubClient();
6061
client = mocked(MatrixClientPeg.safeGet());
6162

63+
const audio = document.createElement("audio");
64+
audio.id = AudioID.Ring;
65+
document.body.appendChild(audio);
66+
6267
room = new Room("!1:example.org", client, "@alice:example.org");
6368

6469
alice = mkRoomMember(room.roomId, "@alice:example.org");
@@ -96,7 +101,12 @@ describe("IncomingCallEvent", () => {
96101
jest.restoreAllMocks();
97102
});
98103

104+
const notifyContent = {
105+
call_id: "",
106+
};
99107
const renderToast = () => {
108+
call.event.getContent = () => notifyContent as any;
109+
100110
render(<IncomingCallToast notifyEvent={call.event} />);
101111
};
102112

@@ -141,7 +151,9 @@ describe("IncomingCallEvent", () => {
141151
}),
142152
);
143153
await waitFor(() =>
144-
expect(toastStore.dismissToast).toHaveBeenCalledWith(getIncomingCallToastKey(call.event.getStateKey()!)),
154+
expect(toastStore.dismissToast).toHaveBeenCalledWith(
155+
getIncomingCallToastKey(notifyContent.call_id, room.roomId),
156+
),
145157
);
146158

147159
defaultDispatcher.unregister(dispatcherRef);
@@ -155,7 +167,9 @@ describe("IncomingCallEvent", () => {
155167

156168
fireEvent.click(screen.getByRole("button", { name: "Close" }));
157169
await waitFor(() =>
158-
expect(toastStore.dismissToast).toHaveBeenCalledWith(getIncomingCallToastKey(call.event.getStateKey()!)),
170+
expect(toastStore.dismissToast).toHaveBeenCalledWith(
171+
getIncomingCallToastKey(notifyContent.call_id, room.roomId),
172+
),
159173
);
160174

161175
defaultDispatcher.unregister(dispatcherRef);
@@ -171,7 +185,9 @@ describe("IncomingCallEvent", () => {
171185
});
172186

173187
await waitFor(() =>
174-
expect(toastStore.dismissToast).toHaveBeenCalledWith(getIncomingCallToastKey(call.event.getStateKey()!)),
188+
expect(toastStore.dismissToast).toHaveBeenCalledWith(
189+
getIncomingCallToastKey(notifyContent.call_id, room.roomId),
190+
),
175191
);
176192
});
177193

@@ -182,7 +198,9 @@ describe("IncomingCallEvent", () => {
182198
event.emit(MatrixEventEvent.BeforeRedaction, event, {} as unknown as MatrixEvent);
183199

184200
await waitFor(() =>
185-
expect(toastStore.dismissToast).toHaveBeenCalledWith(getIncomingCallToastKey(call.event.getStateKey()!)),
201+
expect(toastStore.dismissToast).toHaveBeenCalledWith(
202+
getIncomingCallToastKey(notifyContent.call_id, room.roomId),
203+
),
186204
);
187205
});
188206
});

0 commit comments

Comments
 (0)