* Refer to ClientWidgetApi as "widget API" rather than "messaging" * Rename StopGapWidgetDriver to ElementWidgetDriver * Rename StopGapWidget to WidgetMessaging * Fix WidgetMessaging's lifetime by storing it in WidgetMessagingStore (Rather than storing just the raw ClientWidgetApi objects.) * Unfail test * use an error * cleanup start * Add docs * Prettier * link to store * remove a let * More logging, split up loop * Add a test demonstrating a regression in Call.start * Restore Call.start to a single, robust event loop * Fix test failure by resetting the messaging store * Expand on the WidgetMessaging doc comment * Add additional tests to buff up coverage * Add a test for the sticker picker opening the IM. * reduce copy paste --------- Co-authored-by: Half-Shot <will@half-shot.uk> Co-authored-by: Timo K <toger5@hotmail.de>
106 lines
3.7 KiB
TypeScript
106 lines
3.7 KiB
TypeScript
/*
|
|
Copyright 2024 New Vector Ltd.
|
|
Copyright 2022 The Matrix.org Foundation C.I.C.
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
|
|
Please see LICENSE files in the repository root for full details.
|
|
*/
|
|
|
|
import React from "react";
|
|
import { render, screen, act, cleanup } from "jest-matrix-react";
|
|
import { mocked, type Mocked } from "jest-mock";
|
|
import {
|
|
type MatrixClient,
|
|
PendingEventOrdering,
|
|
Room,
|
|
RoomStateEvent,
|
|
type RoomMember,
|
|
} from "matrix-js-sdk/src/matrix";
|
|
import { Widget } from "matrix-widget-api";
|
|
|
|
import {
|
|
stubClient,
|
|
mkRoomMember,
|
|
wrapInMatrixClientContext,
|
|
useMockedCalls,
|
|
MockedCall,
|
|
setupAsyncStoreWithClient,
|
|
useMockMediaDevices,
|
|
} from "../../../../test-utils";
|
|
import { MatrixClientPeg } from "../../../../../src/MatrixClientPeg";
|
|
import { CallView as _CallView } from "../../../../../src/components/views/voip/CallView";
|
|
import { WidgetMessagingStore } from "../../../../../src/stores/widgets/WidgetMessagingStore";
|
|
import { CallStore } from "../../../../../src/stores/CallStore";
|
|
import DMRoomMap from "../../../../../src/utils/DMRoomMap";
|
|
import { type WidgetMessaging } from "../../../../../src/stores/widgets/WidgetMessaging";
|
|
|
|
const CallView = wrapInMatrixClientContext(_CallView);
|
|
|
|
describe("CallView", () => {
|
|
useMockedCalls();
|
|
jest.spyOn(HTMLMediaElement.prototype, "play").mockImplementation(async () => {});
|
|
|
|
let client: Mocked<MatrixClient>;
|
|
let room: Room;
|
|
let alice: RoomMember;
|
|
let call: MockedCall;
|
|
let widget: Widget;
|
|
|
|
beforeEach(() => {
|
|
useMockMediaDevices();
|
|
|
|
stubClient();
|
|
client = mocked(MatrixClientPeg.safeGet());
|
|
DMRoomMap.makeShared(client);
|
|
|
|
room = new Room("!1:example.org", client, "@alice:example.org", {
|
|
pendingEventOrdering: PendingEventOrdering.Detached,
|
|
});
|
|
alice = mkRoomMember(room.roomId, "@alice:example.org");
|
|
jest.spyOn(room, "getMember").mockImplementation((userId) => (userId === alice.userId ? alice : null));
|
|
|
|
client.getRoom.mockImplementation((roomId) => (roomId === room.roomId ? room : null));
|
|
client.getRooms.mockReturnValue([room]);
|
|
client.reEmitter.reEmit(room, [RoomStateEvent.Events]);
|
|
|
|
setupAsyncStoreWithClient(CallStore.instance, client);
|
|
setupAsyncStoreWithClient(WidgetMessagingStore.instance, client);
|
|
|
|
MockedCall.create(room, "1");
|
|
const maybeCall = CallStore.instance.getCall(room.roomId);
|
|
if (!(maybeCall instanceof MockedCall)) throw new Error("Failed to create call");
|
|
call = maybeCall;
|
|
|
|
widget = new Widget(call.widget);
|
|
WidgetMessagingStore.instance.storeMessaging(widget, room.roomId, {
|
|
on: () => {},
|
|
off: () => {},
|
|
stop: () => {},
|
|
embedUrl: "https://example.org",
|
|
} as unknown as WidgetMessaging);
|
|
});
|
|
|
|
afterEach(() => {
|
|
cleanup(); // Unmount before we do any cleanup that might update the component
|
|
call.destroy();
|
|
WidgetMessagingStore.instance.stopMessaging(widget, room.roomId);
|
|
client.reEmitter.stopReEmitting(room, [RoomStateEvent.Events]);
|
|
});
|
|
|
|
const renderView = async (role: string | undefined = undefined): Promise<void> => {
|
|
render(<CallView room={room} resizing={false} role={role} onClose={() => {}} />);
|
|
await act(() => Promise.resolve()); // Let effects settle
|
|
};
|
|
|
|
it("accepts an accessibility role", async () => {
|
|
await renderView("main");
|
|
screen.getByRole("main");
|
|
});
|
|
|
|
it("calls clean on mount", async () => {
|
|
const cleanSpy = jest.spyOn(call, "clean");
|
|
await renderView();
|
|
expect(cleanSpy).toHaveBeenCalled();
|
|
});
|
|
});
|