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:
@@ -26,6 +26,7 @@ import {
|
||||
MockedCall,
|
||||
setupAsyncStoreWithClient,
|
||||
useMockMediaDevices,
|
||||
clientAndSDKContextRenderOptions,
|
||||
} from "../../../../test-utils";
|
||||
import { MatrixClientPeg } from "../../../../../src/MatrixClientPeg";
|
||||
import { CallView as _CallView } from "../../../../../src/components/views/voip/CallView";
|
||||
@@ -33,6 +34,7 @@ import { WidgetMessagingStore } from "../../../../../src/stores/widgets/WidgetMe
|
||||
import { CallStore } from "../../../../../src/stores/CallStore";
|
||||
import DMRoomMap from "../../../../../src/utils/DMRoomMap";
|
||||
import { type WidgetMessaging } from "../../../../../src/stores/widgets/WidgetMessaging";
|
||||
import { TestSDKContext } from "../../../TestSDKContext.ts";
|
||||
|
||||
const CallView = wrapInMatrixClientContext(_CallView);
|
||||
|
||||
@@ -41,6 +43,7 @@ describe("CallView", () => {
|
||||
jest.spyOn(HTMLMediaElement.prototype, "play").mockImplementation(async () => {});
|
||||
|
||||
let client: Mocked<MatrixClient>;
|
||||
let sdkContext: TestSDKContext;
|
||||
let room: Room;
|
||||
let alice: RoomMember;
|
||||
let call: MockedCall;
|
||||
@@ -51,6 +54,8 @@ describe("CallView", () => {
|
||||
|
||||
stubClient();
|
||||
client = mocked(MatrixClientPeg.safeGet());
|
||||
sdkContext = new TestSDKContext();
|
||||
sdkContext._client = client;
|
||||
DMRoomMap.makeShared(client);
|
||||
|
||||
room = new Room("!1:example.org", client, "@alice:example.org", {
|
||||
@@ -88,7 +93,10 @@ describe("CallView", () => {
|
||||
});
|
||||
|
||||
const renderView = async (role: string | undefined = undefined): Promise<void> => {
|
||||
render(<CallView room={room} resizing={false} role={role} onClose={() => {}} />);
|
||||
render(
|
||||
<CallView room={room} resizing={false} role={role} onClose={() => {}} />,
|
||||
clientAndSDKContextRenderOptions(client, sdkContext),
|
||||
);
|
||||
await act(() => Promise.resolve()); // Let effects settle
|
||||
};
|
||||
|
||||
|
||||
@@ -6,16 +6,21 @@ Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
import React from "react";
|
||||
import { render } from "jest-matrix-react";
|
||||
import { render, fireEvent } from "jest-matrix-react";
|
||||
import { type MatrixCall } from "matrix-js-sdk/src/matrix";
|
||||
import { type CallFeed } from "matrix-js-sdk/src/webrtc/callFeed";
|
||||
import { SDPStreamMetadataPurpose } from "matrix-js-sdk/src/webrtc/callEventTypes";
|
||||
|
||||
import LegacyCallView from "../../../../../src/components/views/voip/LegacyCallView";
|
||||
import { stubClient } from "../../../../test-utils";
|
||||
import { clientAndSDKContextRenderOptions, createTestClient, stubClient } from "../../../../test-utils";
|
||||
import DMRoomMap from "../../../../../src/utils/DMRoomMap";
|
||||
import { TestSDKContext } from "../../../TestSDKContext.ts";
|
||||
|
||||
describe("LegacyCallView", () => {
|
||||
const cli = stubClient();
|
||||
const sdkContext = new TestSDKContext();
|
||||
sdkContext._client = cli;
|
||||
|
||||
it("should exit full screen on unmount", () => {
|
||||
const element = document.createElement("div");
|
||||
// @ts-expect-error
|
||||
@@ -35,7 +40,10 @@ describe("LegacyCallView", () => {
|
||||
isScreensharing: jest.fn().mockReturnValue(false),
|
||||
} as unknown as MatrixCall;
|
||||
|
||||
const { unmount } = render(<LegacyCallView call={call} sidebarShown={false} />);
|
||||
const { unmount } = render(
|
||||
<LegacyCallView call={call} sidebarShown={false} />,
|
||||
clientAndSDKContextRenderOptions(cli, sdkContext),
|
||||
);
|
||||
expect(document.exitFullscreen).not.toHaveBeenCalled();
|
||||
unmount();
|
||||
expect(document.exitFullscreen).toHaveBeenCalled();
|
||||
@@ -75,7 +83,10 @@ describe("LegacyCallView", () => {
|
||||
getUserIdForRoomId: jest.fn().mockReturnValue("test-user"),
|
||||
} as unknown as DMRoomMap);
|
||||
|
||||
const { container, rerender } = render(<LegacyCallView call={call} sidebarShown={true} />);
|
||||
const { container, rerender } = render(
|
||||
<LegacyCallView call={call} sidebarShown={true} />,
|
||||
clientAndSDKContextRenderOptions(cli, sdkContext),
|
||||
);
|
||||
expect(container.querySelector(".mx_LegacyCallViewSidebar")).toBeTruthy();
|
||||
rerender(<LegacyCallView call={call} sidebarShown={true} />);
|
||||
expect(container.querySelector(".mx_LegacyCallViewSidebar")).toBeTruthy();
|
||||
@@ -98,7 +109,102 @@ describe("LegacyCallView", () => {
|
||||
getUserIdForRoomId: jest.fn().mockReturnValue("test-user"),
|
||||
} as unknown as DMRoomMap);
|
||||
|
||||
const { container } = render(<LegacyCallView call={call} sidebarShown={false} pipMode={true} />);
|
||||
const { container } = render(
|
||||
<LegacyCallView call={call} sidebarShown={false} pipMode={true} />,
|
||||
clientAndSDKContextRenderOptions(cli, sdkContext),
|
||||
);
|
||||
expect(container.querySelector(".mx_LegacyCallViewButtons_button_sidebar")).toBeFalsy();
|
||||
});
|
||||
|
||||
it("should allow user to resume held call", async () => {
|
||||
const client = createTestClient();
|
||||
const sdkContext = new TestSDKContext();
|
||||
sdkContext._client = client;
|
||||
|
||||
const call = {
|
||||
roomId: "test-room",
|
||||
on: jest.fn(),
|
||||
removeListener: jest.fn(),
|
||||
getFeeds: jest.fn().mockReturnValue(
|
||||
[{ local: true }, { local: false }, { local: true, screenshare: true }].map(
|
||||
(x, i) =>
|
||||
({
|
||||
stream: { id: "test-" + i },
|
||||
addListener: jest.fn(),
|
||||
removeListener: jest.fn(),
|
||||
getMember: jest.fn(),
|
||||
isAudioMuted: jest.fn().mockReturnValue(true),
|
||||
isVideoMuted: jest.fn().mockReturnValue(true),
|
||||
isLocal: jest.fn().mockReturnValue(x.local),
|
||||
purpose: x.screenshare && SDPStreamMetadataPurpose.Screenshare,
|
||||
}) as unknown as CallFeed,
|
||||
),
|
||||
),
|
||||
isLocalOnHold: jest.fn().mockReturnValue(false),
|
||||
isRemoteOnHold: jest.fn().mockReturnValue(true),
|
||||
isMicrophoneMuted: jest.fn().mockReturnValue(true),
|
||||
isLocalVideoMuted: jest.fn().mockReturnValue(true),
|
||||
isScreensharing: jest.fn().mockReturnValue(true),
|
||||
noIncomingFeeds: jest.fn().mockReturnValue(false),
|
||||
opponentSupportsSDPStreamMetadata: jest.fn().mockReturnValue(true),
|
||||
getOpponentMember: jest.fn(),
|
||||
} as unknown as MatrixCall;
|
||||
|
||||
jest.spyOn(sdkContext.legacyCallHandler, "roomIdForCall").mockReturnValue(call.roomId);
|
||||
jest.spyOn(sdkContext.legacyCallHandler, "setActiveCallRoomId");
|
||||
|
||||
const { getByText } = render(
|
||||
<LegacyCallView call={call} sidebarShown />,
|
||||
clientAndSDKContextRenderOptions(client, sdkContext),
|
||||
);
|
||||
fireEvent.click(getByText("Resume"));
|
||||
|
||||
expect(sdkContext.legacyCallHandler.setActiveCallRoomId).toHaveBeenCalledWith(call.roomId);
|
||||
});
|
||||
|
||||
it("should allow user to hangup call", async () => {
|
||||
const client = createTestClient();
|
||||
const sdkContext = new TestSDKContext();
|
||||
sdkContext._client = client;
|
||||
|
||||
const call = {
|
||||
roomId: "test-room",
|
||||
on: jest.fn(),
|
||||
removeListener: jest.fn(),
|
||||
getFeeds: jest.fn().mockReturnValue(
|
||||
[{ local: true }, { local: false }, { local: true, screenshare: true }].map(
|
||||
(x, i) =>
|
||||
({
|
||||
stream: { id: "test-" + i },
|
||||
addListener: jest.fn(),
|
||||
removeListener: jest.fn(),
|
||||
getMember: jest.fn(),
|
||||
isAudioMuted: jest.fn().mockReturnValue(true),
|
||||
isVideoMuted: jest.fn().mockReturnValue(true),
|
||||
isLocal: jest.fn().mockReturnValue(x.local),
|
||||
purpose: x.screenshare && SDPStreamMetadataPurpose.Screenshare,
|
||||
}) as unknown as CallFeed,
|
||||
),
|
||||
),
|
||||
isLocalOnHold: jest.fn().mockReturnValue(false),
|
||||
isRemoteOnHold: jest.fn().mockReturnValue(false),
|
||||
isMicrophoneMuted: jest.fn().mockReturnValue(true),
|
||||
isLocalVideoMuted: jest.fn().mockReturnValue(true),
|
||||
isScreensharing: jest.fn().mockReturnValue(true),
|
||||
noIncomingFeeds: jest.fn().mockReturnValue(false),
|
||||
opponentSupportsSDPStreamMetadata: jest.fn().mockReturnValue(true),
|
||||
getOpponentMember: jest.fn(),
|
||||
} as unknown as MatrixCall;
|
||||
|
||||
jest.spyOn(sdkContext.legacyCallHandler, "roomIdForCall").mockReturnValue(call.roomId);
|
||||
jest.spyOn(sdkContext.legacyCallHandler, "hangupOrReject");
|
||||
|
||||
const { getByLabelText } = render(
|
||||
<LegacyCallView call={call} sidebarShown />,
|
||||
clientAndSDKContextRenderOptions(client, sdkContext),
|
||||
);
|
||||
fireEvent.click(getByLabelText("Hangup"));
|
||||
|
||||
expect(sdkContext.legacyCallHandler.hangupOrReject).toHaveBeenCalledWith(call.roomId);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -12,29 +12,29 @@ import { CallEventHandlerEvent } from "matrix-js-sdk/src/webrtc/callEventHandler
|
||||
|
||||
import LegacyCallView from "../../../../../src/components/views/voip/LegacyCallView";
|
||||
import LegacyCallViewForRoom from "../../../../../src/components/views/voip/LegacyCallViewForRoom";
|
||||
import { mkStubRoom, stubClient } from "../../../../test-utils";
|
||||
import { clientAndSDKContextRenderOptions, mkStubRoom, stubClient } from "../../../../test-utils";
|
||||
import DMRoomMap from "../../../../../src/utils/DMRoomMap";
|
||||
import { MatrixClientPeg } from "../../../../../src/MatrixClientPeg";
|
||||
import LegacyCallHandler from "../../../../../src/LegacyCallHandler";
|
||||
import { SDKContext } from "../../../../../src/contexts/SDKContext";
|
||||
import { SDKContextClass } from "../../../../../src/contexts/SDKContextClass";
|
||||
import { TestSDKContext } from "../../../TestSDKContext.ts";
|
||||
|
||||
jest.mock("../../../../../src/components/views/voip/LegacyCallView", () => jest.fn(() => "LegacyCallView"));
|
||||
|
||||
describe("LegacyCallViewForRoom", () => {
|
||||
const LegacyCallViewMock = LegacyCallView as unknown as jest.Mock;
|
||||
let sdkContext: SDKContextClass;
|
||||
let sdkContext: TestSDKContext;
|
||||
|
||||
beforeEach(() => {
|
||||
stubClient();
|
||||
sdkContext = new SDKContextClass();
|
||||
sdkContext = new TestSDKContext();
|
||||
sdkContext._client = stubClient();
|
||||
LegacyCallViewMock.mockClear();
|
||||
});
|
||||
|
||||
it("should remember sidebar state, defaulting to shown", async () => {
|
||||
const callHandler = new LegacyCallHandler();
|
||||
const callHandler = new LegacyCallHandler(sdkContext);
|
||||
callHandler.start();
|
||||
jest.spyOn(LegacyCallHandler, "instance", "get").mockImplementation(() => callHandler);
|
||||
sdkContext._LegacyCallHandler = callHandler;
|
||||
|
||||
const call = new MatrixCall({
|
||||
client: MatrixClientPeg.safeGet(),
|
||||
@@ -49,7 +49,10 @@ describe("LegacyCallViewForRoom", () => {
|
||||
const cli = MatrixClientPeg.safeGet();
|
||||
cli.emit(CallEventHandlerEvent.Incoming, call);
|
||||
|
||||
const { rerender } = render(<LegacyCallViewForRoom roomId={call.roomId} />);
|
||||
const { rerender } = render(
|
||||
<LegacyCallViewForRoom roomId={call.roomId} />,
|
||||
clientAndSDKContextRenderOptions(cli, sdkContext),
|
||||
);
|
||||
|
||||
let props = LegacyCallViewMock.mock.lastCall![0];
|
||||
expect(props.sidebarShown).toBeTruthy(); // Sidebar defaults to shown
|
||||
@@ -84,9 +87,7 @@ describe("LegacyCallViewForRoom", () => {
|
||||
addListener: jest.fn(),
|
||||
removeListener: jest.fn(),
|
||||
};
|
||||
jest.spyOn(LegacyCallHandler, "instance", "get").mockImplementation(
|
||||
() => callHandler as unknown as LegacyCallHandler,
|
||||
);
|
||||
sdkContext._LegacyCallHandler = callHandler as unknown as LegacyCallHandler;
|
||||
|
||||
jest.spyOn(sdkContext.resizeNotifier, "startResizing");
|
||||
jest.spyOn(sdkContext.resizeNotifier, "stopResizing");
|
||||
|
||||
@@ -14,9 +14,9 @@ import { type MatrixClient, Room } from "matrix-js-sdk/src/matrix";
|
||||
|
||||
import * as AvatarModule from "../../../../../src/Avatar";
|
||||
import VideoFeed from "../../../../../src/components/views/voip/VideoFeed";
|
||||
import { stubClient, useMockedCalls } from "../../../../test-utils";
|
||||
import type LegacyCallHandler from "../../../../../src/LegacyCallHandler";
|
||||
import { clientAndSDKContextRenderOptions, stubClient, useMockedCalls } from "../../../../test-utils";
|
||||
import DMRoomMap from "../../../../../src/utils/DMRoomMap";
|
||||
import { TestSDKContext } from "../../../TestSDKContext.ts";
|
||||
|
||||
const FAKE_AVATAR_URL = "http://fakeurl.dummy/fake.png";
|
||||
|
||||
@@ -24,9 +24,12 @@ describe("VideoFeed", () => {
|
||||
useMockedCalls();
|
||||
|
||||
let client: MatrixClient;
|
||||
let sdkContext: TestSDKContext;
|
||||
|
||||
beforeAll(() => {
|
||||
client = stubClient();
|
||||
sdkContext = new TestSDKContext();
|
||||
sdkContext._client = client;
|
||||
(AvatarModule as any).avatarUrlForRoom = jest.fn().mockReturnValue(FAKE_AVATAR_URL);
|
||||
|
||||
const dmRoomMap = new DMRoomMap(client);
|
||||
@@ -39,9 +42,7 @@ describe("VideoFeed", () => {
|
||||
});
|
||||
|
||||
it("Displays the room avatar when no video is available", () => {
|
||||
window.mxLegacyCallHandler = {
|
||||
roomIdForCall: jest.fn().mockReturnValue("!this:room.here"),
|
||||
} as unknown as LegacyCallHandler;
|
||||
jest.spyOn(sdkContext.legacyCallHandler, "roomIdForCall").mockReturnValue("!this:room.here");
|
||||
|
||||
const mockCall = {
|
||||
room: new Room("!room:example.com", client, client.getSafeUserId()),
|
||||
@@ -53,7 +54,10 @@ describe("VideoFeed", () => {
|
||||
addListener: jest.fn(),
|
||||
removeListener: jest.fn(),
|
||||
};
|
||||
render(<VideoFeed feed={feed as unknown as CallFeed} call={mockCall as unknown as MatrixCall} />);
|
||||
render(
|
||||
<VideoFeed feed={feed as unknown as CallFeed} call={mockCall as unknown as MatrixCall} />,
|
||||
clientAndSDKContextRenderOptions(client, sdkContext),
|
||||
);
|
||||
const avatarImg = screen.getByRole("presentation");
|
||||
expect(avatarImg).toHaveAttribute("src", FAKE_AVATAR_URL);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user