2022-05-06 17:09:28 +08: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.
|
|
|
|
*/
|
|
|
|
|
2018-02-07 01:50:53 +08:00
|
|
|
import React from "react";
|
2022-08-02 21:10:43 +08:00
|
|
|
// eslint-disable-next-line deprecate/import
|
2022-05-04 22:37:41 +08:00
|
|
|
import { mount, ReactWrapper } from "enzyme";
|
|
|
|
import { MatrixEvent, RoomMember } from "matrix-js-sdk/src/matrix";
|
|
|
|
|
|
|
|
import {
|
|
|
|
getMockClientWithEventEmitter,
|
|
|
|
mkMembership,
|
|
|
|
mockClientMethodsUser,
|
|
|
|
unmockClientPeg,
|
|
|
|
} from "../../../test-utils";
|
|
|
|
import EventListSummary from "../../../../src/components/views/elements/EventListSummary";
|
|
|
|
import { Layout } from "../../../../src/settings/enums/Layout";
|
|
|
|
import MatrixClientContext from "../../../../src/contexts/MatrixClientContext";
|
2017-01-17 19:01:54 +08:00
|
|
|
|
2022-02-09 18:51:12 +08:00
|
|
|
describe("EventListSummary", function () {
|
2022-05-04 22:37:41 +08:00
|
|
|
const roomId = "!room:server.org";
|
2017-01-18 18:53:17 +08:00
|
|
|
// Generate dummy event tiles for use in simulating an expanded MELS
|
2022-05-04 22:37:41 +08:00
|
|
|
const generateTiles = (events: MatrixEvent[]) => {
|
2017-01-17 19:01:54 +08:00
|
|
|
return events.map((e) => {
|
|
|
|
return (
|
|
|
|
<div key={e.getId()} className="event_tile">
|
|
|
|
Expanded membership
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2017-01-18 18:53:17 +08:00
|
|
|
/**
|
2017-01-25 18:52:55 +08:00
|
|
|
* Generates a membership event with the target of the event set as a mocked
|
|
|
|
* RoomMember based on `parameters.userId`.
|
2017-01-18 18:53:17 +08:00
|
|
|
* @param {string} eventId the ID of the event.
|
|
|
|
* @param {object} parameters the parameters to use to create the event.
|
2017-01-25 18:52:55 +08:00
|
|
|
* @param {string} parameters.membership the membership to assign to
|
|
|
|
* `content.membership`
|
2017-01-18 18:53:17 +08: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 18:52:55 +08:00
|
|
|
* @param {string} parameters.senderId the user ID of the sender of the event.
|
|
|
|
* Optional. Defaults to `parameters.userId`.
|
2017-01-18 18:53:17 +08:00
|
|
|
* @returns {MatrixEvent} the event created.
|
|
|
|
*/
|
2022-05-04 22:37:41 +08:00
|
|
|
interface MembershipEventParams {
|
|
|
|
senderId?: string;
|
|
|
|
userId: string;
|
|
|
|
membership: string;
|
|
|
|
prevMembership?: string;
|
|
|
|
}
|
|
|
|
const generateMembershipEvent = (
|
|
|
|
eventId: string,
|
|
|
|
{ senderId, userId, membership, prevMembership }: MembershipEventParams,
|
|
|
|
): MatrixEvent => {
|
|
|
|
const member = new RoomMember(roomId, userId);
|
|
|
|
// Use localpart as display name;
|
|
|
|
member.name = userId.match(/@([^:]*):/)[1];
|
|
|
|
jest.spyOn(member, "getAvatarUrl").mockReturnValue("avatar.jpeg");
|
|
|
|
jest.spyOn(member, "getMxcAvatarUrl").mockReturnValue("mxc://avatar.url/image.png");
|
|
|
|
const e = mkMembership({
|
2017-01-18 18:53:17 +08:00
|
|
|
event: true,
|
2022-05-04 22:37:41 +08:00
|
|
|
room: roomId,
|
|
|
|
user: senderId || userId,
|
|
|
|
skey: userId,
|
|
|
|
mship: membership,
|
|
|
|
prevMship: prevMembership,
|
|
|
|
target: member,
|
2017-01-18 18:53:17 +08:00
|
|
|
});
|
2017-01-25 18:52:55 +08:00
|
|
|
// Override random event ID to allow for equality tests against tiles from
|
|
|
|
// generateTiles
|
2017-01-18 18:53:17 +08:00
|
|
|
e.event.event_id = eventId;
|
|
|
|
return e;
|
2017-01-17 19:01:54 +08:00
|
|
|
};
|
|
|
|
|
2017-01-18 18:53:17 +08:00
|
|
|
// Generate mock MatrixEvents from the array of parameters
|
2022-05-04 22:37:41 +08:00
|
|
|
const generateEvents = (parameters: MembershipEventParams[]) => {
|
2017-01-17 19:01:54 +08:00
|
|
|
const res = [];
|
|
|
|
for (let i = 0; i < parameters.length; i++) {
|
|
|
|
res.push(generateMembershipEvent(`event${i}`, parameters[i]));
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
};
|
|
|
|
|
2017-01-18 18:53:17 +08: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`.
|
2017-01-17 19:01:54 +08:00
|
|
|
const generateEventsForUsers = (userIdTemplate, n, events) => {
|
|
|
|
let eventsForUsers = [];
|
|
|
|
let userId = "";
|
|
|
|
for (let i = 0; i < n; i++) {
|
|
|
|
userId = userIdTemplate.replace("$", i);
|
|
|
|
events.forEach((e) => {
|
|
|
|
e.userId = userId;
|
|
|
|
});
|
|
|
|
eventsForUsers = eventsForUsers.concat(generateEvents(events));
|
|
|
|
}
|
|
|
|
return eventsForUsers;
|
|
|
|
};
|
|
|
|
|
2022-05-04 22:37:41 +08:00
|
|
|
const mockClient = getMockClientWithEventEmitter({
|
|
|
|
...mockClientMethodsUser(),
|
|
|
|
});
|
|
|
|
|
|
|
|
const defaultProps = {
|
|
|
|
layout: Layout.Bubble,
|
|
|
|
events: [],
|
|
|
|
children: [],
|
|
|
|
};
|
|
|
|
const renderComponent = (props = {}): ReactWrapper => {
|
|
|
|
return mount(
|
|
|
|
<MatrixClientContext.Provider value={mockClient}>
|
|
|
|
<EventListSummary {...defaultProps} {...props} />
|
|
|
|
</MatrixClientContext.Provider>,
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2019-12-17 19:47:01 +08:00
|
|
|
beforeEach(function () {
|
2022-05-04 22:37:41 +08:00
|
|
|
jest.clearAllMocks();
|
|
|
|
});
|
|
|
|
|
|
|
|
afterAll(() => {
|
|
|
|
unmockClientPeg();
|
2017-01-17 19:01:54 +08:00
|
|
|
});
|
|
|
|
|
2017-01-18 19:03:38 +08:00
|
|
|
it("renders expanded events if there are less than props.threshold", function () {
|
2021-06-29 20:11:58 +08:00
|
|
|
const events = generateEvents([{ userId: "@user_1:some.domain", prevMembership: "leave", membership: "join" }]);
|
2017-01-17 19:01:54 +08:00
|
|
|
const props = {
|
2017-01-25 18:52:55 +08:00
|
|
|
events: events,
|
|
|
|
children: generateTiles(events),
|
|
|
|
summaryLength: 1,
|
|
|
|
avatarsMaxLength: 5,
|
|
|
|
threshold: 3,
|
2017-01-17 19:01:54 +08:00
|
|
|
};
|
|
|
|
|
2022-05-04 22:37:41 +08:00
|
|
|
const wrapper = renderComponent(props); // matrix cli context wrapper
|
2017-01-17 19:01:54 +08:00
|
|
|
|
2022-05-04 22:37:41 +08:00
|
|
|
expect(wrapper.find("GenericEventListSummary").props().children).toEqual([
|
2021-08-04 00:07:37 +08:00
|
|
|
<div className="event_tile" key="event0">
|
|
|
|
Expanded membership
|
|
|
|
</div>,
|
2017-01-17 19:01:54 +08:00
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
2017-01-18 19:03:38 +08:00
|
|
|
it("renders expanded events if there are less than props.threshold", function () {
|
2017-01-17 19:01:54 +08:00
|
|
|
const events = generateEvents([
|
2021-06-29 20:11:58 +08:00
|
|
|
{ userId: "@user_1:some.domain", prevMembership: "leave", membership: "join" },
|
|
|
|
{ userId: "@user_1:some.domain", prevMembership: "join", membership: "leave" },
|
2017-01-17 19:01:54 +08:00
|
|
|
]);
|
|
|
|
const props = {
|
2017-01-25 18:52:55 +08:00
|
|
|
events: events,
|
|
|
|
children: generateTiles(events),
|
|
|
|
summaryLength: 1,
|
|
|
|
avatarsMaxLength: 5,
|
|
|
|
threshold: 3,
|
2017-01-17 19:01:54 +08:00
|
|
|
};
|
|
|
|
|
2022-05-04 22:37:41 +08:00
|
|
|
const wrapper = renderComponent(props); // matrix cli context wrapper
|
2017-01-17 19:01:54 +08:00
|
|
|
|
2022-05-04 22:37:41 +08:00
|
|
|
expect(wrapper.find("GenericEventListSummary").props().children).toEqual([
|
2021-08-04 00:07:37 +08:00
|
|
|
<div className="event_tile" key="event0">
|
|
|
|
Expanded membership
|
|
|
|
</div>,
|
|
|
|
<div className="event_tile" key="event1">
|
|
|
|
Expanded membership
|
|
|
|
</div>,
|
2017-01-17 19:01:54 +08:00
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
2017-01-18 19:03:38 +08:00
|
|
|
it("renders collapsed events if events.length = props.threshold", function () {
|
2017-01-17 19:01:54 +08:00
|
|
|
const events = generateEvents([
|
2021-06-29 20:11:58 +08:00
|
|
|
{ userId: "@user_1:some.domain", prevMembership: "leave", membership: "join" },
|
|
|
|
{ userId: "@user_1:some.domain", prevMembership: "join", membership: "leave" },
|
|
|
|
{ userId: "@user_1:some.domain", prevMembership: "leave", membership: "join" },
|
2017-01-17 19:01:54 +08:00
|
|
|
]);
|
|
|
|
const props = {
|
2017-01-25 18:52:55 +08:00
|
|
|
events: events,
|
|
|
|
children: generateTiles(events),
|
|
|
|
summaryLength: 1,
|
|
|
|
avatarsMaxLength: 5,
|
|
|
|
threshold: 3,
|
2017-01-17 19:01:54 +08:00
|
|
|
};
|
|
|
|
|
2022-05-04 22:37:41 +08:00
|
|
|
const wrapper = renderComponent(props);
|
|
|
|
const summary = wrapper.find(".mx_GenericEventListSummary_summary");
|
|
|
|
const summaryText = summary.text();
|
2017-01-17 19:01:54 +08:00
|
|
|
|
|
|
|
expect(summaryText).toBe("user_1 joined and left and joined");
|
|
|
|
});
|
|
|
|
|
2017-01-18 19:03:38 +08:00
|
|
|
it("truncates long join,leave repetitions", function () {
|
2017-01-17 19:01:54 +08:00
|
|
|
const events = generateEvents([
|
2021-06-29 20:11:58 +08:00
|
|
|
{ userId: "@user_1:some.domain", prevMembership: "leave", membership: "join" },
|
|
|
|
{ userId: "@user_1:some.domain", prevMembership: "join", membership: "leave" },
|
|
|
|
{ userId: "@user_1:some.domain", prevMembership: "leave", membership: "join" },
|
|
|
|
{ userId: "@user_1:some.domain", prevMembership: "join", membership: "leave" },
|
|
|
|
{ userId: "@user_1:some.domain", prevMembership: "leave", membership: "join" },
|
|
|
|
{ userId: "@user_1:some.domain", prevMembership: "join", membership: "leave" },
|
|
|
|
{ userId: "@user_1:some.domain", prevMembership: "leave", membership: "join" },
|
|
|
|
{ userId: "@user_1:some.domain", prevMembership: "join", membership: "leave" },
|
|
|
|
{ userId: "@user_1:some.domain", prevMembership: "leave", membership: "join" },
|
|
|
|
{ userId: "@user_1:some.domain", prevMembership: "join", membership: "leave" },
|
|
|
|
{ userId: "@user_1:some.domain", prevMembership: "leave", membership: "join" },
|
|
|
|
{ userId: "@user_1:some.domain", prevMembership: "join", membership: "leave" },
|
|
|
|
{ userId: "@user_1:some.domain", prevMembership: "leave", membership: "join" },
|
|
|
|
{ userId: "@user_1:some.domain", prevMembership: "join", membership: "leave" },
|
2017-01-17 19:01:54 +08:00
|
|
|
]);
|
|
|
|
const props = {
|
2017-01-25 18:52:55 +08:00
|
|
|
events: events,
|
|
|
|
children: generateTiles(events),
|
|
|
|
summaryLength: 1,
|
|
|
|
avatarsMaxLength: 5,
|
|
|
|
threshold: 3,
|
2017-01-17 19:01:54 +08:00
|
|
|
};
|
|
|
|
|
2022-05-04 22:37:41 +08:00
|
|
|
const wrapper = renderComponent(props);
|
|
|
|
const summary = wrapper.find(".mx_GenericEventListSummary_summary");
|
|
|
|
const summaryText = summary.text();
|
2017-01-17 19:01:54 +08:00
|
|
|
|
|
|
|
expect(summaryText).toBe("user_1 joined and left 7 times");
|
|
|
|
});
|
|
|
|
|
2017-01-25 18:52:55 +08:00
|
|
|
it("truncates long join,leave repetitions between other events", function () {
|
2017-01-17 19:01:54 +08:00
|
|
|
const events = generateEvents([
|
2017-01-25 18:52:55 +08:00
|
|
|
{
|
|
|
|
userId: "@user_1:some.domain",
|
|
|
|
prevMembership: "ban",
|
|
|
|
membership: "leave",
|
|
|
|
senderId: "@some_other_user:some.domain",
|
|
|
|
},
|
2021-06-29 20:11:58 +08:00
|
|
|
{ userId: "@user_1:some.domain", prevMembership: "leave", membership: "join" },
|
|
|
|
{ userId: "@user_1:some.domain", prevMembership: "join", membership: "leave" },
|
|
|
|
{ userId: "@user_1:some.domain", prevMembership: "leave", membership: "join" },
|
|
|
|
{ userId: "@user_1:some.domain", prevMembership: "join", membership: "leave" },
|
|
|
|
{ userId: "@user_1:some.domain", prevMembership: "leave", membership: "join" },
|
|
|
|
{ userId: "@user_1:some.domain", prevMembership: "join", membership: "leave" },
|
|
|
|
{ userId: "@user_1:some.domain", prevMembership: "leave", membership: "join" },
|
|
|
|
{ userId: "@user_1:some.domain", prevMembership: "join", membership: "leave" },
|
|
|
|
{ userId: "@user_1:some.domain", prevMembership: "leave", membership: "join" },
|
|
|
|
{ userId: "@user_1:some.domain", prevMembership: "join", membership: "leave" },
|
|
|
|
{ userId: "@user_1:some.domain", prevMembership: "leave", membership: "join" },
|
|
|
|
{ userId: "@user_1:some.domain", prevMembership: "join", membership: "leave" },
|
|
|
|
{ userId: "@user_1:some.domain", prevMembership: "leave", membership: "join" },
|
|
|
|
{ userId: "@user_1:some.domain", prevMembership: "join", membership: "leave" },
|
2017-01-25 18:52:55 +08:00
|
|
|
{
|
|
|
|
userId: "@user_1:some.domain",
|
|
|
|
prevMembership: "leave",
|
|
|
|
membership: "invite",
|
|
|
|
senderId: "@some_other_user:some.domain",
|
|
|
|
},
|
2017-01-17 19:01:54 +08:00
|
|
|
]);
|
|
|
|
const props = {
|
2017-01-25 18:52:55 +08:00
|
|
|
events: events,
|
|
|
|
children: generateTiles(events),
|
|
|
|
summaryLength: 1,
|
|
|
|
avatarsMaxLength: 5,
|
|
|
|
threshold: 3,
|
2017-01-17 19:01:54 +08:00
|
|
|
};
|
|
|
|
|
2022-05-04 22:37:41 +08:00
|
|
|
const wrapper = renderComponent(props);
|
|
|
|
const summary = wrapper.find(".mx_GenericEventListSummary_summary");
|
|
|
|
const summaryText = summary.text();
|
2017-01-17 19:01:54 +08:00
|
|
|
|
2017-10-12 00:56:17 +08:00
|
|
|
expect(summaryText).toBe("user_1 was unbanned, joined and left 7 times and was invited");
|
2017-01-17 19:01:54 +08:00
|
|
|
});
|
|
|
|
|
2021-04-30 01:57:02 +08:00
|
|
|
it("truncates multiple sequences of repetitions with other events between", function () {
|
|
|
|
const events = generateEvents([
|
2017-01-25 18:52:55 +08:00
|
|
|
{
|
|
|
|
userId: "@user_1:some.domain",
|
|
|
|
prevMembership: "ban",
|
|
|
|
membership: "leave",
|
|
|
|
senderId: "@some_other_user:some.domain",
|
|
|
|
},
|
2021-06-29 20:11:58 +08:00
|
|
|
{ userId: "@user_1:some.domain", prevMembership: "leave", membership: "join" },
|
|
|
|
{ userId: "@user_1:some.domain", prevMembership: "join", membership: "leave" },
|
|
|
|
{ userId: "@user_1:some.domain", prevMembership: "leave", membership: "join" },
|
|
|
|
{ userId: "@user_1:some.domain", prevMembership: "join", membership: "leave" },
|
2017-01-25 18:52:55 +08:00
|
|
|
{
|
|
|
|
userId: "@user_1:some.domain",
|
|
|
|
prevMembership: "leave",
|
|
|
|
membership: "ban",
|
|
|
|
senderId: "@some_other_user:some.domain",
|
|
|
|
},
|
2021-06-29 20:11:58 +08:00
|
|
|
{ userId: "@user_1:some.domain", prevMembership: "ban", membership: "join" },
|
|
|
|
{ userId: "@user_1:some.domain", prevMembership: "join", membership: "leave" },
|
|
|
|
{ userId: "@user_1:some.domain", prevMembership: "leave", membership: "join" },
|
|
|
|
{ userId: "@user_1:some.domain", prevMembership: "join", membership: "leave" },
|
|
|
|
{ userId: "@user_1:some.domain", prevMembership: "leave", membership: "join" },
|
|
|
|
{ userId: "@user_1:some.domain", prevMembership: "join", membership: "leave" },
|
2017-01-25 18:52:55 +08:00
|
|
|
{
|
|
|
|
userId: "@user_1:some.domain",
|
|
|
|
prevMembership: "leave",
|
|
|
|
membership: "invite",
|
|
|
|
senderId: "@some_other_user:some.domain",
|
|
|
|
},
|
2021-04-30 01:57:02 +08:00
|
|
|
]);
|
|
|
|
const props = {
|
2017-01-25 18:52:55 +08:00
|
|
|
events: events,
|
|
|
|
children: generateTiles(events),
|
|
|
|
summaryLength: 1,
|
|
|
|
avatarsMaxLength: 5,
|
|
|
|
threshold: 3,
|
2021-04-30 01:57:02 +08:00
|
|
|
};
|
2017-01-17 19:01:54 +08:00
|
|
|
|
2022-05-04 22:37:41 +08:00
|
|
|
const wrapper = renderComponent(props);
|
|
|
|
const summary = wrapper.find(".mx_GenericEventListSummary_summary");
|
|
|
|
const summaryText = summary.text();
|
2017-01-17 19:01:54 +08:00
|
|
|
|
2021-04-30 01:57:02 +08:00
|
|
|
expect(summaryText).toBe(
|
|
|
|
"user_1 was unbanned, joined and left 2 times, was banned, " + "joined and left 3 times and was invited",
|
|
|
|
);
|
|
|
|
});
|
2017-01-17 19:01:54 +08:00
|
|
|
|
2017-01-18 19:03:38 +08:00
|
|
|
it("handles multiple users following the same sequence of memberships", function () {
|
2017-01-17 19:01:54 +08:00
|
|
|
const events = generateEvents([
|
|
|
|
// user_1
|
2017-01-25 18:52:55 +08:00
|
|
|
{
|
|
|
|
userId: "@user_1:some.domain",
|
|
|
|
prevMembership: "ban",
|
|
|
|
membership: "leave",
|
|
|
|
senderId: "@some_other_user:some.domain",
|
|
|
|
},
|
2021-06-29 20:11:58 +08:00
|
|
|
{ userId: "@user_1:some.domain", prevMembership: "leave", membership: "join" },
|
|
|
|
{ userId: "@user_1:some.domain", prevMembership: "join", membership: "leave" },
|
|
|
|
{ userId: "@user_1:some.domain", prevMembership: "leave", membership: "join" },
|
|
|
|
{ userId: "@user_1:some.domain", prevMembership: "join", membership: "leave" },
|
2017-01-25 18:52:55 +08:00
|
|
|
{
|
|
|
|
userId: "@user_1:some.domain",
|
|
|
|
prevMembership: "leave",
|
|
|
|
membership: "ban",
|
|
|
|
senderId: "@some_other_user:some.domain",
|
|
|
|
},
|
2017-01-17 19:01:54 +08:00
|
|
|
// user_2
|
2017-01-25 18:52:55 +08:00
|
|
|
{
|
|
|
|
userId: "@user_2:some.domain",
|
|
|
|
prevMembership: "ban",
|
|
|
|
membership: "leave",
|
|
|
|
senderId: "@some_other_user:some.domain",
|
|
|
|
},
|
2021-06-29 20:11:58 +08:00
|
|
|
{ userId: "@user_2:some.domain", prevMembership: "leave", membership: "join" },
|
|
|
|
{ userId: "@user_2:some.domain", prevMembership: "join", membership: "leave" },
|
|
|
|
{ userId: "@user_2:some.domain", prevMembership: "leave", membership: "join" },
|
|
|
|
{ userId: "@user_2:some.domain", prevMembership: "join", membership: "leave" },
|
2017-01-25 18:52:55 +08:00
|
|
|
{
|
|
|
|
userId: "@user_2:some.domain",
|
|
|
|
prevMembership: "leave",
|
|
|
|
membership: "ban",
|
|
|
|
senderId: "@some_other_user:some.domain",
|
|
|
|
},
|
2017-01-17 19:01:54 +08:00
|
|
|
]);
|
|
|
|
const props = {
|
2017-01-25 18:52:55 +08:00
|
|
|
events: events,
|
|
|
|
children: generateTiles(events),
|
|
|
|
summaryLength: 1,
|
|
|
|
avatarsMaxLength: 5,
|
|
|
|
threshold: 3,
|
2017-01-17 19:01:54 +08:00
|
|
|
};
|
|
|
|
|
2022-05-04 22:37:41 +08:00
|
|
|
const wrapper = renderComponent(props);
|
|
|
|
const summary = wrapper.find(".mx_GenericEventListSummary_summary");
|
|
|
|
const summaryText = summary.text();
|
2017-01-17 19:01:54 +08:00
|
|
|
|
2017-10-12 00:56:17 +08:00
|
|
|
expect(summaryText).toBe("user_1 and one other were unbanned, joined and left 2 times and were banned");
|
2017-01-17 19:01:54 +08:00
|
|
|
});
|
|
|
|
|
2017-01-18 19:03:38 +08:00
|
|
|
it("handles many users following the same sequence of memberships", function () {
|
2017-01-17 19:01:54 +08:00
|
|
|
const events = generateEventsForUsers("@user_$:some.domain", 20, [
|
2017-01-25 18:52:55 +08:00
|
|
|
{
|
|
|
|
prevMembership: "ban",
|
|
|
|
membership: "leave",
|
|
|
|
senderId: "@some_other_user:some.domain",
|
|
|
|
},
|
2021-06-29 20:11:58 +08:00
|
|
|
{ prevMembership: "leave", membership: "join" },
|
|
|
|
{ prevMembership: "join", membership: "leave" },
|
|
|
|
{ prevMembership: "leave", membership: "join" },
|
|
|
|
{ prevMembership: "join", membership: "leave" },
|
2017-01-25 18:52:55 +08:00
|
|
|
{
|
|
|
|
prevMembership: "leave",
|
|
|
|
membership: "ban",
|
|
|
|
senderId: "@some_other_user:some.domain",
|
|
|
|
},
|
2017-01-17 19:01:54 +08:00
|
|
|
]);
|
|
|
|
const props = {
|
2017-01-25 18:52:55 +08:00
|
|
|
events: events,
|
|
|
|
children: generateTiles(events),
|
|
|
|
summaryLength: 1,
|
|
|
|
avatarsMaxLength: 5,
|
|
|
|
threshold: 3,
|
2017-01-17 19:01:54 +08:00
|
|
|
};
|
|
|
|
|
2022-05-04 22:37:41 +08:00
|
|
|
const wrapper = renderComponent(props);
|
|
|
|
const summary = wrapper.find(".mx_GenericEventListSummary_summary");
|
|
|
|
const summaryText = summary.text();
|
2017-01-17 19:01:54 +08:00
|
|
|
|
2017-10-12 00:56:17 +08:00
|
|
|
expect(summaryText).toBe("user_0 and 19 others were unbanned, joined and left 2 times and were banned");
|
2017-01-17 19:01:54 +08:00
|
|
|
});
|
|
|
|
|
2021-04-30 01:57:02 +08:00
|
|
|
it("correctly orders sequences of transitions by the order of their first event", function () {
|
|
|
|
const events = generateEvents([
|
2017-01-25 18:52:55 +08:00
|
|
|
{
|
|
|
|
userId: "@user_2:some.domain",
|
|
|
|
prevMembership: "ban",
|
|
|
|
membership: "leave",
|
|
|
|
senderId: "@some_other_user:some.domain",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
userId: "@user_1:some.domain",
|
|
|
|
prevMembership: "ban",
|
|
|
|
membership: "leave",
|
|
|
|
senderId: "@some_other_user:some.domain",
|
|
|
|
},
|
2021-06-29 20:11:58 +08:00
|
|
|
{ userId: "@user_1:some.domain", prevMembership: "leave", membership: "join" },
|
|
|
|
{ userId: "@user_1:some.domain", prevMembership: "join", membership: "leave" },
|
|
|
|
{ userId: "@user_1:some.domain", prevMembership: "leave", membership: "join" },
|
|
|
|
{ userId: "@user_1:some.domain", prevMembership: "join", membership: "leave" },
|
2017-01-25 18:52:55 +08:00
|
|
|
{
|
|
|
|
userId: "@user_1:some.domain",
|
|
|
|
prevMembership: "leave",
|
|
|
|
membership: "ban",
|
|
|
|
senderId: "@some_other_user:some.domain",
|
|
|
|
},
|
2021-06-29 20:11:58 +08:00
|
|
|
{ userId: "@user_2:some.domain", prevMembership: "leave", membership: "join" },
|
|
|
|
{ userId: "@user_2:some.domain", prevMembership: "join", membership: "leave" },
|
|
|
|
{ userId: "@user_2:some.domain", prevMembership: "leave", membership: "join" },
|
|
|
|
{ userId: "@user_2:some.domain", prevMembership: "join", membership: "leave" },
|
2021-04-30 01:57:02 +08:00
|
|
|
]);
|
|
|
|
const props = {
|
2017-01-25 18:52:55 +08:00
|
|
|
events: events,
|
|
|
|
children: generateTiles(events),
|
|
|
|
summaryLength: 1,
|
|
|
|
avatarsMaxLength: 5,
|
|
|
|
threshold: 3,
|
2021-04-30 01:57:02 +08:00
|
|
|
};
|
2017-01-17 19:01:54 +08:00
|
|
|
|
2022-05-04 22:37:41 +08:00
|
|
|
const wrapper = renderComponent(props);
|
|
|
|
const summary = wrapper.find(".mx_GenericEventListSummary_summary");
|
|
|
|
const summaryText = summary.text();
|
2017-01-17 19:01:54 +08:00
|
|
|
|
2021-04-30 01:57:02 +08:00
|
|
|
expect(summaryText).toBe(
|
|
|
|
"user_2 was unbanned and joined and left 2 times, user_1 was unbanned, " +
|
2017-10-12 00:56:17 +08:00
|
|
|
"joined and left 2 times and was banned",
|
2021-04-30 01:57:02 +08:00
|
|
|
);
|
|
|
|
});
|
2017-01-17 19:01:54 +08:00
|
|
|
|
2017-01-18 19:03:38 +08:00
|
|
|
it("correctly identifies transitions", function () {
|
2017-01-17 19:01:54 +08:00
|
|
|
const events = generateEvents([
|
|
|
|
// invited
|
2021-06-29 20:11:58 +08:00
|
|
|
{ userId: "@user_1:some.domain", membership: "invite" },
|
2017-01-17 19:01:54 +08:00
|
|
|
// banned
|
2021-06-29 20:11:58 +08:00
|
|
|
{ userId: "@user_1:some.domain", membership: "ban" },
|
2017-01-17 19:01:54 +08:00
|
|
|
// joined
|
2021-06-29 20:11:58 +08:00
|
|
|
{ userId: "@user_1:some.domain", membership: "join" },
|
2017-01-17 19:01:54 +08:00
|
|
|
// invite_reject
|
2017-01-25 18:52:55 +08:00
|
|
|
{
|
|
|
|
userId: "@user_1:some.domain",
|
|
|
|
prevMembership: "invite",
|
|
|
|
membership: "leave",
|
|
|
|
},
|
2017-01-17 19:01:54 +08:00
|
|
|
// left
|
2021-06-29 20:11:58 +08:00
|
|
|
{ userId: "@user_1:some.domain", prevMembership: "join", membership: "leave" },
|
2017-01-17 19:01:54 +08:00
|
|
|
// invite_withdrawal
|
2017-01-25 18:52:55 +08:00
|
|
|
{
|
|
|
|
userId: "@user_1:some.domain",
|
|
|
|
prevMembership: "invite",
|
|
|
|
membership: "leave",
|
|
|
|
senderId: "@some_other_user:some.domain",
|
|
|
|
},
|
2017-01-17 19:01:54 +08:00
|
|
|
// unbanned
|
2017-01-25 18:52:55 +08:00
|
|
|
{
|
|
|
|
userId: "@user_1:some.domain",
|
|
|
|
prevMembership: "ban",
|
|
|
|
membership: "leave",
|
|
|
|
senderId: "@some_other_user:some.domain",
|
|
|
|
},
|
2017-01-17 19:01:54 +08:00
|
|
|
// kicked
|
2017-01-25 18:52:55 +08:00
|
|
|
{
|
|
|
|
userId: "@user_1:some.domain",
|
|
|
|
prevMembership: "join",
|
|
|
|
membership: "leave",
|
|
|
|
senderId: "@some_other_user:some.domain",
|
|
|
|
},
|
2019-07-11 04:58:08 +08:00
|
|
|
// default for sender=target (leave)
|
|
|
|
{
|
|
|
|
userId: "@user_1:some.domain",
|
|
|
|
prevMembership: "????",
|
|
|
|
membership: "leave",
|
|
|
|
senderId: "@user_1:some.domain",
|
|
|
|
},
|
|
|
|
// default for sender<>target (kicked)
|
2017-01-25 18:52:55 +08:00
|
|
|
{
|
|
|
|
userId: "@user_1:some.domain",
|
|
|
|
prevMembership: "????",
|
|
|
|
membership: "leave",
|
|
|
|
senderId: "@some_other_user:some.domain",
|
|
|
|
},
|
2017-01-17 19:01:54 +08:00
|
|
|
]);
|
|
|
|
const props = {
|
2017-01-25 18:52:55 +08:00
|
|
|
events: events,
|
|
|
|
children: generateTiles(events),
|
|
|
|
summaryLength: 1,
|
|
|
|
avatarsMaxLength: 5,
|
|
|
|
threshold: 3,
|
2017-01-17 19:01:54 +08:00
|
|
|
};
|
|
|
|
|
2022-05-04 22:37:41 +08:00
|
|
|
const wrapper = renderComponent(props);
|
|
|
|
const summary = wrapper.find(".mx_GenericEventListSummary_summary");
|
|
|
|
const summaryText = summary.text();
|
2017-01-17 19:01:54 +08:00
|
|
|
|
|
|
|
expect(summaryText).toBe(
|
2017-01-25 18:52:55 +08:00
|
|
|
"user_1 was invited, was banned, joined, rejected their invitation, left, " +
|
2022-01-14 21:08:34 +08:00
|
|
|
"had their invitation withdrawn, was unbanned, was removed, left and was removed",
|
2017-01-17 19:01:54 +08:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2017-01-18 19:03:38 +08:00
|
|
|
it("handles invitation plurals correctly when there are multiple users", function () {
|
2017-01-17 19:01:54 +08:00
|
|
|
const events = generateEvents([
|
2017-01-25 18:52:55 +08:00
|
|
|
{
|
|
|
|
userId: "@user_1:some.domain",
|
|
|
|
prevMembership: "invite",
|
|
|
|
membership: "leave",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
userId: "@user_1:some.domain",
|
|
|
|
prevMembership: "invite",
|
|
|
|
membership: "leave",
|
|
|
|
senderId: "@some_other_user:some.domain",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
userId: "@user_2:some.domain",
|
|
|
|
prevMembership: "invite",
|
|
|
|
membership: "leave",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
userId: "@user_2:some.domain",
|
|
|
|
prevMembership: "invite",
|
|
|
|
membership: "leave",
|
|
|
|
senderId: "@some_other_user:some.domain",
|
|
|
|
},
|
2017-01-17 19:01:54 +08:00
|
|
|
]);
|
|
|
|
const props = {
|
2017-01-25 18:52:55 +08:00
|
|
|
events: events,
|
|
|
|
children: generateTiles(events),
|
|
|
|
summaryLength: 1,
|
|
|
|
avatarsMaxLength: 5,
|
|
|
|
threshold: 3,
|
2017-01-17 19:01:54 +08:00
|
|
|
};
|
|
|
|
|
2022-05-04 22:37:41 +08:00
|
|
|
const wrapper = renderComponent(props);
|
|
|
|
const summary = wrapper.find(".mx_GenericEventListSummary_summary");
|
|
|
|
const summaryText = summary.text();
|
2017-01-17 19:01:54 +08:00
|
|
|
|
|
|
|
expect(summaryText).toBe(
|
2017-05-26 18:58:45 +08:00
|
|
|
"user_1 and one other rejected their invitations and " + "had their invitations withdrawn",
|
2017-01-17 19:01:54 +08:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2021-04-30 01:57:02 +08:00
|
|
|
it("handles invitation plurals correctly when there are multiple invites", function () {
|
|
|
|
const events = generateEvents([
|
2017-01-25 18:52:55 +08:00
|
|
|
{
|
|
|
|
userId: "@user_1:some.domain",
|
|
|
|
prevMembership: "invite",
|
|
|
|
membership: "leave",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
userId: "@user_1:some.domain",
|
|
|
|
prevMembership: "invite",
|
|
|
|
membership: "leave",
|
|
|
|
},
|
2021-04-30 01:57:02 +08:00
|
|
|
]);
|
|
|
|
const props = {
|
2017-01-25 18:52:55 +08:00
|
|
|
events: events,
|
|
|
|
children: generateTiles(events),
|
|
|
|
summaryLength: 1,
|
|
|
|
avatarsMaxLength: 5,
|
|
|
|
threshold: 1, // threshold = 1 to force collapse
|
2021-04-30 01:57:02 +08:00
|
|
|
};
|
2017-01-17 19:01:54 +08:00
|
|
|
|
2022-05-04 22:37:41 +08:00
|
|
|
const wrapper = renderComponent(props);
|
|
|
|
const summary = wrapper.find(".mx_GenericEventListSummary_summary");
|
|
|
|
const summaryText = summary.text();
|
2017-01-17 19:01:54 +08:00
|
|
|
|
2021-04-30 01:57:02 +08:00
|
|
|
expect(summaryText).toBe("user_1 rejected their invitation 2 times");
|
|
|
|
});
|
2017-01-17 19:01:54 +08:00
|
|
|
|
2017-01-18 19:03:38 +08:00
|
|
|
it('handles a summary length = 2, with no "others"', function () {
|
2017-01-17 19:01:54 +08:00
|
|
|
const events = generateEvents([
|
2021-06-29 20:11:58 +08:00
|
|
|
{ userId: "@user_1:some.domain", membership: "join" },
|
|
|
|
{ userId: "@user_1:some.domain", membership: "join" },
|
|
|
|
{ userId: "@user_2:some.domain", membership: "join" },
|
|
|
|
{ userId: "@user_2:some.domain", membership: "join" },
|
2017-01-17 19:01:54 +08:00
|
|
|
]);
|
|
|
|
const props = {
|
2017-01-25 18:52:55 +08:00
|
|
|
events: events,
|
|
|
|
children: generateTiles(events),
|
|
|
|
summaryLength: 2,
|
|
|
|
avatarsMaxLength: 5,
|
|
|
|
threshold: 3,
|
2017-01-17 19:01:54 +08:00
|
|
|
};
|
|
|
|
|
2022-05-04 22:37:41 +08:00
|
|
|
const wrapper = renderComponent(props);
|
|
|
|
const summary = wrapper.find(".mx_GenericEventListSummary_summary");
|
|
|
|
const summaryText = summary.text();
|
2017-01-17 19:01:54 +08:00
|
|
|
|
2017-10-12 00:56:17 +08:00
|
|
|
expect(summaryText).toBe("user_1 and user_2 joined 2 times");
|
2017-01-17 19:01:54 +08:00
|
|
|
});
|
|
|
|
|
2017-01-18 19:03:38 +08:00
|
|
|
it('handles a summary length = 2, with 1 "other"', function () {
|
2017-01-17 19:01:54 +08:00
|
|
|
const events = generateEvents([
|
2021-06-29 20:11:58 +08:00
|
|
|
{ userId: "@user_1:some.domain", membership: "join" },
|
|
|
|
{ userId: "@user_2:some.domain", membership: "join" },
|
|
|
|
{ userId: "@user_3:some.domain", membership: "join" },
|
2017-01-17 19:01:54 +08:00
|
|
|
]);
|
|
|
|
const props = {
|
2017-01-25 18:52:55 +08:00
|
|
|
events: events,
|
|
|
|
children: generateTiles(events),
|
|
|
|
summaryLength: 2,
|
|
|
|
avatarsMaxLength: 5,
|
|
|
|
threshold: 3,
|
2017-01-17 19:01:54 +08:00
|
|
|
};
|
|
|
|
|
2022-05-04 22:37:41 +08:00
|
|
|
const wrapper = renderComponent(props);
|
|
|
|
const summary = wrapper.find(".mx_GenericEventListSummary_summary");
|
|
|
|
const summaryText = summary.text();
|
2017-01-17 19:01:54 +08:00
|
|
|
|
2017-10-12 00:56:17 +08:00
|
|
|
expect(summaryText).toBe("user_1, user_2 and one other joined");
|
2017-01-17 19:01:54 +08:00
|
|
|
});
|
|
|
|
|
2017-01-18 19:03:38 +08:00
|
|
|
it('handles a summary length = 2, with many "others"', function () {
|
2017-01-17 19:01:54 +08:00
|
|
|
const events = generateEventsForUsers("@user_$:some.domain", 20, [{ membership: "join" }]);
|
|
|
|
const props = {
|
2017-01-25 18:52:55 +08:00
|
|
|
events: events,
|
|
|
|
children: generateTiles(events),
|
|
|
|
summaryLength: 2,
|
|
|
|
avatarsMaxLength: 5,
|
|
|
|
threshold: 3,
|
2017-01-17 19:01:54 +08:00
|
|
|
};
|
|
|
|
|
2022-05-04 22:37:41 +08:00
|
|
|
const wrapper = renderComponent(props);
|
|
|
|
const summary = wrapper.find(".mx_GenericEventListSummary_summary");
|
|
|
|
const summaryText = summary.text();
|
2017-01-17 19:01:54 +08:00
|
|
|
|
2017-10-12 00:56:17 +08:00
|
|
|
expect(summaryText).toBe("user_0, user_1 and 18 others joined");
|
2017-01-17 19:01:54 +08:00
|
|
|
});
|
2017-01-25 18:52:55 +08:00
|
|
|
});
|