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

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
Signed-off-by: Timo K <toger5@hotmail.de>
  • Loading branch information
toger5 committed Nov 14, 2023
1 parent ad26d1d commit 71263ea
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/toasts/IncomingCallToast.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<ViewRoomPayload>({
action: Action.ViewRoom,
room_id: room?.roomId,
view_call: true,
metricsTrigger: undefined,
});
dismissToast();
},
[room, dismissToast],
[room],
);

// Dismiss on closing toast.
Expand Down
26 changes: 22 additions & 4 deletions test/toasts/IncomingCallToast-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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");
Expand Down Expand Up @@ -96,7 +101,12 @@ describe("IncomingCallEvent", () => {
jest.restoreAllMocks();
});

const notifyContent = {
call_id: "",
};
const renderToast = () => {
call.event.getContent = () => notifyContent as any;

render(<IncomingCallToast notifyEvent={call.event} />);
};

Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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),
),
);
});

Expand All @@ -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),
),
);
});
});

0 comments on commit 71263ea

Please sign in to comment.