Remove LegacyCallHandler singleton (#34086)
* Remove dead code * Remove LegacyCallHandler singleton Route via SDKContext to cut import cycles * Remove unused setting * Fix tests * Fix tests * Cascade SDKContext through PersistedElement * Improve coverage * Iterate * Improve coverage * Improve coverage
This commit is contained in:
@@ -34,6 +34,7 @@ import {
|
||||
setupAsyncStoreWithClient,
|
||||
resetAsyncStoreWithClient,
|
||||
mkEvent,
|
||||
clientAndSDKContextRenderOptions,
|
||||
} from "../../test-utils";
|
||||
import defaultDispatcher from "../../../src/dispatcher/dispatcher";
|
||||
import { Action } from "../../../src/dispatcher/actions";
|
||||
@@ -47,9 +48,10 @@ import {
|
||||
getNotificationEventSendTs,
|
||||
IncomingCallToast,
|
||||
} from "../../../src/toasts/IncomingCallToast";
|
||||
import LegacyCallHandler, { AudioID } from "../../../src/LegacyCallHandler";
|
||||
import { AudioID } from "../../../src/LegacyCallHandler";
|
||||
import { CallEvent } from "../../../src/models/Call";
|
||||
import { type WidgetMessaging } from "../../../src/stores/widgets/WidgetMessaging";
|
||||
import { TestSDKContext } from "../TestSDKContext.ts";
|
||||
|
||||
function makeNotificationEvent(room: Room, content: IContent = {}): MatrixEvent {
|
||||
const ts = Date.now();
|
||||
@@ -76,6 +78,7 @@ describe("IncomingCallToast", () => {
|
||||
useMockedCalls();
|
||||
|
||||
let client: Mocked<MatrixClient>;
|
||||
let sdkContext: TestSDKContext;
|
||||
let room: Room;
|
||||
|
||||
let alice: RoomMember;
|
||||
@@ -92,6 +95,8 @@ describe("IncomingCallToast", () => {
|
||||
beforeEach(async () => {
|
||||
stubClient();
|
||||
client = mocked(MatrixClientPeg.safeGet());
|
||||
sdkContext = new TestSDKContext();
|
||||
sdkContext._client = client;
|
||||
|
||||
const audio = document.createElement("audio");
|
||||
audio.id = AudioID.Ring;
|
||||
@@ -146,6 +151,7 @@ describe("IncomingCallToast", () => {
|
||||
notificationEvent={notificationEvent}
|
||||
toastKey={getIncomingCallToastKey(callId, room.roomId)}
|
||||
/>,
|
||||
clientAndSDKContextRenderOptions(client, sdkContext),
|
||||
);
|
||||
return callId;
|
||||
};
|
||||
@@ -196,8 +202,11 @@ describe("IncomingCallToast", () => {
|
||||
|
||||
it("start ringing on ring notify event", () => {
|
||||
const notificationEvent = makeNotificationEvent(room, { notification_type: "ring" });
|
||||
const playMock = jest.spyOn(LegacyCallHandler.instance, "play");
|
||||
render(<IncomingCallToast notificationEvent={notificationEvent} toastKey="" />);
|
||||
const playMock = jest.spyOn(sdkContext.legacyCallHandler, "play");
|
||||
render(
|
||||
<IncomingCallToast notificationEvent={notificationEvent} toastKey="" />,
|
||||
clientAndSDKContextRenderOptions(client, sdkContext),
|
||||
);
|
||||
expect(playMock).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
|
||||
@@ -10,10 +10,15 @@ import { LOCAL_NOTIFICATION_SETTINGS_PREFIX, MatrixEvent, Room } from "matrix-js
|
||||
import { MatrixCall } from "matrix-js-sdk/src/webrtc/call";
|
||||
import React from "react";
|
||||
|
||||
import LegacyCallHandler from "../../../src/LegacyCallHandler";
|
||||
import IncomingLegacyCallToast from "../../../src/toasts/IncomingLegacyCallToast";
|
||||
import DMRoomMap from "../../../src/utils/DMRoomMap";
|
||||
import { getMockClientWithEventEmitter, mockClientMethodsServer, mockClientMethodsUser } from "../../test-utils";
|
||||
import {
|
||||
clientAndSDKContextRenderOptions,
|
||||
getMockClientWithEventEmitter,
|
||||
mockClientMethodsServer,
|
||||
mockClientMethodsUser,
|
||||
} from "../../test-utils";
|
||||
import { SDKContextClass } from "../../../src/contexts/SDKContextClass.ts";
|
||||
|
||||
describe("<IncomingLegacyCallToast />", () => {
|
||||
const userId = "@alice:server.org";
|
||||
@@ -41,16 +46,24 @@ describe("<IncomingLegacyCallToast />", () => {
|
||||
jest.clearAllMocks();
|
||||
mockClient.getAccountData.mockReturnValue(undefined);
|
||||
mockClient.getRoom.mockReturnValue(mockRoom);
|
||||
// @ts-ignore
|
||||
SDKContextClass.instance._client = mockClient;
|
||||
});
|
||||
|
||||
it("renders when silence button when call is not silenced", () => {
|
||||
const { getByLabelText } = render(getComponent());
|
||||
const { getByLabelText } = render(
|
||||
getComponent(),
|
||||
clientAndSDKContextRenderOptions(mockClient, SDKContextClass.instance),
|
||||
);
|
||||
expect(getByLabelText("Silence call")).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it("renders sound on button when call is silenced", () => {
|
||||
LegacyCallHandler.instance.silenceCall(call.callId);
|
||||
const { getByLabelText } = render(getComponent());
|
||||
SDKContextClass.instance.legacyCallHandler.silenceCall(call.callId);
|
||||
const { getByLabelText } = render(
|
||||
getComponent(),
|
||||
clientAndSDKContextRenderOptions(mockClient, SDKContextClass.instance),
|
||||
);
|
||||
expect(getByLabelText("Sound on")).toMatchSnapshot();
|
||||
});
|
||||
|
||||
@@ -66,7 +79,10 @@ describe("<IncomingLegacyCallToast />", () => {
|
||||
});
|
||||
}
|
||||
});
|
||||
const { getByLabelText } = render(getComponent());
|
||||
const { getByLabelText } = render(
|
||||
getComponent(),
|
||||
clientAndSDKContextRenderOptions(mockClient, SDKContextClass.instance),
|
||||
);
|
||||
expect(getByLabelText("Notifications silenced")).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user