2022-05-06 17:09:28 +08:00
|
|
|
/*
|
2023-08-01 15:32:53 +08:00
|
|
|
Copyright 2023 The Matrix.org Foundation C.I.C.
|
2022-05-06 17:09:28 +08:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2022-12-12 19:24:14 +08:00
|
|
|
import React from "react";
|
2023-08-31 01:55:02 +08:00
|
|
|
import { CallType, MatrixCall } from "matrix-js-sdk/src/webrtc/call";
|
2024-01-03 20:25:44 +08:00
|
|
|
import {
|
|
|
|
EventType,
|
|
|
|
JoinRule,
|
|
|
|
MatrixClient,
|
|
|
|
MatrixEvent,
|
|
|
|
PendingEventOrdering,
|
|
|
|
Room,
|
|
|
|
RoomMember,
|
|
|
|
} from "matrix-js-sdk/src/matrix";
|
2023-09-12 15:35:07 +08:00
|
|
|
import {
|
2023-11-01 20:03:10 +08:00
|
|
|
createEvent,
|
2023-09-12 15:35:07 +08:00
|
|
|
fireEvent,
|
|
|
|
getAllByLabelText,
|
|
|
|
getByLabelText,
|
2023-09-20 19:51:15 +08:00
|
|
|
getByRole,
|
2023-09-12 15:35:07 +08:00
|
|
|
getByText,
|
|
|
|
render,
|
2024-01-12 03:56:36 +08:00
|
|
|
RenderOptions,
|
2023-09-12 15:35:07 +08:00
|
|
|
screen,
|
|
|
|
waitFor,
|
|
|
|
} from "@testing-library/react";
|
2023-11-01 20:03:10 +08:00
|
|
|
import { ViewRoomOpts } from "@matrix-org/react-sdk-module-api/lib/lifecycles/RoomViewLifecycle";
|
2024-01-12 03:56:36 +08:00
|
|
|
import { TooltipProvider } from "@vector-im/compound-web";
|
2023-09-12 15:35:07 +08:00
|
|
|
|
2024-01-12 03:56:36 +08:00
|
|
|
import { filterConsole, mkEvent, stubClient } from "../../../test-utils";
|
2023-08-01 15:32:53 +08:00
|
|
|
import RoomHeader from "../../../../src/components/views/rooms/RoomHeader";
|
2023-08-02 18:54:06 +08:00
|
|
|
import DMRoomMap from "../../../../src/utils/DMRoomMap";
|
|
|
|
import { MatrixClientPeg } from "../../../../src/MatrixClientPeg";
|
|
|
|
import RightPanelStore from "../../../../src/stores/right-panel/RightPanelStore";
|
|
|
|
import { RightPanelPhases } from "../../../../src/stores/right-panel/RightPanelStorePhases";
|
2023-08-23 22:13:40 +08:00
|
|
|
import LegacyCallHandler from "../../../../src/LegacyCallHandler";
|
|
|
|
import SettingsStore from "../../../../src/settings/SettingsStore";
|
|
|
|
import SdkConfig from "../../../../src/SdkConfig";
|
|
|
|
import dispatcher from "../../../../src/dispatcher/dispatcher";
|
|
|
|
import { CallStore } from "../../../../src/stores/CallStore";
|
|
|
|
import { Call, ElementCall } from "../../../../src/models/Call";
|
2023-08-31 19:06:14 +08:00
|
|
|
import * as ShieldUtils from "../../../../src/utils/ShieldUtils";
|
2023-09-12 15:35:07 +08:00
|
|
|
import { Container, WidgetLayoutStore } from "../../../../src/stores/widgets/WidgetLayoutStore";
|
2024-01-12 03:56:36 +08:00
|
|
|
import MatrixClientContext from "../../../../src/contexts/MatrixClientContext";
|
2024-03-07 23:38:53 +08:00
|
|
|
import { _t } from "../../../../src/languageHandler";
|
2024-02-09 00:48:50 +08:00
|
|
|
import * as UseCall from "../../../../src/hooks/useCall";
|
|
|
|
import { SdkContextClass } from "../../../../src/contexts/SDKContext";
|
|
|
|
import WidgetStore, { IApp } from "../../../../src/stores/WidgetStore";
|
2024-03-07 23:38:53 +08:00
|
|
|
import ShareDialog from "../../../../src/components/views/dialogs/ShareDialog";
|
|
|
|
import Modal from "../../../../src/Modal";
|
2023-08-31 19:06:14 +08:00
|
|
|
jest.mock("../../../../src/utils/ShieldUtils");
|
2023-06-09 20:33:54 +08:00
|
|
|
|
2024-01-12 03:56:36 +08:00
|
|
|
function getWrapper(): RenderOptions {
|
|
|
|
return {
|
|
|
|
wrapper: ({ children }) => (
|
|
|
|
<TooltipProvider>
|
|
|
|
<MatrixClientContext.Provider value={MatrixClientPeg.safeGet()}>
|
|
|
|
{children}
|
|
|
|
</MatrixClientContext.Provider>
|
|
|
|
</TooltipProvider>
|
|
|
|
),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-08-31 01:55:02 +08:00
|
|
|
describe("RoomHeader", () => {
|
2023-11-16 11:25:34 +08:00
|
|
|
filterConsole(
|
|
|
|
"[getType] Room !1:example.org does not have an m.room.create event",
|
|
|
|
"Age for event was not available, using `now - origin_server_ts` as a fallback. If the device clock is not correct issues might occur.",
|
|
|
|
);
|
2023-09-12 15:35:07 +08:00
|
|
|
|
2022-09-25 22:57:25 +08:00
|
|
|
let room: Room;
|
|
|
|
|
2023-08-01 15:32:53 +08:00
|
|
|
const ROOM_ID = "!1:example.org";
|
2022-09-25 22:57:25 +08:00
|
|
|
|
2023-08-02 18:54:06 +08:00
|
|
|
let setCardSpy: jest.SpyInstance | undefined;
|
|
|
|
|
2023-08-01 15:32:53 +08:00
|
|
|
beforeEach(async () => {
|
2022-09-25 22:57:25 +08:00
|
|
|
stubClient();
|
2023-08-02 18:54:06 +08:00
|
|
|
room = new Room(ROOM_ID, MatrixClientPeg.get()!, "@alice:example.org", {
|
|
|
|
pendingEventOrdering: PendingEventOrdering.Detached,
|
|
|
|
});
|
|
|
|
DMRoomMap.setShared({
|
|
|
|
getUserIdForRoomId: jest.fn(),
|
|
|
|
} as unknown as DMRoomMap);
|
|
|
|
|
|
|
|
setCardSpy = jest.spyOn(RightPanelStore.instance, "setCard");
|
2023-02-28 16:58:23 +08:00
|
|
|
});
|
|
|
|
|
2023-08-23 22:13:40 +08:00
|
|
|
afterEach(() => {
|
2023-09-08 00:34:52 +08:00
|
|
|
jest.restoreAllMocks();
|
2023-08-23 22:13:40 +08:00
|
|
|
});
|
|
|
|
|
2023-08-01 15:32:53 +08:00
|
|
|
it("renders the room header", () => {
|
2024-01-12 03:56:36 +08:00
|
|
|
const { container } = render(<RoomHeader room={room} />, getWrapper());
|
2023-08-01 15:32:53 +08:00
|
|
|
expect(container).toHaveTextContent(ROOM_ID);
|
2023-02-28 16:58:23 +08:00
|
|
|
});
|
2023-08-01 21:47:09 +08:00
|
|
|
|
2023-08-02 18:54:06 +08:00
|
|
|
it("renders the room topic", async () => {
|
2023-09-20 19:51:15 +08:00
|
|
|
const TOPIC = "Hello World! http://element.io";
|
2023-08-02 18:54:06 +08:00
|
|
|
|
|
|
|
const roomTopic = new MatrixEvent({
|
|
|
|
type: EventType.RoomTopic,
|
|
|
|
event_id: "$00002",
|
|
|
|
room_id: room.roomId,
|
|
|
|
sender: "@alice:example.com",
|
|
|
|
origin_server_ts: 1,
|
|
|
|
content: { topic: TOPIC },
|
|
|
|
state_key: "",
|
|
|
|
});
|
|
|
|
await room.addLiveEvents([roomTopic]);
|
|
|
|
|
2024-01-12 03:56:36 +08:00
|
|
|
const { container } = render(<RoomHeader room={room} />, getWrapper());
|
2023-08-02 18:54:06 +08:00
|
|
|
expect(container).toHaveTextContent(TOPIC);
|
2023-09-20 19:51:15 +08:00
|
|
|
expect(getByRole(container, "link")).toHaveTextContent("http://element.io");
|
2023-08-02 18:54:06 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it("opens the room summary", async () => {
|
2024-01-12 03:56:36 +08:00
|
|
|
const { container } = render(<RoomHeader room={room} />, getWrapper());
|
2023-08-02 18:54:06 +08:00
|
|
|
|
2023-09-12 15:35:07 +08:00
|
|
|
fireEvent.click(getByText(container, ROOM_ID));
|
2023-08-02 18:54:06 +08:00
|
|
|
expect(setCardSpy).toHaveBeenCalledWith({ phase: RightPanelPhases.RoomSummary });
|
|
|
|
});
|
2023-08-23 22:13:40 +08:00
|
|
|
|
2023-08-31 01:55:02 +08:00
|
|
|
it("does not show the face pile for DMs", () => {
|
|
|
|
const client = MatrixClientPeg.get()!;
|
|
|
|
|
|
|
|
jest.spyOn(client, "getAccountData").mockReturnValue(
|
|
|
|
mkEvent({
|
|
|
|
event: true,
|
|
|
|
type: EventType.Direct,
|
|
|
|
user: client.getSafeUserId(),
|
|
|
|
content: {
|
|
|
|
"user@example.com": [room.roomId],
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
|
|
|
|
room.getJoinedMembers = jest.fn().mockReturnValue([
|
|
|
|
{
|
|
|
|
userId: "@me:example.org",
|
|
|
|
name: "Member",
|
|
|
|
rawDisplayName: "Member",
|
|
|
|
roomId: room.roomId,
|
|
|
|
membership: "join",
|
|
|
|
getAvatarUrl: () => "mxc://avatar.url/image.png",
|
|
|
|
getMxcAvatarUrl: () => "mxc://avatar.url/image.png",
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
|
2024-01-12 03:56:36 +08:00
|
|
|
const { asFragment } = render(<RoomHeader room={room} />, getWrapper());
|
2023-08-31 01:55:02 +08:00
|
|
|
|
|
|
|
expect(asFragment()).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("shows a face pile for rooms", async () => {
|
|
|
|
const members = [
|
|
|
|
{
|
|
|
|
userId: "@me:example.org",
|
|
|
|
name: "Member",
|
|
|
|
rawDisplayName: "Member",
|
|
|
|
roomId: room.roomId,
|
|
|
|
membership: "join",
|
|
|
|
getAvatarUrl: () => "mxc://avatar.url/image.png",
|
|
|
|
getMxcAvatarUrl: () => "mxc://avatar.url/image.png",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
userId: "@you:example.org",
|
|
|
|
name: "Member",
|
|
|
|
rawDisplayName: "Member",
|
|
|
|
roomId: room.roomId,
|
|
|
|
membership: "join",
|
|
|
|
getAvatarUrl: () => "mxc://avatar.url/image.png",
|
|
|
|
getMxcAvatarUrl: () => "mxc://avatar.url/image.png",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
userId: "@them:example.org",
|
|
|
|
name: "Member",
|
|
|
|
rawDisplayName: "Member",
|
|
|
|
roomId: room.roomId,
|
|
|
|
membership: "join",
|
|
|
|
getAvatarUrl: () => "mxc://avatar.url/image.png",
|
|
|
|
getMxcAvatarUrl: () => "mxc://avatar.url/image.png",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
userId: "@bot:example.org",
|
|
|
|
name: "Bot user",
|
|
|
|
rawDisplayName: "Bot user",
|
|
|
|
roomId: room.roomId,
|
|
|
|
membership: "join",
|
|
|
|
getAvatarUrl: () => "mxc://avatar.url/image.png",
|
|
|
|
getMxcAvatarUrl: () => "mxc://avatar.url/image.png",
|
|
|
|
},
|
|
|
|
];
|
|
|
|
room.currentState.setJoinedMemberCount(members.length);
|
|
|
|
room.getJoinedMembers = jest.fn().mockReturnValue(members);
|
|
|
|
|
2024-01-12 03:56:36 +08:00
|
|
|
const { container } = render(<RoomHeader room={room} />, getWrapper());
|
2023-08-31 01:55:02 +08:00
|
|
|
|
|
|
|
expect(container).toHaveTextContent("4");
|
|
|
|
|
|
|
|
const facePile = getByLabelText(container, "4 members");
|
|
|
|
expect(facePile).toHaveTextContent("4");
|
|
|
|
|
2023-09-12 15:35:07 +08:00
|
|
|
fireEvent.click(facePile);
|
2023-08-31 01:55:02 +08:00
|
|
|
|
|
|
|
expect(setCardSpy).toHaveBeenCalledWith({ phase: RightPanelPhases.RoomMemberList });
|
|
|
|
});
|
|
|
|
|
2023-08-23 22:13:40 +08:00
|
|
|
it("opens the thread panel", async () => {
|
2024-01-12 03:56:36 +08:00
|
|
|
const { container } = render(<RoomHeader room={room} />, getWrapper());
|
2023-08-23 22:13:40 +08:00
|
|
|
|
2023-09-12 15:35:07 +08:00
|
|
|
fireEvent.click(getByLabelText(container, "Threads"));
|
2023-08-23 22:13:40 +08:00
|
|
|
expect(setCardSpy).toHaveBeenCalledWith({ phase: RightPanelPhases.ThreadPanel });
|
|
|
|
});
|
|
|
|
|
|
|
|
it("opens the notifications panel", async () => {
|
2023-09-01 04:57:45 +08:00
|
|
|
jest.spyOn(SettingsStore, "getValue").mockImplementation((name: string) => {
|
|
|
|
if (name === "feature_notifications") return true;
|
|
|
|
});
|
|
|
|
|
2024-01-12 03:56:36 +08:00
|
|
|
const { container } = render(<RoomHeader room={room} />, getWrapper());
|
2023-08-23 22:13:40 +08:00
|
|
|
|
2023-09-12 15:35:07 +08:00
|
|
|
fireEvent.click(getByLabelText(container, "Notifications"));
|
2023-08-23 22:13:40 +08:00
|
|
|
expect(setCardSpy).toHaveBeenCalledWith({ phase: RightPanelPhases.NotificationPanel });
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("groups call disabled", () => {
|
|
|
|
it("you can't call if you're alone", () => {
|
|
|
|
mockRoomMembers(room, 1);
|
2024-01-12 03:56:36 +08:00
|
|
|
const { container } = render(<RoomHeader room={room} />, getWrapper());
|
2023-09-12 00:55:32 +08:00
|
|
|
for (const button of getAllByLabelText(container, "There's no one here to call")) {
|
2023-12-14 19:10:01 +08:00
|
|
|
expect(button).toHaveAttribute("aria-disabled", "true");
|
2023-08-23 22:13:40 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
it("you can call when you're two in the room", async () => {
|
|
|
|
mockRoomMembers(room, 2);
|
2024-01-12 03:56:36 +08:00
|
|
|
const { container } = render(<RoomHeader room={room} />, getWrapper());
|
2023-09-12 00:55:32 +08:00
|
|
|
const voiceButton = getByLabelText(container, "Voice call");
|
|
|
|
const videoButton = getByLabelText(container, "Video call");
|
2023-12-14 19:10:01 +08:00
|
|
|
expect(voiceButton).not.toHaveAttribute("aria-disabled", "true");
|
|
|
|
expect(videoButton).not.toHaveAttribute("aria-disabled", "true");
|
2023-08-23 22:13:40 +08:00
|
|
|
|
|
|
|
const placeCallSpy = jest.spyOn(LegacyCallHandler.instance, "placeCall");
|
|
|
|
|
2023-09-12 15:35:07 +08:00
|
|
|
fireEvent.click(voiceButton);
|
2023-08-23 22:13:40 +08:00
|
|
|
expect(placeCallSpy).toHaveBeenLastCalledWith(room.roomId, CallType.Voice);
|
|
|
|
|
2023-09-12 15:35:07 +08:00
|
|
|
fireEvent.click(videoButton);
|
2023-08-23 22:13:40 +08:00
|
|
|
expect(placeCallSpy).toHaveBeenLastCalledWith(room.roomId, CallType.Video);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("you can't call if there's already a call", () => {
|
|
|
|
mockRoomMembers(room, 2);
|
|
|
|
jest.spyOn(LegacyCallHandler.instance, "getCallForRoom").mockReturnValue(
|
|
|
|
// The JS-SDK does not export the class `MatrixCall` only the type
|
|
|
|
{} as MatrixCall,
|
|
|
|
);
|
2024-01-12 03:56:36 +08:00
|
|
|
const { container } = render(<RoomHeader room={room} />, getWrapper());
|
2023-09-12 00:55:32 +08:00
|
|
|
for (const button of getAllByLabelText(container, "Ongoing call")) {
|
2023-12-14 19:10:01 +08:00
|
|
|
expect(button).toHaveAttribute("aria-disabled", "true");
|
2023-08-23 22:13:40 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
it("can calls in large rooms if able to edit widgets", () => {
|
|
|
|
mockRoomMembers(room, 10);
|
|
|
|
jest.spyOn(room.currentState, "mayClientSendStateEvent").mockReturnValue(true);
|
2024-01-12 03:56:36 +08:00
|
|
|
const { container } = render(<RoomHeader room={room} />, getWrapper());
|
2023-08-23 22:13:40 +08:00
|
|
|
|
2023-12-14 19:10:01 +08:00
|
|
|
expect(getByLabelText(container, "Voice call")).not.toHaveAttribute("aria-disabled", "true");
|
|
|
|
expect(getByLabelText(container, "Video call")).not.toHaveAttribute("aria-disabled", "true");
|
2023-08-23 22:13:40 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it("disable calls in large rooms by default", () => {
|
|
|
|
mockRoomMembers(room, 10);
|
|
|
|
jest.spyOn(room.currentState, "mayClientSendStateEvent").mockReturnValue(false);
|
2024-01-12 03:56:36 +08:00
|
|
|
const { container } = render(<RoomHeader room={room} />, getWrapper());
|
2023-09-12 15:35:07 +08:00
|
|
|
expect(
|
|
|
|
getByLabelText(container, "You do not have permission to start voice calls", { selector: "button" }),
|
2023-12-14 19:10:01 +08:00
|
|
|
).toHaveAttribute("aria-disabled", "true");
|
2023-09-12 15:35:07 +08:00
|
|
|
expect(
|
|
|
|
getByLabelText(container, "You do not have permission to start video calls", { selector: "button" }),
|
2023-12-14 19:10:01 +08:00
|
|
|
).toHaveAttribute("aria-disabled", "true");
|
2023-08-23 22:13:40 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("group call enabled", () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
jest.spyOn(SettingsStore, "getValue").mockImplementation((feature) => feature === "feature_group_calls");
|
|
|
|
});
|
|
|
|
|
|
|
|
it("renders only the video call element", async () => {
|
2023-09-12 15:35:07 +08:00
|
|
|
mockRoomMembers(room, 3);
|
2023-08-23 22:13:40 +08:00
|
|
|
jest.spyOn(SdkConfig, "get").mockReturnValue({ use_exclusively: true });
|
|
|
|
// allow element calls
|
|
|
|
jest.spyOn(room.currentState, "mayClientSendStateEvent").mockReturnValue(true);
|
|
|
|
|
2024-01-12 03:56:36 +08:00
|
|
|
const { container } = render(<RoomHeader room={room} />, getWrapper());
|
2023-08-23 22:13:40 +08:00
|
|
|
|
|
|
|
expect(screen.queryByTitle("Voice call")).toBeNull();
|
|
|
|
|
2023-09-12 00:55:32 +08:00
|
|
|
const videoCallButton = getByLabelText(container, "Video call");
|
2023-12-14 19:10:01 +08:00
|
|
|
expect(videoCallButton).not.toHaveAttribute("aria-disabled", "true");
|
2023-08-23 22:13:40 +08:00
|
|
|
|
|
|
|
const dispatcherSpy = jest.spyOn(dispatcher, "dispatch");
|
|
|
|
|
2023-09-12 15:35:07 +08:00
|
|
|
fireEvent.click(getByLabelText(container, "Video call"));
|
2023-08-23 22:13:40 +08:00
|
|
|
|
|
|
|
expect(dispatcherSpy).toHaveBeenCalledWith(expect.objectContaining({ view_call: true }));
|
|
|
|
});
|
|
|
|
|
2023-09-12 15:35:07 +08:00
|
|
|
it("can't call if there's an ongoing (pinned) call", () => {
|
2023-08-23 22:13:40 +08:00
|
|
|
jest.spyOn(SdkConfig, "get").mockReturnValue({ use_exclusively: true });
|
|
|
|
// allow element calls
|
|
|
|
jest.spyOn(room.currentState, "mayClientSendStateEvent").mockReturnValue(true);
|
2023-09-12 15:35:07 +08:00
|
|
|
jest.spyOn(WidgetLayoutStore.instance, "isInContainer").mockReturnValue(true);
|
2024-02-09 00:48:50 +08:00
|
|
|
const widget = { type: "m.jitsi" } as IApp;
|
|
|
|
jest.spyOn(CallStore.instance, "getCall").mockReturnValue({
|
|
|
|
widget,
|
|
|
|
on: () => {},
|
|
|
|
} as unknown as Call);
|
|
|
|
jest.spyOn(WidgetStore.instance, "getApps").mockReturnValue([widget]);
|
2024-01-12 03:56:36 +08:00
|
|
|
const { container } = render(<RoomHeader room={room} />, getWrapper());
|
2023-12-14 19:10:01 +08:00
|
|
|
expect(getByLabelText(container, "Ongoing call")).toHaveAttribute("aria-disabled", "true");
|
2023-08-23 22:13:40 +08:00
|
|
|
});
|
|
|
|
|
2023-09-12 15:35:07 +08:00
|
|
|
it("clicking on ongoing (unpinned) call re-pins it", () => {
|
2024-02-09 00:48:50 +08:00
|
|
|
mockRoomMembers(room, 3);
|
|
|
|
jest.spyOn(SettingsStore, "getValue").mockReturnValue(false);
|
2024-01-30 00:06:12 +08:00
|
|
|
// allow calls
|
2023-09-12 15:35:07 +08:00
|
|
|
jest.spyOn(room.currentState, "mayClientSendStateEvent").mockReturnValue(true);
|
|
|
|
jest.spyOn(WidgetLayoutStore.instance, "isInContainer").mockReturnValue(false);
|
|
|
|
const spy = jest.spyOn(WidgetLayoutStore.instance, "moveToContainer");
|
|
|
|
|
2024-02-09 00:48:50 +08:00
|
|
|
const widget = { type: "m.jitsi" } as IApp;
|
2024-01-31 23:18:52 +08:00
|
|
|
jest.spyOn(CallStore.instance, "getCall").mockReturnValue({
|
|
|
|
widget,
|
|
|
|
on: () => {},
|
|
|
|
} as unknown as Call);
|
2024-02-09 00:48:50 +08:00
|
|
|
jest.spyOn(WidgetStore.instance, "getApps").mockReturnValue([widget]);
|
2023-09-12 15:35:07 +08:00
|
|
|
|
2024-01-12 03:56:36 +08:00
|
|
|
const { container } = render(<RoomHeader room={room} />, getWrapper());
|
2023-12-14 19:10:01 +08:00
|
|
|
expect(getByLabelText(container, "Video call")).not.toHaveAttribute("aria-disabled", "true");
|
2023-09-12 15:35:07 +08:00
|
|
|
fireEvent.click(getByLabelText(container, "Video call"));
|
|
|
|
expect(spy).toHaveBeenCalledWith(room, widget, Container.Top);
|
|
|
|
});
|
|
|
|
|
2023-08-23 22:13:40 +08:00
|
|
|
it("disables calling if there's a jitsi call", () => {
|
|
|
|
mockRoomMembers(room, 2);
|
|
|
|
jest.spyOn(LegacyCallHandler.instance, "getCallForRoom").mockReturnValue(
|
|
|
|
// The JS-SDK does not export the class `MatrixCall` only the type
|
|
|
|
{} as MatrixCall,
|
|
|
|
);
|
2024-01-12 03:56:36 +08:00
|
|
|
const { container } = render(<RoomHeader room={room} />, getWrapper());
|
2023-09-12 00:55:32 +08:00
|
|
|
for (const button of getAllByLabelText(container, "Ongoing call")) {
|
2023-12-14 19:10:01 +08:00
|
|
|
expect(button).toHaveAttribute("aria-disabled", "true");
|
2023-08-23 22:13:40 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
it("can't call if you have no friends", () => {
|
|
|
|
mockRoomMembers(room, 1);
|
2024-01-12 03:56:36 +08:00
|
|
|
const { container } = render(<RoomHeader room={room} />, getWrapper());
|
2023-09-12 00:55:32 +08:00
|
|
|
for (const button of getAllByLabelText(container, "There's no one here to call")) {
|
2023-12-14 19:10:01 +08:00
|
|
|
expect(button).toHaveAttribute("aria-disabled", "true");
|
2023-08-23 22:13:40 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
it("calls using legacy or jitsi", async () => {
|
|
|
|
mockRoomMembers(room, 2);
|
2024-01-31 23:18:52 +08:00
|
|
|
jest.spyOn(room.currentState, "mayClientSendStateEvent").mockImplementation((key) => {
|
|
|
|
if (key === "im.vector.modular.widgets") return true;
|
|
|
|
return false;
|
|
|
|
});
|
2024-01-12 03:56:36 +08:00
|
|
|
const { container } = render(<RoomHeader room={room} />, getWrapper());
|
2023-08-23 22:13:40 +08:00
|
|
|
|
2023-09-12 00:55:32 +08:00
|
|
|
const voiceButton = getByLabelText(container, "Voice call");
|
|
|
|
const videoButton = getByLabelText(container, "Video call");
|
2023-12-14 19:10:01 +08:00
|
|
|
expect(voiceButton).not.toHaveAttribute("aria-disabled", "true");
|
|
|
|
expect(videoButton).not.toHaveAttribute("aria-disabled", "true");
|
2023-08-23 22:13:40 +08:00
|
|
|
|
|
|
|
const placeCallSpy = jest.spyOn(LegacyCallHandler.instance, "placeCall");
|
2023-09-12 15:35:07 +08:00
|
|
|
fireEvent.click(voiceButton);
|
2023-08-23 22:13:40 +08:00
|
|
|
expect(placeCallSpy).toHaveBeenLastCalledWith(room.roomId, CallType.Voice);
|
|
|
|
|
2023-09-12 15:35:07 +08:00
|
|
|
fireEvent.click(videoButton);
|
2023-08-23 22:13:40 +08:00
|
|
|
expect(placeCallSpy).toHaveBeenLastCalledWith(room.roomId, CallType.Video);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("calls using legacy or jitsi for large rooms", async () => {
|
|
|
|
mockRoomMembers(room, 3);
|
|
|
|
|
|
|
|
jest.spyOn(room.currentState, "mayClientSendStateEvent").mockImplementation((key) => {
|
|
|
|
if (key === "im.vector.modular.widgets") return true;
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2024-01-12 03:56:36 +08:00
|
|
|
const { container } = render(<RoomHeader room={room} />, getWrapper());
|
2023-08-23 22:13:40 +08:00
|
|
|
|
2023-09-12 00:55:32 +08:00
|
|
|
const voiceButton = getByLabelText(container, "Voice call");
|
|
|
|
const videoButton = getByLabelText(container, "Video call");
|
2023-12-14 19:10:01 +08:00
|
|
|
expect(voiceButton).not.toHaveAttribute("aria-disabled", "true");
|
|
|
|
expect(videoButton).not.toHaveAttribute("aria-disabled", "true");
|
2023-08-23 22:13:40 +08:00
|
|
|
|
|
|
|
const placeCallSpy = jest.spyOn(LegacyCallHandler.instance, "placeCall");
|
2023-09-12 15:35:07 +08:00
|
|
|
fireEvent.click(voiceButton);
|
2023-08-23 22:13:40 +08:00
|
|
|
expect(placeCallSpy).toHaveBeenLastCalledWith(room.roomId, CallType.Voice);
|
|
|
|
|
2023-09-12 15:35:07 +08:00
|
|
|
fireEvent.click(videoButton);
|
2023-08-23 22:13:40 +08:00
|
|
|
expect(placeCallSpy).toHaveBeenLastCalledWith(room.roomId, CallType.Video);
|
|
|
|
});
|
|
|
|
|
2024-01-30 00:06:12 +08:00
|
|
|
it("calls using element call for large rooms", async () => {
|
2023-08-23 22:13:40 +08:00
|
|
|
mockRoomMembers(room, 3);
|
|
|
|
|
|
|
|
jest.spyOn(room.currentState, "mayClientSendStateEvent").mockImplementation((key) => {
|
2024-01-31 23:18:52 +08:00
|
|
|
if (key === ElementCall.MEMBER_EVENT_TYPE.name) return true;
|
2023-08-23 22:13:40 +08:00
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2024-01-12 03:56:36 +08:00
|
|
|
const { container } = render(<RoomHeader room={room} />, getWrapper());
|
2023-08-23 22:13:40 +08:00
|
|
|
|
2023-09-12 00:55:32 +08:00
|
|
|
const voiceButton = getByLabelText(container, "Voice call");
|
|
|
|
const videoButton = getByLabelText(container, "Video call");
|
2023-12-14 19:10:01 +08:00
|
|
|
expect(voiceButton).not.toHaveAttribute("aria-disabled", "true");
|
|
|
|
expect(videoButton).not.toHaveAttribute("aria-disabled", "true");
|
2023-08-23 22:13:40 +08:00
|
|
|
|
|
|
|
const dispatcherSpy = jest.spyOn(dispatcher, "dispatch");
|
2023-09-12 15:35:07 +08:00
|
|
|
fireEvent.click(videoButton);
|
2023-08-23 22:13:40 +08:00
|
|
|
expect(dispatcherSpy).toHaveBeenCalledWith(expect.objectContaining({ view_call: true }));
|
|
|
|
});
|
2024-02-09 00:48:50 +08:00
|
|
|
|
|
|
|
it("buttons are disabled if there is an ongoing call", async () => {
|
|
|
|
mockRoomMembers(room, 3);
|
|
|
|
|
|
|
|
jest.spyOn(CallStore.prototype, "activeCalls", "get").mockReturnValue(
|
|
|
|
new Set([{ roomId: "some_other_room" } as Call]),
|
|
|
|
);
|
|
|
|
const { container } = render(<RoomHeader room={room} />, getWrapper());
|
|
|
|
|
|
|
|
const [videoButton, voiceButton] = getAllByLabelText(container, "Ongoing call");
|
|
|
|
|
|
|
|
expect(voiceButton).toHaveAttribute("aria-disabled", "true");
|
|
|
|
expect(videoButton).toHaveAttribute("aria-disabled", "true");
|
|
|
|
});
|
|
|
|
|
|
|
|
it("join button is shown if there is an ongoing call", async () => {
|
|
|
|
mockRoomMembers(room, 3);
|
|
|
|
jest.spyOn(UseCall, "useParticipantCount").mockReturnValue(3);
|
|
|
|
const { container } = render(<RoomHeader room={room} />, getWrapper());
|
|
|
|
const joinButton = getByLabelText(container, "Join");
|
|
|
|
expect(joinButton).not.toHaveAttribute("aria-disabled", "true");
|
|
|
|
});
|
|
|
|
|
|
|
|
it("join button is disabled if there is an other ongoing call", async () => {
|
|
|
|
mockRoomMembers(room, 3);
|
|
|
|
jest.spyOn(UseCall, "useParticipantCount").mockReturnValue(3);
|
|
|
|
jest.spyOn(CallStore.prototype, "activeCalls", "get").mockReturnValue(
|
|
|
|
new Set([{ roomId: "some_other_room" } as Call]),
|
|
|
|
);
|
|
|
|
const { container } = render(<RoomHeader room={room} />, getWrapper());
|
|
|
|
const joinButton = getByLabelText(container, "Ongoing call");
|
|
|
|
|
|
|
|
expect(joinButton).toHaveAttribute("aria-disabled", "true");
|
|
|
|
});
|
|
|
|
|
|
|
|
it("close lobby button is shown", async () => {
|
|
|
|
mockRoomMembers(room, 3);
|
|
|
|
|
|
|
|
jest.spyOn(SdkContextClass.instance.roomViewStore, "isViewingCall").mockReturnValue(true);
|
|
|
|
const { container } = render(<RoomHeader room={room} />, getWrapper());
|
|
|
|
getByLabelText(container, "Close lobby");
|
|
|
|
});
|
|
|
|
|
|
|
|
it("close lobby button is shown if there is an ongoing call but we are viewing the lobby", async () => {
|
|
|
|
mockRoomMembers(room, 3);
|
|
|
|
jest.spyOn(UseCall, "useParticipantCount").mockReturnValue(3);
|
|
|
|
jest.spyOn(SdkContextClass.instance.roomViewStore, "isViewingCall").mockReturnValue(true);
|
|
|
|
|
|
|
|
const { container } = render(<RoomHeader room={room} />, getWrapper());
|
|
|
|
getByLabelText(container, "Close lobby");
|
|
|
|
});
|
2023-08-23 22:13:40 +08:00
|
|
|
});
|
2023-08-31 19:06:14 +08:00
|
|
|
|
2024-03-07 23:38:53 +08:00
|
|
|
describe("External conference", () => {
|
|
|
|
const oldGet = SdkConfig.get;
|
|
|
|
beforeEach(() => {
|
|
|
|
jest.spyOn(SdkConfig, "get").mockImplementation((key) => {
|
|
|
|
if (key === "element_call") {
|
|
|
|
return { guest_spa_url: "https://guest_spa_url.com", url: "https://spa_url.com" };
|
|
|
|
}
|
|
|
|
return oldGet(key);
|
|
|
|
});
|
|
|
|
mockRoomMembers(room, 3);
|
|
|
|
jest.spyOn(SdkContextClass.instance.roomViewStore, "isViewingCall").mockReturnValue(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("shows the external conference if the room has public join rules", () => {
|
|
|
|
jest.spyOn(room, "getJoinRule").mockReturnValue(JoinRule.Public);
|
|
|
|
|
|
|
|
const { container } = render(<RoomHeader room={room} />, getWrapper());
|
|
|
|
expect(getByLabelText(container, _t("voip|get_call_link"))).toBeInTheDocument();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("shows the external conference if the room has Knock join rules", () => {
|
|
|
|
jest.spyOn(room, "getJoinRule").mockReturnValue(JoinRule.Knock);
|
|
|
|
|
|
|
|
const { container } = render(<RoomHeader room={room} />, getWrapper());
|
|
|
|
expect(getByLabelText(container, _t("voip|get_call_link"))).toBeInTheDocument();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("don't show external conference button if the call is not shown", () => {
|
|
|
|
jest.spyOn(room, "getJoinRule").mockReturnValue(JoinRule.Public);
|
|
|
|
jest.spyOn(SdkContextClass.instance.roomViewStore, "isViewingCall").mockReturnValue(false);
|
|
|
|
|
|
|
|
let { container } = render(<RoomHeader room={room} />, getWrapper());
|
|
|
|
expect(screen.queryByLabelText(_t("voip|get_call_link"))).not.toBeInTheDocument();
|
|
|
|
|
|
|
|
jest.spyOn(SdkContextClass.instance.roomViewStore, "isViewingCall").mockReturnValue(true);
|
|
|
|
|
|
|
|
container = render(<RoomHeader room={room} />, getWrapper()).container;
|
|
|
|
|
|
|
|
expect(getByLabelText(container, _t("voip|get_call_link"))).toBeInTheDocument();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("don't show external conference button if now guest spa link is configured", () => {
|
|
|
|
jest.spyOn(room, "getJoinRule").mockReturnValue(JoinRule.Public);
|
|
|
|
jest.spyOn(SdkContextClass.instance.roomViewStore, "isViewingCall").mockReturnValue(true);
|
|
|
|
|
|
|
|
jest.spyOn(SdkConfig, "get").mockImplementation((key) => {
|
|
|
|
if (key === "element_call") {
|
|
|
|
return { url: "https://example2.com" };
|
|
|
|
}
|
|
|
|
return oldGet(key);
|
|
|
|
});
|
|
|
|
|
|
|
|
render(<RoomHeader room={room} />, getWrapper());
|
|
|
|
|
|
|
|
// We only change the SdkConfig and show that this everything else is
|
|
|
|
// configured so that the call link button is shown.
|
|
|
|
|
|
|
|
jest.spyOn(SdkConfig, "get").mockImplementation((key) => {
|
|
|
|
if (key === "element_call") {
|
|
|
|
return { guest_spa_url: "https://guest_spa_url.com", url: "https://example2.com" };
|
|
|
|
}
|
|
|
|
return oldGet(key);
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(screen.queryByLabelText(_t("voip|get_call_link"))).not.toBeInTheDocument();
|
|
|
|
const { container } = render(<RoomHeader room={room} />, getWrapper());
|
|
|
|
expect(getByLabelText(container, _t("voip|get_call_link"))).toBeInTheDocument();
|
|
|
|
});
|
|
|
|
it("opens the share dialog with the correct share link", () => {
|
|
|
|
jest.spyOn(room, "getJoinRule").mockReturnValue(JoinRule.Public);
|
|
|
|
jest.spyOn(SdkContextClass.instance.roomViewStore, "isViewingCall").mockReturnValue(true);
|
|
|
|
|
|
|
|
const { container } = render(<RoomHeader room={room} />, getWrapper());
|
|
|
|
const modalSpy = jest.spyOn(Modal, "createDialog");
|
|
|
|
fireEvent.click(getByLabelText(container, _t("voip|get_call_link")));
|
|
|
|
const target =
|
|
|
|
"https://guest_spa_url.com/room/#/!1:example.org?roomId=%211%3Aexample.org&perParticipantE2EE=true&viaServers=example.org";
|
|
|
|
expect(modalSpy).toHaveBeenCalled();
|
|
|
|
const arg0 = modalSpy.mock.calls[0][0];
|
|
|
|
const arg1 = modalSpy.mock.calls[0][1] as any;
|
|
|
|
expect(arg0).toEqual(ShareDialog);
|
|
|
|
const { customTitle, subtitle } = arg1;
|
|
|
|
expect({ customTitle, subtitle }).toEqual({
|
|
|
|
customTitle: "Conference invite link",
|
|
|
|
subtitle: _t("share|share_call_subtitle"),
|
|
|
|
});
|
|
|
|
expect(arg1.target.toString()).toEqual(target);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2023-09-01 17:45:50 +08:00
|
|
|
describe("public room", () => {
|
|
|
|
it("shows a globe", () => {
|
|
|
|
const joinRuleEvent = new MatrixEvent({
|
|
|
|
type: EventType.RoomJoinRules,
|
|
|
|
content: { join_rule: JoinRule.Public },
|
|
|
|
sender: MatrixClientPeg.get()!.getSafeUserId(),
|
|
|
|
state_key: "",
|
|
|
|
room_id: room.roomId,
|
|
|
|
});
|
|
|
|
room.addLiveEvents([joinRuleEvent]);
|
|
|
|
|
2024-01-12 03:56:36 +08:00
|
|
|
const { container } = render(<RoomHeader room={room} />, getWrapper());
|
2023-09-01 17:45:50 +08:00
|
|
|
|
|
|
|
expect(getByLabelText(container, "Public room")).toBeInTheDocument();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2023-08-31 19:06:14 +08:00
|
|
|
describe("dm", () => {
|
|
|
|
let client: MatrixClient;
|
|
|
|
beforeEach(() => {
|
|
|
|
client = MatrixClientPeg.get()!;
|
|
|
|
|
|
|
|
// Make the mocked room a DM
|
|
|
|
jest.spyOn(client, "getAccountData").mockImplementation((eventType: string): MatrixEvent | undefined => {
|
|
|
|
if (eventType === EventType.Direct) {
|
|
|
|
return mkEvent({
|
|
|
|
event: true,
|
|
|
|
content: {
|
|
|
|
[client.getUserId()!]: [room.roomId],
|
|
|
|
},
|
|
|
|
type: EventType.Direct,
|
|
|
|
user: client.getSafeUserId(),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return undefined;
|
|
|
|
});
|
|
|
|
jest.spyOn(client, "isCryptoEnabled").mockReturnValue(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it.each([
|
|
|
|
[ShieldUtils.E2EStatus.Verified, "Verified"],
|
|
|
|
[ShieldUtils.E2EStatus.Warning, "Untrusted"],
|
|
|
|
])("shows the %s icon", async (value: ShieldUtils.E2EStatus, expectedLabel: string) => {
|
|
|
|
jest.spyOn(ShieldUtils, "shieldStatusForRoom").mockResolvedValue(value);
|
|
|
|
|
2024-01-12 03:56:36 +08:00
|
|
|
const { container } = render(<RoomHeader room={room} />, getWrapper());
|
2023-08-31 19:06:14 +08:00
|
|
|
|
|
|
|
await waitFor(() => expect(getByLabelText(container, expectedLabel)).toBeInTheDocument());
|
|
|
|
});
|
|
|
|
});
|
2023-11-01 20:03:10 +08:00
|
|
|
|
|
|
|
it("renders additionalButtons", async () => {
|
|
|
|
const additionalButtons: ViewRoomOpts["buttons"] = [
|
|
|
|
{
|
2023-11-09 19:23:30 +08:00
|
|
|
icon: () => <>test-icon</>,
|
2023-11-01 20:03:10 +08:00
|
|
|
id: "test-id",
|
|
|
|
label: () => "test-label",
|
|
|
|
onClick: () => {},
|
|
|
|
},
|
|
|
|
];
|
2024-01-12 03:56:36 +08:00
|
|
|
render(<RoomHeader room={room} additionalButtons={additionalButtons} />, getWrapper());
|
2023-11-01 20:03:10 +08:00
|
|
|
expect(screen.getByRole("button", { name: "test-label" })).toBeInTheDocument();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("calls onClick-callback on additionalButtons", () => {
|
|
|
|
const callback = jest.fn();
|
|
|
|
const additionalButtons: ViewRoomOpts["buttons"] = [
|
|
|
|
{
|
2023-11-09 19:23:30 +08:00
|
|
|
icon: () => <>test-icon</>,
|
2023-11-01 20:03:10 +08:00
|
|
|
id: "test-id",
|
|
|
|
label: () => "test-label",
|
|
|
|
onClick: callback,
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
2024-01-12 03:56:36 +08:00
|
|
|
render(<RoomHeader room={room} additionalButtons={additionalButtons} />, getWrapper());
|
2023-11-01 20:03:10 +08:00
|
|
|
|
|
|
|
const button = screen.getByRole("button", { name: "test-label" });
|
|
|
|
const event = createEvent.click(button);
|
|
|
|
event.stopPropagation = jest.fn();
|
|
|
|
fireEvent(button, event);
|
|
|
|
|
|
|
|
expect(callback).toHaveBeenCalled();
|
|
|
|
expect(event.stopPropagation).toHaveBeenCalled();
|
|
|
|
});
|
2024-01-03 20:25:44 +08:00
|
|
|
|
|
|
|
describe("ask to join disabled", () => {
|
|
|
|
it("does not render the RoomKnocksBar", () => {
|
2024-01-12 03:56:36 +08:00
|
|
|
render(<RoomHeader room={room} />, getWrapper());
|
2024-01-03 20:25:44 +08:00
|
|
|
expect(screen.queryByRole("heading", { name: "Asking to join" })).not.toBeInTheDocument();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("ask to join enabled", () => {
|
|
|
|
it("does render the RoomKnocksBar", () => {
|
|
|
|
jest.spyOn(SettingsStore, "getValue").mockImplementation((feature) => feature === "feature_ask_to_join");
|
|
|
|
jest.spyOn(room, "canInvite").mockReturnValue(true);
|
|
|
|
jest.spyOn(room, "getJoinRule").mockReturnValue(JoinRule.Knock);
|
|
|
|
jest.spyOn(room, "getMembersWithMembership").mockReturnValue([new RoomMember(room.roomId, "@foo")]);
|
|
|
|
|
2024-01-12 03:56:36 +08:00
|
|
|
render(<RoomHeader room={room} />, getWrapper());
|
2024-01-03 20:25:44 +08:00
|
|
|
expect(screen.getByRole("heading", { name: "Asking to join" })).toBeInTheDocument();
|
|
|
|
});
|
|
|
|
});
|
2022-09-25 22:57:25 +08:00
|
|
|
});
|
2023-08-23 22:13:40 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param count the number of users to create
|
|
|
|
*/
|
|
|
|
function mockRoomMembers(room: Room, count: number) {
|
|
|
|
const members = Array(count)
|
|
|
|
.fill(0)
|
|
|
|
.map((_, index) => ({
|
|
|
|
userId: `@user-${index}:example.org`,
|
|
|
|
name: `Member ${index}`,
|
|
|
|
rawDisplayName: `Member ${index}`,
|
|
|
|
roomId: room.roomId,
|
|
|
|
membership: "join",
|
|
|
|
getAvatarUrl: () => `mxc://avatar.url/user-${index}.png`,
|
|
|
|
getMxcAvatarUrl: () => `mxc://avatar.url/user-${index}.png`,
|
|
|
|
}));
|
|
|
|
|
|
|
|
room.currentState.setJoinedMemberCount(members.length);
|
|
|
|
room.getJoinedMembers = jest.fn().mockReturnValue(members);
|
|
|
|
}
|