2021-06-23 12:32:41 +00:00
|
|
|
/*
|
2024-09-09 13:57:16 +00:00
|
|
|
Copyright 2024 New Vector Ltd.
|
2022-11-18 19:05:00 +00:00
|
|
|
Copyright 2022 The Matrix.org Foundation C.I.C.
|
2024-09-09 13:57:16 +00:00
|
|
|
Copyright 2021 Šimon Brandner <simon.bra.ag@gmail.com>
|
2021-06-23 12:32:41 +00:00
|
|
|
|
2024-09-09 13:57:16 +00:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only
|
|
|
|
Please see LICENSE files in the repository root for full details.
|
2021-06-23 12:32:41 +00:00
|
|
|
*/
|
|
|
|
|
2023-03-01 15:59:27 +00:00
|
|
|
import React from "react";
|
2024-10-14 16:11:58 +00:00
|
|
|
import { act, fireEvent, render, RenderResult, screen, waitFor, waitForElementToBeRemoved } from "jest-matrix-react";
|
2024-03-18 14:40:52 +00:00
|
|
|
import { Room, MatrixClient, RoomState, RoomMember, User, MatrixEvent } from "matrix-js-sdk/src/matrix";
|
|
|
|
import { KnownMembership } from "matrix-js-sdk/src/types";
|
2023-11-21 01:43:32 +00:00
|
|
|
import { mocked, MockedObject } from "jest-mock";
|
2021-10-22 22:23:32 +00:00
|
|
|
|
2024-10-15 13:57:26 +00:00
|
|
|
import { MatrixClientPeg } from "../../../../../src/MatrixClientPeg";
|
|
|
|
import * as TestUtils from "../../../../test-utils";
|
|
|
|
import MemberList from "../../../../../src/components/views/rooms/MemberList";
|
|
|
|
import { SDKContext } from "../../../../../src/contexts/SDKContext";
|
2022-11-18 19:05:00 +00:00
|
|
|
import { TestSdkContext } from "../../../TestSdkContext";
|
2023-11-21 01:43:32 +00:00
|
|
|
import {
|
|
|
|
filterConsole,
|
|
|
|
flushPromises,
|
|
|
|
getMockClientWithEventEmitter,
|
2024-08-06 17:22:02 +00:00
|
|
|
mockClientMethodsRooms,
|
2023-11-21 01:43:32 +00:00
|
|
|
mockClientMethodsUser,
|
2024-10-15 13:57:26 +00:00
|
|
|
} from "../../../../test-utils";
|
|
|
|
import { shouldShowComponent } from "../../../../../src/customisations/helpers/UIComponents";
|
|
|
|
import defaultDispatcher from "../../../../../src/dispatcher/dispatcher";
|
2023-11-21 01:43:32 +00:00
|
|
|
|
2024-10-15 13:57:26 +00:00
|
|
|
jest.mock("../../../../../src/customisations/helpers/UIComponents", () => ({
|
2023-11-21 01:43:32 +00:00
|
|
|
shouldShowComponent: jest.fn(),
|
|
|
|
}));
|
2021-06-02 09:42:17 +00:00
|
|
|
|
2019-01-04 04:55:52 +00:00
|
|
|
function generateRoomId() {
|
|
|
|
return "!" + Math.random().toString().slice(2, 10) + ":domain";
|
|
|
|
}
|
|
|
|
|
|
|
|
describe("MemberList", () => {
|
2023-11-21 01:43:32 +00:00
|
|
|
filterConsole(
|
|
|
|
"Age for event was not available, using `now - origin_server_ts` as a fallback. If the device clock is not correct issues might occur.",
|
|
|
|
);
|
2022-03-21 09:03:03 +00:00
|
|
|
function createRoom(opts = {}) {
|
2023-02-16 09:38:44 +00:00
|
|
|
const room = new Room(generateRoomId(), client, client.getUserId()!);
|
2019-01-04 04:55:52 +00:00
|
|
|
if (opts) {
|
|
|
|
Object.assign(room, opts);
|
|
|
|
}
|
|
|
|
return room;
|
|
|
|
}
|
|
|
|
|
2023-02-15 13:36:22 +00:00
|
|
|
let client: MatrixClient;
|
2023-03-01 15:59:27 +00:00
|
|
|
let root: RenderResult;
|
2023-02-13 11:39:16 +00:00
|
|
|
let memberListRoom: Room;
|
2023-02-15 13:36:22 +00:00
|
|
|
let memberList: MemberList;
|
2019-01-04 04:55:52 +00:00
|
|
|
|
2023-02-13 11:39:16 +00:00
|
|
|
let adminUsers: RoomMember[] = [];
|
|
|
|
let moderatorUsers: RoomMember[] = [];
|
|
|
|
let defaultUsers: RoomMember[] = [];
|
2019-01-04 04:55:52 +00:00
|
|
|
|
2023-03-01 15:59:27 +00:00
|
|
|
function memberString(member: RoomMember): string {
|
|
|
|
if (!member) {
|
|
|
|
return "(null)";
|
|
|
|
} else {
|
|
|
|
const u = member.user;
|
|
|
|
return (
|
|
|
|
"(" +
|
|
|
|
member.name +
|
|
|
|
", " +
|
|
|
|
member.powerLevel +
|
|
|
|
", " +
|
|
|
|
(u ? u.lastActiveAgo : "<null>") +
|
|
|
|
", " +
|
|
|
|
(u ? u.getLastActiveTs() : "<null>") +
|
|
|
|
", " +
|
|
|
|
(u ? u.currentlyActive : "<null>") +
|
|
|
|
", " +
|
|
|
|
(u ? u.presence : "<null>") +
|
|
|
|
")"
|
|
|
|
);
|
2019-01-04 04:55:52 +00:00
|
|
|
}
|
2023-03-01 15:59:27 +00:00
|
|
|
}
|
2019-01-04 04:55:52 +00:00
|
|
|
|
2023-03-01 15:59:27 +00:00
|
|
|
function expectOrderedByPresenceAndPowerLevel(memberTiles: NodeListOf<Element>, isPresenceEnabled: boolean) {
|
2023-02-15 13:36:22 +00:00
|
|
|
let prevMember: RoomMember | undefined;
|
2019-01-04 04:55:52 +00:00
|
|
|
for (const tile of memberTiles) {
|
|
|
|
const memberA = prevMember;
|
2024-04-24 12:24:25 +00:00
|
|
|
const memberB = memberListRoom.currentState.members[tile.getAttribute("aria-label")!.split(" ")[0]];
|
2019-01-04 04:55:52 +00:00
|
|
|
prevMember = memberB; // just in case an expect fails, set this early
|
|
|
|
if (!memberA) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2023-03-01 15:59:27 +00:00
|
|
|
console.log("COMPARING A VS B:", memberString(memberA), memberString(memberB));
|
2019-01-04 04:55:52 +00:00
|
|
|
|
2023-02-15 13:36:22 +00:00
|
|
|
const userA = memberA.user!;
|
|
|
|
const userB = memberB.user!;
|
2019-01-04 04:55:52 +00:00
|
|
|
|
|
|
|
let groupChange = false;
|
|
|
|
|
|
|
|
if (isPresenceEnabled) {
|
2023-02-13 11:39:16 +00:00
|
|
|
const convertPresence = (p: string) => (p === "unavailable" ? "online" : p);
|
|
|
|
const presenceIndex = (p: string) => {
|
2019-01-04 04:55:52 +00:00
|
|
|
const order = ["active", "online", "offline"];
|
|
|
|
const idx = order.indexOf(convertPresence(p));
|
|
|
|
return idx === -1 ? order.length : idx; // unknown states at the end
|
|
|
|
};
|
|
|
|
|
|
|
|
const idxA = presenceIndex(userA.currentlyActive ? "active" : userA.presence);
|
|
|
|
const idxB = presenceIndex(userB.currentlyActive ? "active" : userB.presence);
|
|
|
|
console.log("Comparing presence groups...");
|
|
|
|
expect(idxB).toBeGreaterThanOrEqual(idxA);
|
|
|
|
groupChange = idxA !== idxB;
|
|
|
|
} else {
|
|
|
|
console.log("Skipped presence groups");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!groupChange) {
|
|
|
|
console.log("Comparing power levels...");
|
|
|
|
expect(memberA.powerLevel).toBeGreaterThanOrEqual(memberB.powerLevel);
|
|
|
|
groupChange = memberA.powerLevel !== memberB.powerLevel;
|
|
|
|
} else {
|
|
|
|
console.log("Skipping power level check due to group change");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!groupChange) {
|
|
|
|
if (isPresenceEnabled) {
|
|
|
|
console.log("Comparing last active timestamp...");
|
2019-01-04 05:24:24 +00:00
|
|
|
expect(userB.getLastActiveTs()).toBeLessThanOrEqual(userA.getLastActiveTs());
|
2019-01-04 04:55:52 +00:00
|
|
|
groupChange = userA.getLastActiveTs() !== userB.getLastActiveTs();
|
|
|
|
} else {
|
|
|
|
console.log("Skipping last active timestamp");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
console.log("Skipping last active timestamp check due to group change");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!groupChange) {
|
2022-04-14 07:52:42 +00:00
|
|
|
const nameA = memberA.name[0] === "@" ? memberA.name.slice(1) : memberA.name;
|
|
|
|
const nameB = memberB.name[0] === "@" ? memberB.name.slice(1) : memberB.name;
|
2024-07-17 13:51:42 +00:00
|
|
|
const collator = new Intl.Collator();
|
|
|
|
const nameCompare = collator.compare(nameB, nameA);
|
2019-01-04 04:55:52 +00:00
|
|
|
console.log("Comparing name");
|
|
|
|
expect(nameCompare).toBeGreaterThanOrEqual(0);
|
|
|
|
} else {
|
|
|
|
console.log("Skipping name check due to group change");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-07 10:14:30 +00:00
|
|
|
function renderMemberList(enablePresence: boolean): void {
|
|
|
|
TestUtils.stubClient();
|
|
|
|
client = MatrixClientPeg.safeGet();
|
|
|
|
client.hasLazyLoadMembersEnabled = () => false;
|
|
|
|
|
|
|
|
// Make room
|
|
|
|
memberListRoom = createRoom();
|
|
|
|
expect(memberListRoom.roomId).toBeTruthy();
|
|
|
|
|
|
|
|
// Make users
|
|
|
|
adminUsers = [];
|
|
|
|
moderatorUsers = [];
|
|
|
|
defaultUsers = [];
|
|
|
|
const usersPerLevel = 2;
|
|
|
|
for (let i = 0; i < usersPerLevel; i++) {
|
|
|
|
const adminUser = new RoomMember(memberListRoom.roomId, `@admin${i}:localhost`);
|
2024-03-12 14:52:54 +00:00
|
|
|
adminUser.membership = KnownMembership.Join;
|
2023-11-07 10:14:30 +00:00
|
|
|
adminUser.powerLevel = 100;
|
|
|
|
adminUser.user = User.createUser(adminUser.userId, client);
|
|
|
|
adminUser.user.currentlyActive = true;
|
|
|
|
adminUser.user.presence = "online";
|
|
|
|
adminUser.user.lastPresenceTs = 1000;
|
|
|
|
adminUser.user.lastActiveAgo = 10;
|
|
|
|
adminUsers.push(adminUser);
|
|
|
|
|
|
|
|
const moderatorUser = new RoomMember(memberListRoom.roomId, `@moderator${i}:localhost`);
|
2024-03-12 14:52:54 +00:00
|
|
|
moderatorUser.membership = KnownMembership.Join;
|
2023-11-07 10:14:30 +00:00
|
|
|
moderatorUser.powerLevel = 50;
|
|
|
|
moderatorUser.user = User.createUser(moderatorUser.userId, client);
|
|
|
|
moderatorUser.user.currentlyActive = true;
|
|
|
|
moderatorUser.user.presence = "online";
|
|
|
|
moderatorUser.user.lastPresenceTs = 1000;
|
|
|
|
moderatorUser.user.lastActiveAgo = 10;
|
|
|
|
moderatorUsers.push(moderatorUser);
|
|
|
|
|
|
|
|
const defaultUser = new RoomMember(memberListRoom.roomId, `@default${i}:localhost`);
|
2024-03-12 14:52:54 +00:00
|
|
|
defaultUser.membership = KnownMembership.Join;
|
2023-11-07 10:14:30 +00:00
|
|
|
defaultUser.powerLevel = 0;
|
|
|
|
defaultUser.user = User.createUser(defaultUser.userId, client);
|
|
|
|
defaultUser.user.currentlyActive = true;
|
|
|
|
defaultUser.user.presence = "online";
|
|
|
|
defaultUser.user.lastPresenceTs = 1000;
|
|
|
|
defaultUser.user.lastActiveAgo = 10;
|
|
|
|
defaultUsers.push(defaultUser);
|
|
|
|
}
|
2023-03-01 15:59:27 +00:00
|
|
|
|
2023-11-07 10:14:30 +00:00
|
|
|
client.getRoom = (roomId) => {
|
|
|
|
if (roomId === memberListRoom.roomId) return memberListRoom;
|
|
|
|
else return null;
|
|
|
|
};
|
|
|
|
memberListRoom.currentState = {
|
|
|
|
members: {},
|
|
|
|
getMember: jest.fn(),
|
|
|
|
getStateEvents: ((eventType, stateKey) =>
|
|
|
|
stateKey === undefined ? [] : null) as RoomState["getStateEvents"], // ignore 3pid invites
|
|
|
|
} as unknown as RoomState;
|
|
|
|
for (const member of [...adminUsers, ...moderatorUsers, ...defaultUsers]) {
|
|
|
|
memberListRoom.currentState.members[member.userId] = member;
|
|
|
|
}
|
2023-03-01 15:59:27 +00:00
|
|
|
|
2023-11-07 10:14:30 +00:00
|
|
|
const gatherWrappedRef = (r: MemberList) => {
|
|
|
|
memberList = r;
|
|
|
|
};
|
|
|
|
const context = new TestSdkContext();
|
|
|
|
context.client = client;
|
|
|
|
context.memberListStore.isPresenceEnabled = jest.fn().mockReturnValue(enablePresence);
|
|
|
|
root = render(
|
|
|
|
<SDKContext.Provider value={context}>
|
|
|
|
<MemberList
|
|
|
|
searchQuery=""
|
|
|
|
onClose={jest.fn()}
|
|
|
|
onSearchQueryChanged={jest.fn()}
|
|
|
|
roomId={memberListRoom.roomId}
|
|
|
|
ref={gatherWrappedRef}
|
|
|
|
/>
|
|
|
|
</SDKContext.Provider>,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
describe.each([false, true])("does order members correctly (presence %s)", (enablePresence) => {
|
|
|
|
beforeEach(function () {
|
|
|
|
renderMemberList(enablePresence);
|
2023-03-01 15:59:27 +00:00
|
|
|
});
|
|
|
|
|
2019-01-04 04:55:52 +00:00
|
|
|
describe("does order members correctly", () => {
|
|
|
|
// Note: even if presence is disabled, we still expect that the presence
|
|
|
|
// tests will pass. All expectOrderedByPresenceAndPowerLevel does is ensure
|
|
|
|
// the order is perceived correctly, regardless of what we did to the members.
|
|
|
|
|
|
|
|
// Each of the 4 tests here is done to prove that the member list can meet
|
|
|
|
// all 4 criteria independently. Together, they should work.
|
|
|
|
|
2023-03-01 15:59:27 +00:00
|
|
|
it("by presence state", async () => {
|
2019-01-04 04:55:52 +00:00
|
|
|
// Intentionally pick users that will confuse the power level sorting
|
|
|
|
const activeUsers = [defaultUsers[0]];
|
|
|
|
const onlineUsers = [adminUsers[0]];
|
|
|
|
const offlineUsers = [...moderatorUsers, ...adminUsers.slice(1), ...defaultUsers.slice(1)];
|
|
|
|
activeUsers.forEach((u) => {
|
2023-02-15 13:36:22 +00:00
|
|
|
u.user!.currentlyActive = true;
|
|
|
|
u.user!.presence = "online";
|
2019-01-04 04:55:52 +00:00
|
|
|
});
|
|
|
|
onlineUsers.forEach((u) => {
|
2023-02-15 13:36:22 +00:00
|
|
|
u.user!.currentlyActive = false;
|
|
|
|
u.user!.presence = "online";
|
2019-01-04 04:55:52 +00:00
|
|
|
});
|
|
|
|
offlineUsers.forEach((u) => {
|
2023-02-15 13:36:22 +00:00
|
|
|
u.user!.currentlyActive = false;
|
|
|
|
u.user!.presence = "offline";
|
2019-01-04 04:55:52 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// Bypass all the event listeners and skip to the good part
|
2023-03-01 15:59:27 +00:00
|
|
|
await act(() => memberList.updateListNow(true));
|
2019-01-04 04:55:52 +00:00
|
|
|
|
2023-03-01 15:59:27 +00:00
|
|
|
const tiles = root.container.querySelectorAll(".mx_EntityTile");
|
2019-01-04 04:55:52 +00:00
|
|
|
expectOrderedByPresenceAndPowerLevel(tiles, enablePresence);
|
|
|
|
});
|
|
|
|
|
2023-03-01 15:59:27 +00:00
|
|
|
it("by power level", async () => {
|
2019-01-04 04:55:52 +00:00
|
|
|
// We already have admin, moderator, and default users so leave them alone
|
|
|
|
|
|
|
|
// Bypass all the event listeners and skip to the good part
|
2023-03-01 15:59:27 +00:00
|
|
|
await act(() => memberList.updateListNow(true));
|
2019-01-04 04:55:52 +00:00
|
|
|
|
2023-03-01 15:59:27 +00:00
|
|
|
const tiles = root.container.querySelectorAll(".mx_EntityTile");
|
2019-01-04 04:55:52 +00:00
|
|
|
expectOrderedByPresenceAndPowerLevel(tiles, enablePresence);
|
|
|
|
});
|
|
|
|
|
2023-03-01 15:59:27 +00:00
|
|
|
it("by last active timestamp", async () => {
|
2019-01-04 04:55:52 +00:00
|
|
|
// Intentionally pick users that will confuse the power level sorting
|
|
|
|
// lastActiveAgoTs == lastPresenceTs - lastActiveAgo
|
|
|
|
const activeUsers = [defaultUsers[0]];
|
|
|
|
const semiActiveUsers = [adminUsers[0]];
|
|
|
|
const inactiveUsers = [...moderatorUsers, ...adminUsers.slice(1), ...defaultUsers.slice(1)];
|
|
|
|
activeUsers.forEach((u) => {
|
2019-01-04 05:24:24 +00:00
|
|
|
u.powerLevel = 100; // set everyone to the same PL to avoid running that check
|
2023-02-15 13:36:22 +00:00
|
|
|
u.user!.lastPresenceTs = 1000;
|
|
|
|
u.user!.lastActiveAgo = 0;
|
2019-01-04 04:55:52 +00:00
|
|
|
});
|
|
|
|
semiActiveUsers.forEach((u) => {
|
2019-01-04 05:24:24 +00:00
|
|
|
u.powerLevel = 100;
|
2023-02-15 13:36:22 +00:00
|
|
|
u.user!.lastPresenceTs = 1000;
|
|
|
|
u.user!.lastActiveAgo = 50;
|
2019-01-04 04:55:52 +00:00
|
|
|
});
|
|
|
|
inactiveUsers.forEach((u) => {
|
2019-01-04 05:24:24 +00:00
|
|
|
u.powerLevel = 100;
|
2023-02-15 13:36:22 +00:00
|
|
|
u.user!.lastPresenceTs = 1000;
|
|
|
|
u.user!.lastActiveAgo = 100;
|
2019-01-04 04:55:52 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// Bypass all the event listeners and skip to the good part
|
2023-03-01 15:59:27 +00:00
|
|
|
await act(() => memberList.updateListNow(true));
|
2019-01-04 04:55:52 +00:00
|
|
|
|
2023-03-01 15:59:27 +00:00
|
|
|
const tiles = root.container.querySelectorAll(".mx_EntityTile");
|
2019-01-04 04:55:52 +00:00
|
|
|
expectOrderedByPresenceAndPowerLevel(tiles, enablePresence);
|
|
|
|
});
|
|
|
|
|
2023-03-01 15:59:27 +00:00
|
|
|
it("by name", async () => {
|
2019-01-04 04:55:52 +00:00
|
|
|
// Intentionally put everyone on the same level to force a name comparison
|
|
|
|
const allUsers = [...adminUsers, ...moderatorUsers, ...defaultUsers];
|
|
|
|
allUsers.forEach((u) => {
|
2023-02-15 13:36:22 +00:00
|
|
|
u.user!.currentlyActive = true;
|
|
|
|
u.user!.presence = "online";
|
|
|
|
u.user!.lastPresenceTs = 1000;
|
|
|
|
u.user!.lastActiveAgo = 0;
|
2019-01-04 04:55:52 +00:00
|
|
|
u.powerLevel = 100;
|
|
|
|
});
|
|
|
|
|
|
|
|
// Bypass all the event listeners and skip to the good part
|
2023-03-01 15:59:27 +00:00
|
|
|
await act(() => memberList.updateListNow(true));
|
2019-01-04 04:55:52 +00:00
|
|
|
|
2023-03-01 15:59:27 +00:00
|
|
|
const tiles = root.container.querySelectorAll(".mx_EntityTile");
|
2019-01-04 04:55:52 +00:00
|
|
|
expectOrderedByPresenceAndPowerLevel(tiles, enablePresence);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2023-11-07 10:14:30 +00:00
|
|
|
|
|
|
|
describe("memberlist is rendered correctly", () => {
|
|
|
|
beforeEach(function () {
|
|
|
|
renderMemberList(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("memberlist is re-rendered on unreachable presence event", async () => {
|
|
|
|
defaultUsers[0].user?.setPresenceEvent(
|
|
|
|
new MatrixEvent({
|
|
|
|
type: "m.presence",
|
|
|
|
sender: defaultUsers[0].userId,
|
|
|
|
content: {
|
|
|
|
presence: "io.element.unreachable",
|
|
|
|
currently_active: false,
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
expect(await screen.findByText(/User's server unreachable/)).toBeInTheDocument();
|
|
|
|
});
|
2023-11-21 01:43:32 +00:00
|
|
|
|
|
|
|
describe("Invite button", () => {
|
|
|
|
const roomId = "!room:server.org";
|
|
|
|
let client!: MockedObject<MatrixClient>;
|
|
|
|
let room!: Room;
|
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
mocked(shouldShowComponent).mockReturnValue(true);
|
|
|
|
client = getMockClientWithEventEmitter({
|
|
|
|
...mockClientMethodsUser(),
|
2024-08-06 17:22:02 +00:00
|
|
|
...mockClientMethodsRooms(),
|
2023-11-21 01:43:32 +00:00
|
|
|
getRoom: jest.fn(),
|
|
|
|
hasLazyLoadMembersEnabled: jest.fn(),
|
|
|
|
});
|
|
|
|
room = new Room(roomId, client, client.getSafeUserId());
|
|
|
|
client.getRoom.mockReturnValue(room);
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
jest.restoreAllMocks();
|
|
|
|
});
|
|
|
|
|
|
|
|
const renderComponent = () => {
|
|
|
|
const context = new TestSdkContext();
|
|
|
|
context.client = client;
|
2024-08-06 17:22:02 +00:00
|
|
|
return render(
|
2023-11-21 01:43:32 +00:00
|
|
|
<SDKContext.Provider value={context}>
|
|
|
|
<MemberList
|
|
|
|
searchQuery=""
|
|
|
|
onClose={jest.fn()}
|
|
|
|
onSearchQueryChanged={jest.fn()}
|
|
|
|
roomId={room.roomId}
|
|
|
|
/>
|
|
|
|
</SDKContext.Provider>,
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
it("does not render invite button when current user is not a member", async () => {
|
|
|
|
renderComponent();
|
|
|
|
await flushPromises();
|
|
|
|
|
|
|
|
expect(screen.queryByText("Invite to this room")).not.toBeInTheDocument();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("does not render invite button UI customisation hides invites", async () => {
|
|
|
|
mocked(shouldShowComponent).mockReturnValue(false);
|
|
|
|
renderComponent();
|
|
|
|
await flushPromises();
|
|
|
|
|
|
|
|
expect(screen.queryByText("Invite to this room")).not.toBeInTheDocument();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("renders disabled invite button when current user is a member but does not have rights to invite", async () => {
|
2024-03-12 14:52:54 +00:00
|
|
|
jest.spyOn(room, "getMyMembership").mockReturnValue(KnownMembership.Join);
|
2023-11-21 01:43:32 +00:00
|
|
|
jest.spyOn(room, "canInvite").mockReturnValue(false);
|
|
|
|
|
|
|
|
renderComponent();
|
|
|
|
await flushPromises();
|
|
|
|
|
|
|
|
// button rendered but disabled
|
2024-10-14 16:11:58 +00:00
|
|
|
expect(screen.getByText("Invite to this room")).toHaveAttribute("aria-disabled", "true");
|
2023-11-21 01:43:32 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("renders enabled invite button when current user is a member and has rights to invite", async () => {
|
2024-03-12 14:52:54 +00:00
|
|
|
jest.spyOn(room, "getMyMembership").mockReturnValue(KnownMembership.Join);
|
2023-11-21 01:43:32 +00:00
|
|
|
jest.spyOn(room, "canInvite").mockReturnValue(true);
|
|
|
|
|
|
|
|
renderComponent();
|
|
|
|
await flushPromises();
|
|
|
|
|
|
|
|
expect(screen.getByText("Invite to this room")).not.toBeDisabled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("opens room inviter on button click", async () => {
|
|
|
|
jest.spyOn(defaultDispatcher, "dispatch");
|
2024-03-12 14:52:54 +00:00
|
|
|
jest.spyOn(room, "getMyMembership").mockReturnValue(KnownMembership.Join);
|
2023-11-21 01:43:32 +00:00
|
|
|
jest.spyOn(room, "canInvite").mockReturnValue(true);
|
|
|
|
|
2024-08-06 17:22:02 +00:00
|
|
|
const { getByRole } = renderComponent();
|
|
|
|
await waitForElementToBeRemoved(() => screen.queryAllByRole("progressbar"));
|
|
|
|
|
|
|
|
await waitFor(() =>
|
|
|
|
expect(getByRole("button", { name: "Invite to this room" })).not.toHaveAttribute(
|
|
|
|
"aria-disabled",
|
|
|
|
"true",
|
|
|
|
),
|
|
|
|
);
|
2023-11-21 01:43:32 +00:00
|
|
|
|
2024-08-06 17:22:02 +00:00
|
|
|
fireEvent.click(getByRole("button", { name: "Invite to this room" }));
|
2023-11-21 01:43:32 +00:00
|
|
|
|
|
|
|
expect(defaultDispatcher.dispatch).toHaveBeenCalledWith({
|
|
|
|
action: "view_invite",
|
|
|
|
roomId,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2023-11-07 10:14:30 +00:00
|
|
|
});
|
2019-01-04 04:55:52 +00:00
|
|
|
});
|