2022-03-22 22:14:11 +00:00
|
|
|
/*
|
|
|
|
Copyright 2022 The Matrix.org Foundation C.I.C.
|
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import React from "react";
|
2022-08-02 13:10:43 +00:00
|
|
|
// eslint-disable-next-line deprecate/import
|
2022-03-22 22:14:11 +00:00
|
|
|
import { mount } from "enzyme";
|
|
|
|
import { act } from "react-dom/test-utils";
|
2022-03-22 23:07:37 +00:00
|
|
|
import { mocked } from "jest-mock";
|
2022-04-21 11:41:38 +00:00
|
|
|
import { MatrixClient } from "matrix-js-sdk/src/client";
|
|
|
|
import { Room } from "matrix-js-sdk/src/models/room";
|
2022-03-28 13:12:09 +00:00
|
|
|
import { RoomMember } from "matrix-js-sdk/src/models/room-member";
|
2022-03-22 22:14:11 +00:00
|
|
|
|
2022-03-28 13:12:09 +00:00
|
|
|
import {
|
|
|
|
stubClient,
|
|
|
|
mockStateEventImplementation,
|
|
|
|
mkRoom,
|
2022-04-20 15:03:33 +00:00
|
|
|
mkVideoChannelMember,
|
2022-04-05 16:57:16 +00:00
|
|
|
stubVideoChannelStore,
|
2022-04-21 11:41:38 +00:00
|
|
|
StubVideoChannelStore,
|
2022-03-28 13:12:09 +00:00
|
|
|
} from "../../../test-utils";
|
2022-06-09 13:19:52 +00:00
|
|
|
import { STUCK_DEVICE_TIMEOUT_MS } from "../../../../src/utils/VideoChannelUtils";
|
2022-03-22 22:14:11 +00:00
|
|
|
import RoomTile from "../../../../src/components/views/rooms/RoomTile";
|
|
|
|
import SettingsStore from "../../../../src/settings/SettingsStore";
|
|
|
|
import { DefaultTagID } from "../../../../src/stores/room-list/models";
|
|
|
|
import DMRoomMap from "../../../../src/utils/DMRoomMap";
|
2022-03-22 22:40:09 +00:00
|
|
|
import { MatrixClientPeg } from "../../../../src/MatrixClientPeg";
|
2022-03-22 23:07:37 +00:00
|
|
|
import PlatformPeg from "../../../../src/PlatformPeg";
|
2022-03-22 22:40:09 +00:00
|
|
|
import BasePlatform from "../../../../src/BasePlatform";
|
2022-03-22 22:14:11 +00:00
|
|
|
|
2022-06-09 13:19:52 +00:00
|
|
|
const mockGetMember = (room: Room, getMembership: (userId: string) => string = () => "join") => {
|
|
|
|
mocked(room).getMember.mockImplementation(userId => ({
|
|
|
|
userId,
|
|
|
|
membership: getMembership(userId),
|
|
|
|
name: userId,
|
|
|
|
rawDisplayName: userId,
|
|
|
|
roomId: "!1:example.org",
|
|
|
|
getAvatarUrl: () => {},
|
|
|
|
getMxcAvatarUrl: () => {},
|
|
|
|
}) as unknown as RoomMember);
|
|
|
|
};
|
|
|
|
|
2022-03-22 22:14:11 +00:00
|
|
|
describe("RoomTile", () => {
|
2022-03-22 22:40:09 +00:00
|
|
|
jest.spyOn(PlatformPeg, 'get')
|
|
|
|
.mockReturnValue({ overrideBrowserShortcuts: () => false } as unknown as BasePlatform);
|
|
|
|
|
2022-04-21 11:41:38 +00:00
|
|
|
let cli: MatrixClient;
|
|
|
|
let store: StubVideoChannelStore;
|
2022-03-22 22:14:11 +00:00
|
|
|
beforeEach(() => {
|
2022-03-22 22:40:09 +00:00
|
|
|
const realGetValue = SettingsStore.getValue;
|
2022-03-28 13:12:09 +00:00
|
|
|
SettingsStore.getValue = <T, >(name: string, roomId?: string): T => {
|
2022-04-01 14:36:10 +00:00
|
|
|
if (name === "feature_video_rooms") {
|
2022-03-28 13:12:09 +00:00
|
|
|
return true as unknown as T;
|
2022-03-22 22:40:09 +00:00
|
|
|
}
|
|
|
|
return realGetValue(name, roomId);
|
2022-03-28 13:12:09 +00:00
|
|
|
};
|
2022-03-22 22:40:09 +00:00
|
|
|
|
2022-03-22 22:14:11 +00:00
|
|
|
stubClient();
|
2022-04-21 11:41:38 +00:00
|
|
|
cli = MatrixClientPeg.get();
|
2022-04-01 14:36:10 +00:00
|
|
|
store = stubVideoChannelStore();
|
|
|
|
DMRoomMap.makeShared();
|
2022-03-22 22:14:11 +00:00
|
|
|
});
|
|
|
|
|
2022-06-09 13:19:52 +00:00
|
|
|
afterEach(() => {
|
|
|
|
jest.clearAllMocks();
|
|
|
|
jest.useRealTimers();
|
|
|
|
});
|
2022-03-28 13:12:09 +00:00
|
|
|
|
2022-04-01 14:36:10 +00:00
|
|
|
describe("video rooms", () => {
|
2022-04-21 11:41:38 +00:00
|
|
|
let room: Room;
|
|
|
|
beforeEach(() => {
|
|
|
|
room = mkRoom(cli, "!1:example.org");
|
|
|
|
mocked(room.isElementVideoRoom).mockReturnValue(true);
|
|
|
|
});
|
2022-03-28 13:12:09 +00:00
|
|
|
|
2022-06-09 13:19:52 +00:00
|
|
|
const mountTile = () => mount(
|
|
|
|
<RoomTile
|
|
|
|
room={room}
|
|
|
|
showMessagePreview={false}
|
|
|
|
isMinimized={false}
|
|
|
|
tag={DefaultTagID.Untagged}
|
|
|
|
/>,
|
|
|
|
);
|
|
|
|
|
2022-04-01 14:36:10 +00:00
|
|
|
it("tracks connection state", () => {
|
2022-06-09 13:19:52 +00:00
|
|
|
const tile = mountTile();
|
|
|
|
expect(tile.find(".mx_VideoRoomSummary_indicator").text()).toEqual("Video");
|
2022-03-22 22:14:11 +00:00
|
|
|
|
2022-04-20 15:03:33 +00:00
|
|
|
act(() => { store.startConnect("!1:example.org"); });
|
|
|
|
tile.update();
|
2022-06-09 13:19:52 +00:00
|
|
|
expect(tile.find(".mx_VideoRoomSummary_indicator").text()).toEqual("Joining…");
|
2022-04-20 15:03:33 +00:00
|
|
|
|
2022-04-01 14:36:10 +00:00
|
|
|
act(() => { store.connect("!1:example.org"); });
|
2022-03-22 22:14:11 +00:00
|
|
|
tile.update();
|
2022-06-09 13:19:52 +00:00
|
|
|
expect(tile.find(".mx_VideoRoomSummary_indicator").text()).toEqual("Joined");
|
2022-03-22 22:14:11 +00:00
|
|
|
|
2022-04-01 14:36:10 +00:00
|
|
|
act(() => { store.disconnect(); });
|
2022-03-22 22:14:11 +00:00
|
|
|
tile.update();
|
2022-06-09 13:19:52 +00:00
|
|
|
expect(tile.find(".mx_VideoRoomSummary_indicator").text()).toEqual("Video");
|
2022-03-22 22:14:11 +00:00
|
|
|
});
|
2022-03-28 13:12:09 +00:00
|
|
|
|
2022-04-01 14:36:10 +00:00
|
|
|
it("displays connected members", () => {
|
2022-06-09 13:19:52 +00:00
|
|
|
mockGetMember(room, userId => userId === "@chris:example.org" ? "leave" : "join");
|
2022-03-28 13:12:09 +00:00
|
|
|
mocked(room.currentState).getStateEvents.mockImplementation(mockStateEventImplementation([
|
|
|
|
// A user connected from 2 devices
|
2022-04-01 14:36:10 +00:00
|
|
|
mkVideoChannelMember("@alice:example.org", ["device 1", "device 2"]),
|
2022-03-28 13:12:09 +00:00
|
|
|
// A disconnected user
|
2022-04-01 14:36:10 +00:00
|
|
|
mkVideoChannelMember("@bob:example.org", []),
|
2022-03-28 13:12:09 +00:00
|
|
|
// A user that claims to have a connected device, but has left the room
|
2022-04-01 14:36:10 +00:00
|
|
|
mkVideoChannelMember("@chris:example.org", ["device 1"]),
|
2022-03-28 13:12:09 +00:00
|
|
|
]));
|
|
|
|
|
2022-06-09 13:19:52 +00:00
|
|
|
const tile = mountTile();
|
2022-03-28 13:12:09 +00:00
|
|
|
|
|
|
|
// Only Alice should display as connected
|
2022-06-09 13:19:52 +00:00
|
|
|
expect(tile.find(".mx_VideoRoomSummary_participants").text()).toEqual("1");
|
2022-04-21 11:41:38 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("reflects local echo in connected members", () => {
|
2022-06-09 13:19:52 +00:00
|
|
|
mockGetMember(room);
|
2022-04-21 11:41:38 +00:00
|
|
|
mocked(room.currentState).getStateEvents.mockImplementation(mockStateEventImplementation([
|
|
|
|
// Make the remote echo claim that we're connected, while leaving the store disconnected
|
|
|
|
mkVideoChannelMember(cli.getUserId(), [cli.getDeviceId()]),
|
|
|
|
]));
|
|
|
|
|
2022-06-09 13:19:52 +00:00
|
|
|
const tile = mountTile();
|
2022-04-21 11:41:38 +00:00
|
|
|
|
|
|
|
// Because of our local echo, we should still appear as disconnected
|
2022-06-09 13:19:52 +00:00
|
|
|
expect(tile.find(".mx_VideoRoomSummary_participants").exists()).toEqual(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("doesn't count members whose device data has expired", () => {
|
|
|
|
jest.useFakeTimers();
|
|
|
|
jest.setSystemTime(0);
|
|
|
|
|
|
|
|
mockGetMember(room);
|
|
|
|
mocked(room.currentState).getStateEvents.mockImplementation(mockStateEventImplementation([
|
|
|
|
mkVideoChannelMember("@alice:example.org", ["device 1"], STUCK_DEVICE_TIMEOUT_MS),
|
|
|
|
]));
|
|
|
|
|
|
|
|
const tile = mountTile();
|
|
|
|
|
|
|
|
expect(tile.find(".mx_VideoRoomSummary_participants").text()).toEqual("1");
|
|
|
|
// Expire Alice's device data
|
|
|
|
act(() => { jest.advanceTimersByTime(STUCK_DEVICE_TIMEOUT_MS); });
|
|
|
|
tile.update();
|
|
|
|
expect(tile.find(".mx_VideoRoomSummary_participants").exists()).toEqual(false);
|
2022-03-28 13:12:09 +00:00
|
|
|
});
|
2022-03-22 22:14:11 +00:00
|
|
|
});
|
|
|
|
});
|