2022-05-06 09:09:28 +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.
|
|
|
|
*/
|
|
|
|
|
2023-02-13 11:39:16 +00:00
|
|
|
import React, { ComponentProps } from "react";
|
2023-02-28 08:58:23 +00:00
|
|
|
import { render, RenderResult } from "@testing-library/react";
|
2022-12-12 11:24:14 +00:00
|
|
|
import { MatrixEvent, RoomMember } from "matrix-js-sdk/src/matrix";
|
2022-05-04 14:37:41 +00:00
|
|
|
|
|
|
|
import {
|
|
|
|
getMockClientWithEventEmitter,
|
2023-02-07 10:09:46 +00:00
|
|
|
mkEvent,
|
2022-05-04 14:37:41 +00:00
|
|
|
mkMembership,
|
|
|
|
mockClientMethodsUser,
|
|
|
|
unmockClientPeg,
|
2022-12-12 11:24:14 +00:00
|
|
|
} from "../../../test-utils";
|
2022-05-04 14:37:41 +00:00
|
|
|
import EventListSummary from "../../../../src/components/views/elements/EventListSummary";
|
2022-12-12 11:24:14 +00:00
|
|
|
import { Layout } from "../../../../src/settings/enums/Layout";
|
|
|
|
import MatrixClientContext from "../../../../src/contexts/MatrixClientContext";
|
2023-09-25 11:18:15 +00:00
|
|
|
import * as languageHandler from "../../../../src/languageHandler";
|
2017-01-17 11:01:54 +00:00
|
|
|
|
2022-12-12 11:24:14 +00:00
|
|
|
describe("EventListSummary", function () {
|
|
|
|
const roomId = "!room:server.org";
|
2017-01-18 10:53:17 +00:00
|
|
|
// Generate dummy event tiles for use in simulating an expanded MELS
|
2022-05-04 14:37:41 +00:00
|
|
|
const generateTiles = (events: MatrixEvent[]) => {
|
2017-01-17 11:01:54 +00:00
|
|
|
return events.map((e) => {
|
|
|
|
return (
|
|
|
|
<div key={e.getId()} className="event_tile">
|
|
|
|
Expanded membership
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2017-01-18 10:53:17 +00:00
|
|
|
/**
|
2017-01-25 10:52:55 +00:00
|
|
|
* Generates a membership event with the target of the event set as a mocked
|
|
|
|
* RoomMember based on `parameters.userId`.
|
2017-01-18 10:53:17 +00:00
|
|
|
* @param {string} eventId the ID of the event.
|
|
|
|
* @param {object} parameters the parameters to use to create the event.
|
2017-01-25 10:52:55 +00:00
|
|
|
* @param {string} parameters.membership the membership to assign to
|
|
|
|
* `content.membership`
|
2017-01-18 10:53:17 +00:00
|
|
|
* @param {string} parameters.userId the state key and target userId of the event. If
|
|
|
|
* `parameters.senderId` is not specified, this is also used as the event sender.
|
|
|
|
* @param {string} parameters.prevMembership the membership to assign to
|
|
|
|
* `prev_content.membership`.
|
2017-01-25 10:52:55 +00:00
|
|
|
* @param {string} parameters.senderId the user ID of the sender of the event.
|
|
|
|
* Optional. Defaults to `parameters.userId`.
|
2017-01-18 10:53:17 +00:00
|
|
|
* @returns {MatrixEvent} the event created.
|
|
|
|
*/
|
2022-05-04 14:37:41 +00:00
|
|
|
interface MembershipEventParams {
|
|
|
|
senderId?: string;
|
2023-02-13 11:39:16 +00:00
|
|
|
userId?: string;
|
2024-03-11 17:16:53 +00:00
|
|
|
membership: Membership;
|
|
|
|
prevMembership?: Membership;
|
2022-05-04 14:37:41 +00:00
|
|
|
}
|
|
|
|
const generateMembershipEvent = (
|
2022-12-12 11:24:14 +00:00
|
|
|
eventId: string,
|
2023-02-16 09:38:44 +00:00
|
|
|
{ senderId, userId, membership, prevMembership }: MembershipEventParams & { userId: string },
|
2022-05-04 14:37:41 +00:00
|
|
|
): MatrixEvent => {
|
|
|
|
const member = new RoomMember(roomId, userId);
|
|
|
|
// Use localpart as display name;
|
2023-02-16 09:38:44 +00:00
|
|
|
member.name = userId.match(/@([^:]*):/)![1];
|
2022-12-12 11:24:14 +00:00
|
|
|
jest.spyOn(member, "getAvatarUrl").mockReturnValue("avatar.jpeg");
|
|
|
|
jest.spyOn(member, "getMxcAvatarUrl").mockReturnValue("mxc://avatar.url/image.png");
|
2022-05-04 14:37:41 +00:00
|
|
|
const e = mkMembership({
|
2017-01-18 10:53:17 +00:00
|
|
|
event: true,
|
2022-05-04 14:37:41 +00:00
|
|
|
room: roomId,
|
|
|
|
user: senderId || userId,
|
|
|
|
skey: userId,
|
|
|
|
mship: membership,
|
|
|
|
prevMship: prevMembership,
|
|
|
|
target: member,
|
2017-01-18 10:53:17 +00:00
|
|
|
});
|
2017-01-25 10:52:55 +00:00
|
|
|
// Override random event ID to allow for equality tests against tiles from
|
|
|
|
// generateTiles
|
2017-01-18 10:53:17 +00:00
|
|
|
e.event.event_id = eventId;
|
|
|
|
return e;
|
2017-01-17 11:01:54 +00:00
|
|
|
};
|
|
|
|
|
2017-01-18 10:53:17 +00:00
|
|
|
// Generate mock MatrixEvents from the array of parameters
|
2023-02-16 09:38:44 +00:00
|
|
|
const generateEvents = (parameters: Array<MembershipEventParams & { userId: string }>) => {
|
|
|
|
const res: MatrixEvent[] = [];
|
2017-01-17 11:01:54 +00:00
|
|
|
for (let i = 0; i < parameters.length; i++) {
|
|
|
|
res.push(generateMembershipEvent(`event${i}`, parameters[i]));
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
};
|
|
|
|
|
2017-01-18 10:53:17 +00:00
|
|
|
// Generate the same sequence of `events` for `n` users, where each user ID
|
|
|
|
// is created by replacing the first "$" in userIdTemplate with `i` for
|
|
|
|
// `i = 0 .. n`.
|
2023-02-13 11:39:16 +00:00
|
|
|
const generateEventsForUsers = (userIdTemplate: string, n: number, events: MembershipEventParams[]) => {
|
2023-02-07 10:09:46 +00:00
|
|
|
let eventsForUsers: MatrixEvent[] = [];
|
2017-01-17 11:01:54 +00:00
|
|
|
let userId = "";
|
|
|
|
for (let i = 0; i < n; i++) {
|
2023-02-13 11:39:16 +00:00
|
|
|
userId = userIdTemplate.replace("$", String(i));
|
2017-01-17 11:01:54 +00:00
|
|
|
events.forEach((e) => {
|
|
|
|
e.userId = userId;
|
|
|
|
});
|
2023-02-16 09:38:44 +00:00
|
|
|
eventsForUsers = eventsForUsers.concat(
|
|
|
|
generateEvents(events as Array<MembershipEventParams & { userId: string }>),
|
|
|
|
);
|
2017-01-17 11:01:54 +00:00
|
|
|
}
|
|
|
|
return eventsForUsers;
|
|
|
|
};
|
|
|
|
|
2022-05-04 14:37:41 +00:00
|
|
|
const mockClient = getMockClientWithEventEmitter({
|
|
|
|
...mockClientMethodsUser(),
|
|
|
|
});
|
|
|
|
|
2023-03-29 07:23:54 +00:00
|
|
|
const defaultProps: Omit<
|
|
|
|
ComponentProps<typeof EventListSummary>,
|
|
|
|
"summaryLength" | "threshold" | "avatarsMaxLength"
|
|
|
|
> = {
|
2022-05-04 14:37:41 +00:00
|
|
|
layout: Layout.Bubble,
|
|
|
|
events: [],
|
|
|
|
children: [],
|
|
|
|
};
|
2023-02-28 08:58:23 +00:00
|
|
|
const renderComponent = (props = {}): RenderResult => {
|
|
|
|
return render(
|
2022-12-12 11:24:14 +00:00
|
|
|
<MatrixClientContext.Provider value={mockClient}>
|
|
|
|
<EventListSummary {...defaultProps} {...props} />
|
|
|
|
</MatrixClientContext.Provider>,
|
2022-05-04 14:37:41 +00:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2022-12-12 11:24:14 +00:00
|
|
|
beforeEach(function () {
|
2022-05-04 14:37:41 +00:00
|
|
|
jest.clearAllMocks();
|
2023-09-25 11:18:15 +00:00
|
|
|
jest.spyOn(languageHandler, "getUserLanguage").mockReturnValue("en-GB");
|
2022-05-04 14:37:41 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
afterAll(() => {
|
|
|
|
unmockClientPeg();
|
2017-01-17 11:01:54 +00:00
|
|
|
});
|
|
|
|
|
2022-12-12 11:24:14 +00:00
|
|
|
it("renders expanded events if there are less than props.threshold", function () {
|
2024-03-11 17:16:53 +00:00
|
|
|
const events = generateEvents([
|
|
|
|
{ userId: "@user_1:some.domain", prevMembership: Membership.Leave, membership: Membership.Join },
|
|
|
|
]);
|
2017-01-17 11:01:54 +00:00
|
|
|
const props = {
|
2017-01-25 10:52:55 +00:00
|
|
|
events: events,
|
|
|
|
children: generateTiles(events),
|
|
|
|
summaryLength: 1,
|
|
|
|
avatarsMaxLength: 5,
|
|
|
|
threshold: 3,
|
2017-01-17 11:01:54 +00:00
|
|
|
};
|
|
|
|
|
2023-02-28 08:58:23 +00:00
|
|
|
const { container } = renderComponent(props); // matrix cli context wrapper
|
2017-01-17 11:01:54 +00:00
|
|
|
|
2023-02-28 08:58:23 +00:00
|
|
|
const children = container.querySelector(".mx_GenericEventListSummary_unstyledList")!.children;
|
|
|
|
expect(children).toHaveLength(1);
|
|
|
|
expect(children[0]).toHaveTextContent("Expanded membership");
|
2017-01-17 11:01:54 +00:00
|
|
|
});
|
|
|
|
|
2023-03-01 15:23:35 +00:00
|
|
|
it("renders expanded events if there are less than props.threshold for join and leave", function () {
|
2017-01-17 11:01:54 +00:00
|
|
|
const events = generateEvents([
|
2024-03-11 17:16:53 +00:00
|
|
|
{ userId: "@user_1:some.domain", prevMembership: Membership.Leave, membership: Membership.Join },
|
|
|
|
{ userId: "@user_1:some.domain", prevMembership: Membership.Join, membership: Membership.Leave },
|
2017-01-17 11:01:54 +00:00
|
|
|
]);
|
|
|
|
const props = {
|
2017-01-25 10:52:55 +00:00
|
|
|
events: events,
|
|
|
|
children: generateTiles(events),
|
|
|
|
summaryLength: 1,
|
|
|
|
avatarsMaxLength: 5,
|
|
|
|
threshold: 3,
|
2017-01-17 11:01:54 +00:00
|
|
|
};
|
|
|
|
|
2023-02-28 08:58:23 +00:00
|
|
|
const { container } = renderComponent(props); // matrix cli context wrapper
|
2017-01-17 11:01:54 +00:00
|
|
|
|
2023-02-28 08:58:23 +00:00
|
|
|
const children = container.querySelector(".mx_GenericEventListSummary_unstyledList")!.children;
|
|
|
|
expect(children).toHaveLength(2);
|
|
|
|
expect(children[0]).toHaveTextContent("Expanded membership");
|
|
|
|
expect(children[1]).toHaveTextContent("Expanded membership");
|
2017-01-17 11:01:54 +00:00
|
|
|
});
|
|
|
|
|
2022-12-12 11:24:14 +00:00
|
|
|
it("renders collapsed events if events.length = props.threshold", function () {
|
2017-01-17 11:01:54 +00:00
|
|
|
const events = generateEvents([
|
2024-03-11 17:16:53 +00:00
|
|
|
{ userId: "@user_1:some.domain", prevMembership: Membership.Leave, membership: Membership.Join },
|
|
|
|
{ userId: "@user_1:some.domain", prevMembership: Membership.Join, membership: Membership.Leave },
|
|
|
|
{ userId: "@user_1:some.domain", prevMembership: Membership.Leave, membership: Membership.Join },
|
2017-01-17 11:01:54 +00:00
|
|
|
]);
|
|
|
|
const props = {
|
2017-01-25 10:52:55 +00:00
|
|
|
events: events,
|
|
|
|
children: generateTiles(events),
|
|
|
|
summaryLength: 1,
|
|
|
|
avatarsMaxLength: 5,
|
|
|
|
threshold: 3,
|
2017-01-17 11:01:54 +00:00
|
|
|
};
|
|
|
|
|
2023-02-28 08:58:23 +00:00
|
|
|
const { container } = renderComponent(props);
|
|
|
|
const summary = container.querySelector(".mx_GenericEventListSummary_summary");
|
|
|
|
expect(summary).toHaveTextContent("user_1 joined and left and joined");
|
2017-01-17 11:01:54 +00:00
|
|
|
});
|
|
|
|
|
2022-12-12 11:24:14 +00:00
|
|
|
it("truncates long join,leave repetitions", function () {
|
2017-01-17 11:01:54 +00:00
|
|
|
const events = generateEvents([
|
2024-03-11 17:16:53 +00:00
|
|
|
{ userId: "@user_1:some.domain", prevMembership: Membership.Leave, membership: Membership.Join },
|
|
|
|
{ userId: "@user_1:some.domain", prevMembership: Membership.Join, membership: Membership.Leave },
|
|
|
|
{ userId: "@user_1:some.domain", prevMembership: Membership.Leave, membership: Membership.Join },
|
|
|
|
{ userId: "@user_1:some.domain", prevMembership: Membership.Join, membership: Membership.Leave },
|
|
|
|
{ userId: "@user_1:some.domain", prevMembership: Membership.Leave, membership: Membership.Join },
|
|
|
|
{ userId: "@user_1:some.domain", prevMembership: Membership.Join, membership: Membership.Leave },
|
|
|
|
{ userId: "@user_1:some.domain", prevMembership: Membership.Leave, membership: Membership.Join },
|
|
|
|
{ userId: "@user_1:some.domain", prevMembership: Membership.Join, membership: Membership.Leave },
|
|
|
|
{ userId: "@user_1:some.domain", prevMembership: Membership.Leave, membership: Membership.Join },
|
|
|
|
{ userId: "@user_1:some.domain", prevMembership: Membership.Join, membership: Membership.Leave },
|
|
|
|
{ userId: "@user_1:some.domain", prevMembership: Membership.Leave, membership: Membership.Join },
|
|
|
|
{ userId: "@user_1:some.domain", prevMembership: Membership.Join, membership: Membership.Leave },
|
|
|
|
{ userId: "@user_1:some.domain", prevMembership: Membership.Leave, membership: Membership.Join },
|
|
|
|
{ userId: "@user_1:some.domain", prevMembership: Membership.Join, membership: Membership.Leave },
|
2017-01-17 11:01:54 +00:00
|
|
|
]);
|
|
|
|
const props = {
|
2017-01-25 10:52:55 +00:00
|
|
|
events: events,
|
|
|
|
children: generateTiles(events),
|
|
|
|
summaryLength: 1,
|
|
|
|
avatarsMaxLength: 5,
|
|
|
|
threshold: 3,
|
2017-01-17 11:01:54 +00:00
|
|
|
};
|
|
|
|
|
2023-02-28 08:58:23 +00:00
|
|
|
const { container } = renderComponent(props);
|
|
|
|
const summary = container.querySelector(".mx_GenericEventListSummary_summary");
|
|
|
|
expect(summary).toHaveTextContent("user_1 joined and left 7 times");
|
2017-01-17 11:01:54 +00:00
|
|
|
});
|
|
|
|
|
2022-12-12 11:24:14 +00:00
|
|
|
it("truncates long join,leave repetitions between other events", function () {
|
2017-01-17 11:01:54 +00:00
|
|
|
const events = generateEvents([
|
2017-01-25 10:52:55 +00:00
|
|
|
{
|
|
|
|
userId: "@user_1:some.domain",
|
2024-03-11 17:16:53 +00:00
|
|
|
prevMembership: Membership.Ban,
|
|
|
|
membership: Membership.Leave,
|
2017-01-25 10:52:55 +00:00
|
|
|
senderId: "@some_other_user:some.domain",
|
|
|
|
},
|
2024-03-11 17:16:53 +00:00
|
|
|
{ userId: "@user_1:some.domain", prevMembership: Membership.Leave, membership: Membership.Join },
|
|
|
|
{ userId: "@user_1:some.domain", prevMembership: Membership.Join, membership: Membership.Leave },
|
|
|
|
{ userId: "@user_1:some.domain", prevMembership: Membership.Leave, membership: Membership.Join },
|
|
|
|
{ userId: "@user_1:some.domain", prevMembership: Membership.Join, membership: Membership.Leave },
|
|
|
|
{ userId: "@user_1:some.domain", prevMembership: Membership.Leave, membership: Membership.Join },
|
|
|
|
{ userId: "@user_1:some.domain", prevMembership: Membership.Join, membership: Membership.Leave },
|
|
|
|
{ userId: "@user_1:some.domain", prevMembership: Membership.Leave, membership: Membership.Join },
|
|
|
|
{ userId: "@user_1:some.domain", prevMembership: Membership.Join, membership: Membership.Leave },
|
|
|
|
{ userId: "@user_1:some.domain", prevMembership: Membership.Leave, membership: Membership.Join },
|
|
|
|
{ userId: "@user_1:some.domain", prevMembership: Membership.Join, membership: Membership.Leave },
|
|
|
|
{ userId: "@user_1:some.domain", prevMembership: Membership.Leave, membership: Membership.Join },
|
|
|
|
{ userId: "@user_1:some.domain", prevMembership: Membership.Join, membership: Membership.Leave },
|
|
|
|
{ userId: "@user_1:some.domain", prevMembership: Membership.Leave, membership: Membership.Join },
|
|
|
|
{ userId: "@user_1:some.domain", prevMembership: Membership.Join, membership: Membership.Leave },
|
2017-01-25 10:52:55 +00:00
|
|
|
{
|
|
|
|
userId: "@user_1:some.domain",
|
2024-03-11 17:16:53 +00:00
|
|
|
prevMembership: Membership.Leave,
|
|
|
|
membership: Membership.Invite,
|
2017-01-25 10:52:55 +00:00
|
|
|
senderId: "@some_other_user:some.domain",
|
|
|
|
},
|
2017-01-17 11:01:54 +00:00
|
|
|
]);
|
|
|
|
const props = {
|
2017-01-25 10:52:55 +00:00
|
|
|
events: events,
|
|
|
|
children: generateTiles(events),
|
|
|
|
summaryLength: 1,
|
|
|
|
avatarsMaxLength: 5,
|
|
|
|
threshold: 3,
|
2017-01-17 11:01:54 +00:00
|
|
|
};
|
|
|
|
|
2023-02-28 08:58:23 +00:00
|
|
|
const { container } = renderComponent(props);
|
|
|
|
const summary = container.querySelector(".mx_GenericEventListSummary_summary");
|
|
|
|
expect(summary).toHaveTextContent("user_1 was unbanned, joined and left 7 times and was invited");
|
2017-01-17 11:01:54 +00:00
|
|
|
});
|
|
|
|
|
2022-12-12 11:24:14 +00:00
|
|
|
it("truncates multiple sequences of repetitions with other events between", function () {
|
2021-04-29 17:57:02 +00:00
|
|
|
const events = generateEvents([
|
2017-01-25 10:52:55 +00:00
|
|
|
{
|
|
|
|
userId: "@user_1:some.domain",
|
2024-03-11 17:16:53 +00:00
|
|
|
prevMembership: Membership.Ban,
|
|
|
|
membership: Membership.Leave,
|
2017-01-25 10:52:55 +00:00
|
|
|
senderId: "@some_other_user:some.domain",
|
|
|
|
},
|
2024-03-11 17:16:53 +00:00
|
|
|
{ userId: "@user_1:some.domain", prevMembership: Membership.Leave, membership: Membership.Join },
|
|
|
|
{ userId: "@user_1:some.domain", prevMembership: Membership.Join, membership: Membership.Leave },
|
|
|
|
{ userId: "@user_1:some.domain", prevMembership: Membership.Leave, membership: Membership.Join },
|
|
|
|
{ userId: "@user_1:some.domain", prevMembership: Membership.Join, membership: Membership.Leave },
|
2017-01-25 10:52:55 +00:00
|
|
|
{
|
|
|
|
userId: "@user_1:some.domain",
|
2024-03-11 17:16:53 +00:00
|
|
|
prevMembership: Membership.Leave,
|
|
|
|
membership: Membership.Ban,
|
2017-01-25 10:52:55 +00:00
|
|
|
senderId: "@some_other_user:some.domain",
|
|
|
|
},
|
2024-03-11 17:16:53 +00:00
|
|
|
{ userId: "@user_1:some.domain", prevMembership: Membership.Ban, membership: Membership.Join },
|
|
|
|
{ userId: "@user_1:some.domain", prevMembership: Membership.Join, membership: Membership.Leave },
|
|
|
|
{ userId: "@user_1:some.domain", prevMembership: Membership.Leave, membership: Membership.Join },
|
|
|
|
{ userId: "@user_1:some.domain", prevMembership: Membership.Join, membership: Membership.Leave },
|
|
|
|
{ userId: "@user_1:some.domain", prevMembership: Membership.Leave, membership: Membership.Join },
|
|
|
|
{ userId: "@user_1:some.domain", prevMembership: Membership.Join, membership: Membership.Leave },
|
2017-01-25 10:52:55 +00:00
|
|
|
{
|
|
|
|
userId: "@user_1:some.domain",
|
2024-03-11 17:16:53 +00:00
|
|
|
prevMembership: Membership.Leave,
|
|
|
|
membership: Membership.Invite,
|
2017-01-25 10:52:55 +00:00
|
|
|
senderId: "@some_other_user:some.domain",
|
|
|
|
},
|
2021-04-29 17:57:02 +00:00
|
|
|
]);
|
|
|
|
const props = {
|
2017-01-25 10:52:55 +00:00
|
|
|
events: events,
|
|
|
|
children: generateTiles(events),
|
|
|
|
summaryLength: 1,
|
|
|
|
avatarsMaxLength: 5,
|
|
|
|
threshold: 3,
|
2021-04-29 17:57:02 +00:00
|
|
|
};
|
2017-01-17 11:01:54 +00:00
|
|
|
|
2023-02-28 08:58:23 +00:00
|
|
|
const { container } = renderComponent(props);
|
|
|
|
const summary = container.querySelector(".mx_GenericEventListSummary_summary");
|
|
|
|
expect(summary).toHaveTextContent(
|
2022-12-12 11:24:14 +00:00
|
|
|
"user_1 was unbanned, joined and left 2 times, was banned, " + "joined and left 3 times and was invited",
|
2021-04-29 17:57:02 +00:00
|
|
|
);
|
|
|
|
});
|
2017-01-17 11:01:54 +00:00
|
|
|
|
2022-12-12 11:24:14 +00:00
|
|
|
it("handles multiple users following the same sequence of memberships", function () {
|
2017-01-17 11:01:54 +00:00
|
|
|
const events = generateEvents([
|
|
|
|
// user_1
|
2017-01-25 10:52:55 +00:00
|
|
|
{
|
|
|
|
userId: "@user_1:some.domain",
|
2024-03-11 17:16:53 +00:00
|
|
|
prevMembership: Membership.Ban,
|
|
|
|
membership: Membership.Leave,
|
2017-01-25 10:52:55 +00:00
|
|
|
senderId: "@some_other_user:some.domain",
|
|
|
|
},
|
2024-03-11 17:16:53 +00:00
|
|
|
{ userId: "@user_1:some.domain", prevMembership: Membership.Leave, membership: Membership.Join },
|
|
|
|
{ userId: "@user_1:some.domain", prevMembership: Membership.Join, membership: Membership.Leave },
|
|
|
|
{ userId: "@user_1:some.domain", prevMembership: Membership.Leave, membership: Membership.Join },
|
|
|
|
{ userId: "@user_1:some.domain", prevMembership: Membership.Join, membership: Membership.Leave },
|
2017-01-25 10:52:55 +00:00
|
|
|
{
|
|
|
|
userId: "@user_1:some.domain",
|
2024-03-11 17:16:53 +00:00
|
|
|
prevMembership: Membership.Leave,
|
|
|
|
membership: Membership.Ban,
|
2017-01-25 10:52:55 +00:00
|
|
|
senderId: "@some_other_user:some.domain",
|
|
|
|
},
|
2017-01-17 11:01:54 +00:00
|
|
|
// user_2
|
2017-01-25 10:52:55 +00:00
|
|
|
{
|
|
|
|
userId: "@user_2:some.domain",
|
2024-03-11 17:16:53 +00:00
|
|
|
prevMembership: Membership.Ban,
|
|
|
|
membership: Membership.Leave,
|
2017-01-25 10:52:55 +00:00
|
|
|
senderId: "@some_other_user:some.domain",
|
|
|
|
},
|
2024-03-11 17:16:53 +00:00
|
|
|
{ userId: "@user_2:some.domain", prevMembership: Membership.Leave, membership: Membership.Join },
|
|
|
|
{ userId: "@user_2:some.domain", prevMembership: Membership.Join, membership: Membership.Leave },
|
|
|
|
{ userId: "@user_2:some.domain", prevMembership: Membership.Leave, membership: Membership.Join },
|
|
|
|
{ userId: "@user_2:some.domain", prevMembership: Membership.Join, membership: Membership.Leave },
|
2017-01-25 10:52:55 +00:00
|
|
|
{
|
|
|
|
userId: "@user_2:some.domain",
|
2024-03-11 17:16:53 +00:00
|
|
|
prevMembership: Membership.Leave,
|
|
|
|
membership: Membership.Ban,
|
2017-01-25 10:52:55 +00:00
|
|
|
senderId: "@some_other_user:some.domain",
|
|
|
|
},
|
2017-01-17 11:01:54 +00:00
|
|
|
]);
|
|
|
|
const props = {
|
2017-01-25 10:52:55 +00:00
|
|
|
events: events,
|
|
|
|
children: generateTiles(events),
|
|
|
|
summaryLength: 1,
|
|
|
|
avatarsMaxLength: 5,
|
|
|
|
threshold: 3,
|
2017-01-17 11:01:54 +00:00
|
|
|
};
|
|
|
|
|
2023-02-28 08:58:23 +00:00
|
|
|
const { container } = renderComponent(props);
|
|
|
|
const summary = container.querySelector(".mx_GenericEventListSummary_summary");
|
|
|
|
expect(summary).toHaveTextContent(
|
|
|
|
"user_1 and one other were unbanned, joined and left 2 times and were banned",
|
|
|
|
);
|
2017-01-17 11:01:54 +00:00
|
|
|
});
|
|
|
|
|
2022-12-12 11:24:14 +00:00
|
|
|
it("handles many users following the same sequence of memberships", function () {
|
2017-01-17 11:01:54 +00:00
|
|
|
const events = generateEventsForUsers("@user_$:some.domain", 20, [
|
2017-01-25 10:52:55 +00:00
|
|
|
{
|
2024-03-11 17:16:53 +00:00
|
|
|
prevMembership: Membership.Ban,
|
|
|
|
membership: Membership.Leave,
|
2017-01-25 10:52:55 +00:00
|
|
|
senderId: "@some_other_user:some.domain",
|
|
|
|
},
|
2024-03-11 17:16:53 +00:00
|
|
|
{ prevMembership: Membership.Leave, membership: Membership.Join },
|
|
|
|
{ prevMembership: Membership.Join, membership: Membership.Leave },
|
|
|
|
{ prevMembership: Membership.Leave, membership: Membership.Join },
|
|
|
|
{ prevMembership: Membership.Join, membership: Membership.Leave },
|
2017-01-25 10:52:55 +00:00
|
|
|
{
|
2024-03-11 17:16:53 +00:00
|
|
|
prevMembership: Membership.Leave,
|
|
|
|
membership: Membership.Ban,
|
2017-01-25 10:52:55 +00:00
|
|
|
senderId: "@some_other_user:some.domain",
|
|
|
|
},
|
2017-01-17 11:01:54 +00:00
|
|
|
]);
|
|
|
|
const props = {
|
2017-01-25 10:52:55 +00:00
|
|
|
events: events,
|
|
|
|
children: generateTiles(events),
|
|
|
|
summaryLength: 1,
|
|
|
|
avatarsMaxLength: 5,
|
|
|
|
threshold: 3,
|
2017-01-17 11:01:54 +00:00
|
|
|
};
|
|
|
|
|
2023-02-28 08:58:23 +00:00
|
|
|
const { container } = renderComponent(props);
|
|
|
|
const summary = container.querySelector(".mx_GenericEventListSummary_summary");
|
|
|
|
expect(summary).toHaveTextContent(
|
|
|
|
"user_0 and 19 others were unbanned, joined and left 2 times and were banned",
|
|
|
|
);
|
2017-01-17 11:01:54 +00:00
|
|
|
});
|
|
|
|
|
2022-12-12 11:24:14 +00:00
|
|
|
it("correctly orders sequences of transitions by the order of their first event", function () {
|
2021-04-29 17:57:02 +00:00
|
|
|
const events = generateEvents([
|
2017-01-25 10:52:55 +00:00
|
|
|
{
|
|
|
|
userId: "@user_2:some.domain",
|
2024-03-11 17:16:53 +00:00
|
|
|
prevMembership: Membership.Ban,
|
|
|
|
membership: Membership.Leave,
|
2017-01-25 10:52:55 +00:00
|
|
|
senderId: "@some_other_user:some.domain",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
userId: "@user_1:some.domain",
|
2024-03-11 17:16:53 +00:00
|
|
|
prevMembership: Membership.Ban,
|
|
|
|
membership: Membership.Leave,
|
2017-01-25 10:52:55 +00:00
|
|
|
senderId: "@some_other_user:some.domain",
|
|
|
|
},
|
2024-03-11 17:16:53 +00:00
|
|
|
{ userId: "@user_1:some.domain", prevMembership: Membership.Leave, membership: Membership.Join },
|
|
|
|
{ userId: "@user_1:some.domain", prevMembership: Membership.Join, membership: Membership.Leave },
|
|
|
|
{ userId: "@user_1:some.domain", prevMembership: Membership.Leave, membership: Membership.Join },
|
|
|
|
{ userId: "@user_1:some.domain", prevMembership: Membership.Join, membership: Membership.Leave },
|
2017-01-25 10:52:55 +00:00
|
|
|
{
|
|
|
|
userId: "@user_1:some.domain",
|
2024-03-11 17:16:53 +00:00
|
|
|
prevMembership: Membership.Leave,
|
|
|
|
membership: Membership.Ban,
|
2017-01-25 10:52:55 +00:00
|
|
|
senderId: "@some_other_user:some.domain",
|
|
|
|
},
|
2024-03-11 17:16:53 +00:00
|
|
|
{ userId: "@user_2:some.domain", prevMembership: Membership.Leave, membership: Membership.Join },
|
|
|
|
{ userId: "@user_2:some.domain", prevMembership: Membership.Join, membership: Membership.Leave },
|
|
|
|
{ userId: "@user_2:some.domain", prevMembership: Membership.Leave, membership: Membership.Join },
|
|
|
|
{ userId: "@user_2:some.domain", prevMembership: Membership.Join, membership: Membership.Leave },
|
2021-04-29 17:57:02 +00:00
|
|
|
]);
|
|
|
|
const props = {
|
2017-01-25 10:52:55 +00:00
|
|
|
events: events,
|
|
|
|
children: generateTiles(events),
|
|
|
|
summaryLength: 1,
|
|
|
|
avatarsMaxLength: 5,
|
|
|
|
threshold: 3,
|
2021-04-29 17:57:02 +00:00
|
|
|
};
|
2017-01-17 11:01:54 +00:00
|
|
|
|
2023-02-28 08:58:23 +00:00
|
|
|
const { container } = renderComponent(props);
|
|
|
|
const summary = container.querySelector(".mx_GenericEventListSummary_summary");
|
|
|
|
expect(summary).toHaveTextContent(
|
2021-04-29 17:57:02 +00:00
|
|
|
"user_2 was unbanned and joined and left 2 times, user_1 was unbanned, " +
|
2022-12-12 11:24:14 +00:00
|
|
|
"joined and left 2 times and was banned",
|
2021-04-29 17:57:02 +00:00
|
|
|
);
|
|
|
|
});
|
2017-01-17 11:01:54 +00:00
|
|
|
|
2022-12-12 11:24:14 +00:00
|
|
|
it("correctly identifies transitions", function () {
|
2017-01-17 11:01:54 +00:00
|
|
|
const events = generateEvents([
|
|
|
|
// invited
|
2024-03-11 17:16:53 +00:00
|
|
|
{ userId: "@user_1:some.domain", membership: Membership.Invite },
|
2017-01-17 11:01:54 +00:00
|
|
|
// banned
|
2024-03-11 17:16:53 +00:00
|
|
|
{ userId: "@user_1:some.domain", membership: Membership.Ban },
|
2017-01-17 11:01:54 +00:00
|
|
|
// joined
|
2024-03-11 17:16:53 +00:00
|
|
|
{ userId: "@user_1:some.domain", membership: Membership.Join },
|
2017-01-17 11:01:54 +00:00
|
|
|
// invite_reject
|
2017-01-25 10:52:55 +00:00
|
|
|
{
|
|
|
|
userId: "@user_1:some.domain",
|
2024-03-11 17:16:53 +00:00
|
|
|
prevMembership: Membership.Invite,
|
|
|
|
membership: Membership.Leave,
|
2017-01-25 10:52:55 +00:00
|
|
|
},
|
2017-01-17 11:01:54 +00:00
|
|
|
// left
|
2024-03-11 17:16:53 +00:00
|
|
|
{ userId: "@user_1:some.domain", prevMembership: Membership.Join, membership: Membership.Leave },
|
2017-01-17 11:01:54 +00:00
|
|
|
// invite_withdrawal
|
2017-01-25 10:52:55 +00:00
|
|
|
{
|
|
|
|
userId: "@user_1:some.domain",
|
2024-03-11 17:16:53 +00:00
|
|
|
prevMembership: Membership.Invite,
|
|
|
|
membership: Membership.Leave,
|
2017-01-25 10:52:55 +00:00
|
|
|
senderId: "@some_other_user:some.domain",
|
|
|
|
},
|
2017-01-17 11:01:54 +00:00
|
|
|
// unbanned
|
2017-01-25 10:52:55 +00:00
|
|
|
{
|
|
|
|
userId: "@user_1:some.domain",
|
2024-03-11 17:16:53 +00:00
|
|
|
prevMembership: Membership.Ban,
|
|
|
|
membership: Membership.Leave,
|
2017-01-25 10:52:55 +00:00
|
|
|
senderId: "@some_other_user:some.domain",
|
|
|
|
},
|
2017-01-17 11:01:54 +00:00
|
|
|
// kicked
|
2017-01-25 10:52:55 +00:00
|
|
|
{
|
|
|
|
userId: "@user_1:some.domain",
|
2024-03-11 17:16:53 +00:00
|
|
|
prevMembership: Membership.Join,
|
|
|
|
membership: Membership.Leave,
|
2017-01-25 10:52:55 +00:00
|
|
|
senderId: "@some_other_user:some.domain",
|
|
|
|
},
|
2019-07-10 20:58:08 +00:00
|
|
|
// default for sender=target (leave)
|
|
|
|
{
|
|
|
|
userId: "@user_1:some.domain",
|
2024-03-11 17:16:53 +00:00
|
|
|
prevMembership: "????" as Membership,
|
|
|
|
membership: Membership.Leave,
|
2019-07-10 20:58:08 +00:00
|
|
|
senderId: "@user_1:some.domain",
|
|
|
|
},
|
|
|
|
// default for sender<>target (kicked)
|
2017-01-25 10:52:55 +00:00
|
|
|
{
|
|
|
|
userId: "@user_1:some.domain",
|
2024-03-11 17:16:53 +00:00
|
|
|
prevMembership: "????" as Membership,
|
|
|
|
membership: Membership.Leave,
|
2017-01-25 10:52:55 +00:00
|
|
|
senderId: "@some_other_user:some.domain",
|
|
|
|
},
|
2017-01-17 11:01:54 +00:00
|
|
|
]);
|
|
|
|
const props = {
|
2017-01-25 10:52:55 +00:00
|
|
|
events: events,
|
|
|
|
children: generateTiles(events),
|
|
|
|
summaryLength: 1,
|
|
|
|
avatarsMaxLength: 5,
|
|
|
|
threshold: 3,
|
2017-01-17 11:01:54 +00:00
|
|
|
};
|
|
|
|
|
2023-02-28 08:58:23 +00:00
|
|
|
const { container } = renderComponent(props);
|
|
|
|
const summary = container.querySelector(".mx_GenericEventListSummary_summary");
|
|
|
|
expect(summary).toHaveTextContent(
|
2017-01-25 10:52:55 +00:00
|
|
|
"user_1 was invited, was banned, joined, rejected their invitation, left, " +
|
2022-12-12 11:24:14 +00:00
|
|
|
"had their invitation withdrawn, was unbanned, was removed, left and was removed",
|
2017-01-17 11:01:54 +00:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2022-12-12 11:24:14 +00:00
|
|
|
it("handles invitation plurals correctly when there are multiple users", function () {
|
2017-01-17 11:01:54 +00:00
|
|
|
const events = generateEvents([
|
2017-01-25 10:52:55 +00:00
|
|
|
{
|
|
|
|
userId: "@user_1:some.domain",
|
2024-03-11 17:16:53 +00:00
|
|
|
prevMembership: Membership.Invite,
|
|
|
|
membership: Membership.Leave,
|
2017-01-25 10:52:55 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
userId: "@user_1:some.domain",
|
2024-03-11 17:16:53 +00:00
|
|
|
prevMembership: Membership.Invite,
|
|
|
|
membership: Membership.Leave,
|
2017-01-25 10:52:55 +00:00
|
|
|
senderId: "@some_other_user:some.domain",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
userId: "@user_2:some.domain",
|
2024-03-11 17:16:53 +00:00
|
|
|
prevMembership: Membership.Invite,
|
|
|
|
membership: Membership.Leave,
|
2017-01-25 10:52:55 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
userId: "@user_2:some.domain",
|
2024-03-11 17:16:53 +00:00
|
|
|
prevMembership: Membership.Invite,
|
|
|
|
membership: Membership.Leave,
|
2017-01-25 10:52:55 +00:00
|
|
|
senderId: "@some_other_user:some.domain",
|
|
|
|
},
|
2017-01-17 11:01:54 +00:00
|
|
|
]);
|
|
|
|
const props = {
|
2017-01-25 10:52:55 +00:00
|
|
|
events: events,
|
|
|
|
children: generateTiles(events),
|
|
|
|
summaryLength: 1,
|
|
|
|
avatarsMaxLength: 5,
|
|
|
|
threshold: 3,
|
2017-01-17 11:01:54 +00:00
|
|
|
};
|
|
|
|
|
2023-02-28 08:58:23 +00:00
|
|
|
const { container } = renderComponent(props);
|
|
|
|
const summary = container.querySelector(".mx_GenericEventListSummary_summary");
|
|
|
|
expect(summary).toHaveTextContent(
|
|
|
|
"user_1 and one other rejected their invitations and had their invitations withdrawn",
|
|
|
|
);
|
2017-01-17 11:01:54 +00:00
|
|
|
});
|
|
|
|
|
2022-12-12 11:24:14 +00:00
|
|
|
it("handles invitation plurals correctly when there are multiple invites", function () {
|
2021-04-29 17:57:02 +00:00
|
|
|
const events = generateEvents([
|
2017-01-25 10:52:55 +00:00
|
|
|
{
|
|
|
|
userId: "@user_1:some.domain",
|
2024-03-11 17:16:53 +00:00
|
|
|
prevMembership: Membership.Invite,
|
|
|
|
membership: Membership.Leave,
|
2017-01-25 10:52:55 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
userId: "@user_1:some.domain",
|
2024-03-11 17:16:53 +00:00
|
|
|
prevMembership: Membership.Invite,
|
|
|
|
membership: Membership.Leave,
|
2017-01-25 10:52:55 +00:00
|
|
|
},
|
2021-04-29 17:57:02 +00:00
|
|
|
]);
|
|
|
|
const props = {
|
2017-01-25 10:52:55 +00:00
|
|
|
events: events,
|
|
|
|
children: generateTiles(events),
|
|
|
|
summaryLength: 1,
|
|
|
|
avatarsMaxLength: 5,
|
|
|
|
threshold: 1, // threshold = 1 to force collapse
|
2021-04-29 17:57:02 +00:00
|
|
|
};
|
2017-01-17 11:01:54 +00:00
|
|
|
|
2023-02-28 08:58:23 +00:00
|
|
|
const { container } = renderComponent(props);
|
|
|
|
const summary = container.querySelector(".mx_GenericEventListSummary_summary");
|
|
|
|
expect(summary).toHaveTextContent("user_1 rejected their invitation 2 times");
|
2021-04-29 17:57:02 +00:00
|
|
|
});
|
2017-01-17 11:01:54 +00:00
|
|
|
|
2022-12-12 11:24:14 +00:00
|
|
|
it('handles a summary length = 2, with no "others"', function () {
|
2017-01-17 11:01:54 +00:00
|
|
|
const events = generateEvents([
|
2024-03-11 17:16:53 +00:00
|
|
|
{ userId: "@user_1:some.domain", membership: Membership.Join },
|
|
|
|
{ userId: "@user_1:some.domain", membership: Membership.Join },
|
|
|
|
{ userId: "@user_2:some.domain", membership: Membership.Join },
|
|
|
|
{ userId: "@user_2:some.domain", membership: Membership.Join },
|
2017-01-17 11:01:54 +00:00
|
|
|
]);
|
|
|
|
const props = {
|
2017-01-25 10:52:55 +00:00
|
|
|
events: events,
|
|
|
|
children: generateTiles(events),
|
|
|
|
summaryLength: 2,
|
|
|
|
avatarsMaxLength: 5,
|
|
|
|
threshold: 3,
|
2017-01-17 11:01:54 +00:00
|
|
|
};
|
|
|
|
|
2023-02-28 08:58:23 +00:00
|
|
|
const { container } = renderComponent(props);
|
|
|
|
const summary = container.querySelector(".mx_GenericEventListSummary_summary");
|
|
|
|
expect(summary).toHaveTextContent("user_1 and user_2 joined 2 times");
|
2017-01-17 11:01:54 +00:00
|
|
|
});
|
|
|
|
|
2022-12-12 11:24:14 +00:00
|
|
|
it('handles a summary length = 2, with 1 "other"', function () {
|
2017-01-17 11:01:54 +00:00
|
|
|
const events = generateEvents([
|
2024-03-11 17:16:53 +00:00
|
|
|
{ userId: "@user_1:some.domain", membership: Membership.Join },
|
|
|
|
{ userId: "@user_2:some.domain", membership: Membership.Join },
|
|
|
|
{ userId: "@user_3:some.domain", membership: Membership.Join },
|
2017-01-17 11:01:54 +00:00
|
|
|
]);
|
|
|
|
const props = {
|
2017-01-25 10:52:55 +00:00
|
|
|
events: events,
|
|
|
|
children: generateTiles(events),
|
|
|
|
summaryLength: 2,
|
|
|
|
avatarsMaxLength: 5,
|
|
|
|
threshold: 3,
|
2017-01-17 11:01:54 +00:00
|
|
|
};
|
|
|
|
|
2023-02-28 08:58:23 +00:00
|
|
|
const { container } = renderComponent(props);
|
|
|
|
const summary = container.querySelector(".mx_GenericEventListSummary_summary");
|
|
|
|
expect(summary).toHaveTextContent("user_1, user_2 and one other joined");
|
2017-01-17 11:01:54 +00:00
|
|
|
});
|
|
|
|
|
2022-12-12 11:24:14 +00:00
|
|
|
it('handles a summary length = 2, with many "others"', function () {
|
2024-03-11 17:16:53 +00:00
|
|
|
const events = generateEventsForUsers("@user_$:some.domain", 20, [{ membership: Membership.Join }]);
|
2017-01-17 11:01:54 +00:00
|
|
|
const props = {
|
2017-01-25 10:52:55 +00:00
|
|
|
events: events,
|
|
|
|
children: generateTiles(events),
|
|
|
|
summaryLength: 2,
|
|
|
|
avatarsMaxLength: 5,
|
|
|
|
threshold: 3,
|
2017-01-17 11:01:54 +00:00
|
|
|
};
|
|
|
|
|
2023-02-28 08:58:23 +00:00
|
|
|
const { container } = renderComponent(props);
|
|
|
|
const summary = container.querySelector(".mx_GenericEventListSummary_summary");
|
|
|
|
expect(summary).toHaveTextContent("user_0, user_1 and 18 others joined");
|
2017-01-17 11:01:54 +00:00
|
|
|
});
|
2023-02-07 10:09:46 +00:00
|
|
|
|
|
|
|
it("should not blindly group 3pid invites and treat them as distinct users instead", () => {
|
|
|
|
const events = [
|
|
|
|
mkEvent({
|
|
|
|
event: true,
|
|
|
|
skey: "randomstring1",
|
|
|
|
user: "@user1:server",
|
|
|
|
type: "m.room.third_party_invite",
|
|
|
|
content: {
|
|
|
|
display_name: "n...@d...",
|
|
|
|
key_validity_url: "https://blah",
|
|
|
|
public_key: "public_key",
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
mkEvent({
|
|
|
|
event: true,
|
|
|
|
skey: "randomstring2",
|
|
|
|
user: "@user1:server",
|
|
|
|
type: "m.room.third_party_invite",
|
|
|
|
content: {
|
|
|
|
display_name: "n...@d...",
|
|
|
|
key_validity_url: "https://blah",
|
|
|
|
public_key: "public_key",
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
mkEvent({
|
|
|
|
event: true,
|
|
|
|
skey: "randomstring3",
|
|
|
|
user: "@user1:server",
|
|
|
|
type: "m.room.third_party_invite",
|
|
|
|
content: {
|
|
|
|
display_name: "d...@w...",
|
|
|
|
key_validity_url: "https://blah",
|
|
|
|
public_key: "public_key",
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
];
|
|
|
|
|
|
|
|
const props = {
|
|
|
|
events: events,
|
|
|
|
children: generateTiles(events),
|
|
|
|
summaryLength: 2,
|
|
|
|
avatarsMaxLength: 5,
|
|
|
|
threshold: 3,
|
|
|
|
};
|
|
|
|
|
2023-02-28 08:58:23 +00:00
|
|
|
const { container } = renderComponent(props);
|
|
|
|
const summary = container.querySelector(".mx_GenericEventListSummary_summary");
|
|
|
|
expect(summary).toHaveTextContent("n...@d... was invited 2 times, d...@w... was invited");
|
2023-02-07 10:09:46 +00:00
|
|
|
});
|
2017-01-25 10:52:55 +00:00
|
|
|
});
|