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

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
toger5 committed Jul 10, 2024
1 parent 0899272 commit 42b736b
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions test/Notifier-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ import {
SyncState,
} from "matrix-js-sdk/src/matrix";
import { waitFor } from "@testing-library/react";
// eslint-disable-next-line no-restricted-imports
import { MatrixRTCSession } from "matrix-js-sdk/src/matrixrtc/MatrixRTCSession";
// eslint-disable-next-line no-restricted-imports
import { CallMembership } from "matrix-js-sdk/src/matrixrtc/CallMembership";

import BasePlatform from "../src/BasePlatform";
import Notifier from "../src/Notifier";
Expand Down Expand Up @@ -53,6 +57,8 @@ import { Action } from "../src/dispatcher/actions";
import { VoiceBroadcastChunkEventType, VoiceBroadcastInfoState } from "../src/voice-broadcast";
import { mkVoiceBroadcastInfoStateEvent } from "./voice-broadcast/utils/test-utils";
import { addReplyToMessageContent } from "../src/utils/Reply";
import { CallStore } from "../src/stores/CallStore";

Check failure on line 60 in test/Notifier-test.ts

View workflow job for this annotation

GitHub Actions / ESLint

'CallStore' is defined but never used

Check failure on line 60 in test/Notifier-test.ts

View workflow job for this annotation

GitHub Actions / Typescript Syntax Check

'CallStore' is declared but its value is never read.
import { Call, ElementCall } from "../src/models/Call";

Check failure on line 61 in test/Notifier-test.ts

View workflow job for this annotation

GitHub Actions / ESLint

'Call' is defined but never used

Check failure on line 61 in test/Notifier-test.ts

View workflow job for this annotation

GitHub Actions / ESLint

'ElementCall' is defined but never used

Check failure on line 61 in test/Notifier-test.ts

View workflow job for this annotation

GitHub Actions / Typescript Syntax Check

All imports in import declaration are unused.

jest.mock("../src/utils/notifications", () => ({
// @ts-ignore
Expand Down Expand Up @@ -139,6 +145,11 @@ describe("Notifier", () => {
getRoom: jest.fn(),
getPushActionsForEvent: jest.fn(),
supportsThreads: jest.fn().mockReturnValue(false),
matrixRTC: {
on: jest.fn(),
off: jest.fn(),
getRoomSession: jest.fn(),
},
});

mockClient.pushRules = {
Expand Down Expand Up @@ -455,6 +466,35 @@ describe("Notifier", () => {
expect(ToastStore.sharedInstance().addOrReplaceToast).not.toHaveBeenCalled();
});

it("should not show toast when group call is already connected", () => {
setGroupCallsEnabled(true);
const spyCallMemberships = jest.spyOn(MatrixRTCSession, "callMembershipsForRoom").mockReturnValue([
new CallMembership(
mkEvent({
event: true,
room: testRoom.roomId,
user: userId,
type: EventType.GroupCallMemberPrefix,
content: {},
}),
{
call_id: "123",
application: "m.call",
focus_active: { type: "livekit" },
foci_preferred: [],
device_id: "DEVICE",
},
),
]);

const roomSession = MatrixRTCSession.roomSessionForRoom(mockClient, testRoom);

mockClient.matrixRTC.getRoomSession.mockReturnValue(roomSession);
emitCallNotifyEvent();
expect(ToastStore.sharedInstance().addOrReplaceToast).not.toHaveBeenCalled();
spyCallMemberships.mockRestore();
});

it("should not show toast when calling with non-group call event", () => {
setGroupCallsEnabled(true);

Expand Down

0 comments on commit 42b736b

Please sign in to comment.