Skip to content

Commit be38f54

Browse files
committed
test that decline event gets sent
Signed-off-by: Timo K <[email protected]>
1 parent 38ef88e commit be38f54

File tree

3 files changed

+34
-4
lines changed

3 files changed

+34
-4
lines changed

src/toasts/IncomingCallToast.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ function JoinCallButtonWithCall({ onClick, call, disabledTooltip }: JoinCallButt
8080
}
8181

8282
interface DeclineCallButtonWithNotificationEventProps {
83-
notificationEvent: MatrixEvent;
84-
room?: Room;
8583
onDeclined: (e: ButtonEvent) => void;
84+
notificationEvent: MatrixEvent;
85+
room: Room | null;
8686
}
8787

8888
function DeclineCallButtonWithNotificationEvent({
@@ -142,11 +142,12 @@ export function IncomingCallToast({ notificationEvent }: Props): JSX.Element {
142142

143143
// Stop ringing on dismiss.
144144
const dismissToast = useCallback((): void => {
145-
if (!notificationEvent.getId()) {
145+
const notificationId = notificationEvent.getId();
146+
if (!notificationId) {
146147
logger.warn("Could not get eventId for RTCNotification event");
147148
return;
148149
}
149-
ToastStore.sharedInstance().dismissToast(getIncomingCallToastKey(notificationEvent.getId()!, roomId));
150+
ToastStore.sharedInstance().dismissToast(getIncomingCallToastKey(notificationId, roomId));
150151
LegacyCallHandler.instance.pause(AudioID.Ring);
151152
}, [notificationEvent, roomId]);
152153

@@ -248,6 +249,7 @@ export function IncomingCallToast({ notificationEvent }: Props): JSX.Element {
248249
onClick={(e) => {
249250
onJoinClick(e);
250251
}}
252+
role="button"
251253
>
252254
<div className="mx_IncomingCallToast_message">
253255
<VideoCallIcon width="20px" height="20px" style={{ position: "relative", top: "4px" }} />{" "}

test/test-utils/test-utils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ export function createTestClient(): MatrixClient {
204204
sendTyping: jest.fn().mockResolvedValue({}),
205205
sendMessage: jest.fn().mockResolvedValue({}),
206206
sendStateEvent: jest.fn().mockResolvedValue(undefined),
207+
sendRtcDecline: jest.fn().mockResolvedValue(undefined),
207208
getSyncState: jest.fn().mockReturnValue("SYNCING"),
208209
generateClientSecret: () => "t35tcl1Ent5ECr3T",
209210
isGuest: jest.fn().mockReturnValue(false),

test/unit-tests/toasts/IncomingCallToast-test.tsx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
EventType,
2020
RoomEvent,
2121
type IRoomTimelineData,
22+
type ISendEventResponse,
2223
} from "matrix-js-sdk/src/matrix";
2324
import { type ClientWidgetApi, Widget } from "matrix-widget-api";
2425
import { type IRTCNotificationContent } from "matrix-js-sdk/src/matrixrtc";
@@ -394,4 +395,30 @@ describe("IncomingCallToast", () => {
394395
),
395396
);
396397
});
398+
399+
it("sends a decline event when clicking the decline button and only dismiss after sending", async () => {
400+
(toastStore.dismissToast as Mock).mockReset();
401+
402+
renderToast();
403+
404+
const { promise, resolve } = Promise.withResolvers<ISendEventResponse>();
405+
client.sendRtcDecline.mockImplementation(() => {
406+
return promise;
407+
});
408+
409+
fireEvent.click(screen.getByRole("button", { name: "Decline" }));
410+
411+
expect(toastStore.dismissToast).not.toHaveBeenCalledWith(
412+
getIncomingCallToastKey(notificationEvent.getId()!, room.roomId),
413+
);
414+
expect(client.sendRtcDecline).toHaveBeenCalledWith("!1:example.org", "$notificationEventId");
415+
416+
resolve({ event_id: "$declineEventId" });
417+
418+
await waitFor(() =>
419+
expect(toastStore.dismissToast).toHaveBeenCalledWith(
420+
getIncomingCallToastKey(notificationEvent.getId()!, room.roomId),
421+
),
422+
);
423+
});
397424
});

0 commit comments

Comments
 (0)