element-web/test/components/views/elements/MemberEventListSummary-test.js

696 lines
27 KiB
JavaScript
Raw Normal View History

import expect from 'expect';
import React from 'react';
import ReactTestUtils from 'react-addons-test-utils';
import sdk from 'matrix-react-sdk';
import * as languageHandler from '../../../../src/languageHandler';
import * as testUtils from '../../../test-utils';
// Give MELS a matrixClient in its child context
const MemberEventListSummary = testUtils.wrapInMatrixClientContext(
sdk.getComponent('views.elements.MemberEventListSummary'),
);
2017-01-17 12:01:54 +01:00
2017-01-25 10:12:29 +01:00
describe('MemberEventListSummary', function() {
2017-01-17 12:01:54 +01:00
let sandbox;
2017-01-18 11:53:17 +01:00
// Generate dummy event tiles for use in simulating an expanded MELS
2017-01-17 12:01:54 +01:00
const generateTiles = (events) => {
return events.map((e) => {
return (
<div key={e.getId()} className="event_tile">
Expanded membership
</div>
);
});
};
2017-01-18 11:53:17 +01:00
/**
2017-01-25 11:52:55 +01:00
* Generates a membership event with the target of the event set as a mocked
* RoomMember based on `parameters.userId`.
2017-01-18 11:53:17 +01:00
* @param {string} eventId the ID of the event.
* @param {object} parameters the parameters to use to create the event.
2017-01-25 11:52:55 +01:00
* @param {string} parameters.membership the membership to assign to
* `content.membership`
2017-01-18 11:53:17 +01: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 11:52:55 +01:00
* @param {string} parameters.senderId the user ID of the sender of the event.
* Optional. Defaults to `parameters.userId`.
2017-01-18 11:53:17 +01:00
* @returns {MatrixEvent} the event created.
*/
2017-01-17 12:01:54 +01:00
const generateMembershipEvent = (eventId, parameters) => {
2017-01-25 11:52:55 +01:00
const e = testUtils.mkMembership({
2017-01-18 11:53:17 +01:00
event: true,
user: parameters.senderId || parameters.userId,
skey: parameters.userId,
mship: parameters.membership,
prevMship: parameters.prevMembership,
2017-01-25 11:52:55 +01:00
target: {
// Use localpart as display name
name: parameters.userId.match(/@([^:]*):/)[1],
2017-01-18 11:53:17 +01:00
userId: parameters.userId,
2017-01-17 12:01:54 +01:00
getAvatarUrl: () => {
return "avatar.jpeg";
},
},
2017-01-18 11:53:17 +01:00
});
2017-01-25 11:52:55 +01:00
// Override random event ID to allow for equality tests against tiles from
// generateTiles
2017-01-18 11:53:17 +01:00
e.event.event_id = eventId;
return e;
2017-01-17 12:01:54 +01:00
};
2017-01-18 11:53:17 +01:00
// Generate mock MatrixEvents from the array of parameters
2017-01-17 12:01:54 +01:00
const generateEvents = (parameters) => {
const res = [];
for (let i = 0; i < parameters.length; i++) {
res.push(generateMembershipEvent(`event${i}`, parameters[i]));
}
return res;
};
2017-01-18 11:53:17 +01: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 12:01:54 +01: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;
};
beforeEach(function(done) {
2017-01-17 12:01:54 +01:00
testUtils.beforeEach(this);
sandbox = testUtils.stubClient();
2017-05-26 13:03:36 +02:00
languageHandler.setLanguage('en').done(done);
languageHandler.setMissingEntryGenerator(function(key) {
return key.split('|', 2)[1];
});
2017-01-17 12:01:54 +01:00
});
afterEach(function() {
sandbox.restore();
});
it('renders expanded events if there are less than props.threshold', function() {
2017-01-17 12:01:54 +01:00
const events = generateEvents([
2017-01-25 11:52:55 +01:00
{userId: "@user_1:some.domain", prevMembership: "leave", membership: "join"},
2017-01-17 12:01:54 +01:00
]);
const props = {
2017-01-25 11:52:55 +01:00
events: events,
children: generateTiles(events),
summaryLength: 1,
avatarsMaxLength: 5,
threshold: 3,
2017-01-17 12:01:54 +01:00
};
const renderer = ReactTestUtils.createRenderer();
renderer.render(<MemberEventListSummary {...props} />);
const result = renderer.getRenderOutput();
expect(result.props.children).toEqual([
<div className="event_tile" key="event0">Expanded membership</div>,
]);
});
it('renders expanded events if there are less than props.threshold', function() {
2017-01-17 12:01:54 +01:00
const events = generateEvents([
2017-01-25 11:52:55 +01:00
{userId: "@user_1:some.domain", prevMembership: "leave", membership: "join"},
{userId: "@user_1:some.domain", prevMembership: "join", membership: "leave"},
2017-01-17 12:01:54 +01:00
]);
const props = {
2017-01-25 11:52:55 +01:00
events: events,
children: generateTiles(events),
summaryLength: 1,
avatarsMaxLength: 5,
threshold: 3,
2017-01-17 12:01:54 +01:00
};
const renderer = ReactTestUtils.createRenderer();
renderer.render(<MemberEventListSummary {...props} />);
const result = renderer.getRenderOutput();
expect(result.props.children).toEqual([
<div className="event_tile" key="event0">Expanded membership</div>,
<div className="event_tile" key="event1">Expanded membership</div>,
]);
});
it('renders collapsed events if events.length = props.threshold', function() {
2017-01-17 12:01:54 +01:00
const events = generateEvents([
2017-01-25 11:52:55 +01: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 12:01:54 +01:00
]);
const props = {
2017-01-25 11:52:55 +01:00
events: events,
children: generateTiles(events),
summaryLength: 1,
avatarsMaxLength: 5,
threshold: 3,
2017-01-17 12:01:54 +01:00
};
2017-01-25 11:52:55 +01:00
const instance = ReactTestUtils.renderIntoDocument(
<MemberEventListSummary {...props} />,
2017-01-25 11:52:55 +01:00
);
const summary = ReactTestUtils.findRenderedDOMComponentWithClass(
instance, "mx_MemberEventListSummary_summary",
2017-01-25 11:52:55 +01:00
);
2017-01-17 12:01:54 +01:00
const summaryText = summary.innerText;
expect(summaryText).toBe("user_1 joined and left and joined");
});
it('truncates long join,leave repetitions', function() {
2017-01-17 12:01:54 +01:00
const events = generateEvents([
2017-01-25 11:52:55 +01: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 12:01:54 +01:00
]);
const props = {
2017-01-25 11:52:55 +01:00
events: events,
children: generateTiles(events),
summaryLength: 1,
avatarsMaxLength: 5,
threshold: 3,
2017-01-17 12:01:54 +01:00
};
2017-01-25 11:52:55 +01:00
const instance = ReactTestUtils.renderIntoDocument(
<MemberEventListSummary {...props} />,
2017-01-25 11:52:55 +01:00
);
const summary = ReactTestUtils.findRenderedDOMComponentWithClass(
instance, "mx_MemberEventListSummary_summary",
2017-01-25 11:52:55 +01:00
);
2017-01-17 12:01:54 +01:00
const summaryText = summary.innerText;
expect(summaryText).toBe("user_1 joined and left 7 times");
});
2017-01-25 11:52:55 +01:00
it('truncates long join,leave repetitions between other events', function() {
2017-01-17 12:01:54 +01:00
const events = generateEvents([
2017-01-25 11:52:55 +01:00
{
userId: "@user_1:some.domain",
prevMembership: "ban",
membership: "leave",
senderId: "@some_other_user:some.domain",
},
{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"},
{
userId: "@user_1:some.domain",
prevMembership: "leave",
membership: "invite",
senderId: "@some_other_user:some.domain",
},
2017-01-17 12:01:54 +01:00
]);
const props = {
2017-01-25 11:52:55 +01:00
events: events,
children: generateTiles(events),
summaryLength: 1,
avatarsMaxLength: 5,
threshold: 3,
2017-01-17 12:01:54 +01:00
};
2017-01-25 11:52:55 +01:00
const instance = ReactTestUtils.renderIntoDocument(
<MemberEventListSummary {...props} />,
2017-01-25 11:52:55 +01:00
);
const summary = ReactTestUtils.findRenderedDOMComponentWithClass(
instance, "mx_MemberEventListSummary_summary",
2017-01-25 11:52:55 +01:00
);
2017-01-17 12:01:54 +01:00
const summaryText = summary.innerText;
2017-01-25 11:52:55 +01:00
expect(summaryText).toBe(
"user_1 was unbanned, joined and left 7 times and was invited",
2017-01-25 11:52:55 +01:00
);
2017-01-17 12:01:54 +01:00
});
2017-01-25 11:52:55 +01:00
it('truncates multiple sequences of repetitions with other events between',
function() {
2017-01-17 12:01:54 +01:00
const events = generateEvents([
2017-01-25 11:52:55 +01:00
{
userId: "@user_1:some.domain",
prevMembership: "ban",
membership: "leave",
senderId: "@some_other_user:some.domain",
},
{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: "ban",
senderId: "@some_other_user:some.domain",
},
{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"},
{
userId: "@user_1:some.domain",
prevMembership: "leave",
membership: "invite",
senderId: "@some_other_user:some.domain",
},
2017-01-17 12:01:54 +01:00
]);
const props = {
2017-01-25 11:52:55 +01:00
events: events,
children: generateTiles(events),
summaryLength: 1,
avatarsMaxLength: 5,
threshold: 3,
2017-01-17 12:01:54 +01:00
};
2017-01-25 11:52:55 +01:00
const instance = ReactTestUtils.renderIntoDocument(
<MemberEventListSummary {...props} />,
2017-01-25 11:52:55 +01:00
);
const summary = ReactTestUtils.findRenderedDOMComponentWithClass(
instance, "mx_MemberEventListSummary_summary",
2017-01-25 11:52:55 +01:00
);
2017-01-17 12:01:54 +01:00
const summaryText = summary.innerText;
2017-01-25 11:52:55 +01: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-25 11:52:55 +01:00
);
2017-01-17 12:01:54 +01:00
});
it('handles multiple users following the same sequence of memberships', function() {
2017-01-17 12:01:54 +01:00
const events = generateEvents([
// user_1
2017-01-25 11:52:55 +01:00
{
userId: "@user_1:some.domain",
prevMembership: "ban",
membership: "leave",
senderId: "@some_other_user:some.domain",
},
{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: "ban",
senderId: "@some_other_user:some.domain",
},
2017-01-17 12:01:54 +01:00
// user_2
2017-01-25 11:52:55 +01:00
{
userId: "@user_2:some.domain",
prevMembership: "ban",
membership: "leave",
senderId: "@some_other_user:some.domain",
},
{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"},
{
userId: "@user_2:some.domain",
prevMembership: "leave",
membership: "ban",
senderId: "@some_other_user:some.domain",
},
2017-01-17 12:01:54 +01:00
]);
const props = {
2017-01-25 11:52:55 +01:00
events: events,
children: generateTiles(events),
summaryLength: 1,
avatarsMaxLength: 5,
threshold: 3,
2017-01-17 12:01:54 +01:00
};
2017-01-25 11:52:55 +01:00
const instance = ReactTestUtils.renderIntoDocument(
<MemberEventListSummary {...props} />,
2017-01-25 11:52:55 +01:00
);
const summary = ReactTestUtils.findRenderedDOMComponentWithClass(
instance, "mx_MemberEventListSummary_summary",
2017-01-25 11:52:55 +01:00
);
2017-01-17 12:01:54 +01:00
const summaryText = summary.innerText;
2017-01-25 11:52:55 +01:00
expect(summaryText).toBe(
"user_1 and one other were unbanned, joined and left 2 times and were banned",
2017-01-25 11:52:55 +01:00
);
2017-01-17 12:01:54 +01:00
});
it('handles many users following the same sequence of memberships', function() {
2017-01-17 12:01:54 +01:00
const events = generateEventsForUsers("@user_$:some.domain", 20, [
2017-01-25 11:52:55 +01:00
{
prevMembership: "ban",
membership: "leave",
senderId: "@some_other_user:some.domain",
},
2017-01-17 12:01:54 +01:00
{prevMembership: "leave", membership: "join"},
{prevMembership: "join", membership: "leave"},
{prevMembership: "leave", membership: "join"},
{prevMembership: "join", membership: "leave"},
2017-01-25 11:52:55 +01:00
{
prevMembership: "leave",
membership: "ban",
senderId: "@some_other_user:some.domain",
},
2017-01-17 12:01:54 +01:00
]);
const props = {
2017-01-25 11:52:55 +01:00
events: events,
children: generateTiles(events),
summaryLength: 1,
avatarsMaxLength: 5,
threshold: 3,
2017-01-17 12:01:54 +01:00
};
2017-01-25 11:52:55 +01:00
const instance = ReactTestUtils.renderIntoDocument(
<MemberEventListSummary {...props} />,
2017-01-25 11:52:55 +01:00
);
const summary = ReactTestUtils.findRenderedDOMComponentWithClass(
instance, "mx_MemberEventListSummary_summary",
2017-01-25 11:52:55 +01:00
);
2017-01-17 12:01:54 +01:00
const summaryText = summary.innerText;
2017-01-25 11:52:55 +01:00
expect(summaryText).toBe(
"user_0 and 19 others were unbanned, joined and left 2 times and were banned",
2017-01-25 11:52:55 +01:00
);
2017-01-17 12:01:54 +01:00
});
2017-01-25 11:52:55 +01:00
it('correctly orders sequences of transitions by the order of their first event',
function() {
2017-01-17 12:01:54 +01:00
const events = generateEvents([
2017-01-25 11:52:55 +01: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",
},
{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: "ban",
senderId: "@some_other_user:some.domain",
},
{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-17 12:01:54 +01:00
]);
const props = {
2017-01-25 11:52:55 +01:00
events: events,
children: generateTiles(events),
summaryLength: 1,
avatarsMaxLength: 5,
threshold: 3,
2017-01-17 12:01:54 +01:00
};
2017-01-25 11:52:55 +01:00
const instance = ReactTestUtils.renderIntoDocument(
<MemberEventListSummary {...props} />,
2017-01-25 11:52:55 +01:00
);
const summary = ReactTestUtils.findRenderedDOMComponentWithClass(
instance, "mx_MemberEventListSummary_summary",
2017-01-25 11:52:55 +01:00
);
2017-01-17 12:01:54 +01:00
const summaryText = summary.innerText;
expect(summaryText).toBe(
2017-01-25 11:52:55 +01:00
"user_2 was unbanned and joined and left 2 times, user_1 was unbanned, " +
"joined and left 2 times and was banned",
2017-01-17 12:01:54 +01:00
);
});
it('correctly identifies transitions', function() {
2017-01-17 12:01:54 +01:00
const events = generateEvents([
// invited
2017-01-25 11:52:55 +01:00
{userId: "@user_1:some.domain", membership: "invite"},
2017-01-17 12:01:54 +01:00
// banned
2017-01-25 11:52:55 +01:00
{userId: "@user_1:some.domain", membership: "ban"},
2017-01-17 12:01:54 +01:00
// joined
2017-01-25 11:52:55 +01:00
{userId: "@user_1:some.domain", membership: "join"},
2017-01-17 12:01:54 +01:00
// invite_reject
2017-01-25 11:52:55 +01:00
{
userId: "@user_1:some.domain",
prevMembership: "invite",
membership: "leave",
},
2017-01-17 12:01:54 +01:00
// left
2017-01-25 11:52:55 +01:00
{userId: "@user_1:some.domain", prevMembership: "join", membership: "leave"},
2017-01-17 12:01:54 +01:00
// invite_withdrawal
2017-01-25 11:52:55 +01:00
{
userId: "@user_1:some.domain",
prevMembership: "invite",
membership: "leave",
senderId: "@some_other_user:some.domain",
},
2017-01-17 12:01:54 +01:00
// unbanned
2017-01-25 11:52:55 +01:00
{
userId: "@user_1:some.domain",
prevMembership: "ban",
membership: "leave",
senderId: "@some_other_user:some.domain",
},
2017-01-17 12:01:54 +01:00
// kicked
2017-01-25 11:52:55 +01:00
{
userId: "@user_1:some.domain",
prevMembership: "join",
membership: "leave",
senderId: "@some_other_user:some.domain",
},
// 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 11:52:55 +01:00
{
userId: "@user_1:some.domain",
prevMembership: "????",
membership: "leave",
senderId: "@some_other_user:some.domain",
},
2017-01-17 12:01:54 +01:00
]);
const props = {
2017-01-25 11:52:55 +01:00
events: events,
children: generateTiles(events),
summaryLength: 1,
avatarsMaxLength: 5,
threshold: 3,
2017-01-17 12:01:54 +01:00
};
2017-01-25 11:52:55 +01:00
const instance = ReactTestUtils.renderIntoDocument(
<MemberEventListSummary {...props} />,
2017-01-25 11:52:55 +01:00
);
const summary = ReactTestUtils.findRenderedDOMComponentWithClass(
instance, "mx_MemberEventListSummary_summary",
2017-01-25 11:52:55 +01:00
);
2017-01-17 12:01:54 +01:00
const summaryText = summary.innerText;
expect(summaryText).toBe(
2017-01-25 11:52:55 +01:00
"user_1 was invited, was banned, joined, rejected their invitation, left, " +
"had their invitation withdrawn, was unbanned, was kicked, left and was kicked",
2017-01-17 12:01:54 +01:00
);
});
it('handles invitation plurals correctly when there are multiple users', function() {
2017-01-17 12:01:54 +01:00
const events = generateEvents([
2017-01-25 11:52:55 +01: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 12:01:54 +01:00
]);
const props = {
2017-01-25 11:52:55 +01:00
events: events,
children: generateTiles(events),
summaryLength: 1,
avatarsMaxLength: 5,
threshold: 3,
2017-01-17 12:01:54 +01:00
};
2017-01-25 11:52:55 +01:00
const instance = ReactTestUtils.renderIntoDocument(
<MemberEventListSummary {...props} />,
2017-01-25 11:52:55 +01:00
);
const summary = ReactTestUtils.findRenderedDOMComponentWithClass(
instance, "mx_MemberEventListSummary_summary",
2017-01-25 11:52:55 +01:00
);
2017-01-17 12:01:54 +01:00
const summaryText = summary.innerText;
expect(summaryText).toBe(
"user_1 and one other rejected their invitations and " +
"had their invitations withdrawn",
2017-01-17 12:01:54 +01:00
);
});
2017-01-25 11:52:55 +01:00
it('handles invitation plurals correctly when there are multiple invites',
function() {
2017-01-17 12:01:54 +01:00
const events = generateEvents([
2017-01-25 11:52:55 +01:00
{
userId: "@user_1:some.domain",
prevMembership: "invite",
membership: "leave",
},
{
userId: "@user_1:some.domain",
prevMembership: "invite",
membership: "leave",
},
2017-01-17 12:01:54 +01:00
]);
const props = {
2017-01-25 11:52:55 +01:00
events: events,
children: generateTiles(events),
summaryLength: 1,
avatarsMaxLength: 5,
threshold: 1, // threshold = 1 to force collapse
2017-01-17 12:01:54 +01:00
};
2017-01-25 11:52:55 +01:00
const instance = ReactTestUtils.renderIntoDocument(
<MemberEventListSummary {...props} />,
2017-01-25 11:52:55 +01:00
);
const summary = ReactTestUtils.findRenderedDOMComponentWithClass(
instance, "mx_MemberEventListSummary_summary",
2017-01-25 11:52:55 +01:00
);
2017-01-17 12:01:54 +01:00
const summaryText = summary.innerText;
expect(summaryText).toBe(
"user_1 rejected their invitation 2 times",
2017-01-17 12:01:54 +01:00
);
});
it('handles a summary length = 2, with no "others"', function() {
2017-01-17 12:01:54 +01:00
const events = generateEvents([
2017-01-25 11:52:55 +01: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 12:01:54 +01:00
]);
const props = {
2017-01-25 11:52:55 +01:00
events: events,
children: generateTiles(events),
summaryLength: 2,
avatarsMaxLength: 5,
threshold: 3,
2017-01-17 12:01:54 +01:00
};
2017-01-25 11:52:55 +01:00
const instance = ReactTestUtils.renderIntoDocument(
<MemberEventListSummary {...props} />,
2017-01-25 11:52:55 +01:00
);
const summary = ReactTestUtils.findRenderedDOMComponentWithClass(
instance, "mx_MemberEventListSummary_summary",
2017-01-25 11:52:55 +01:00
);
2017-01-17 12:01:54 +01:00
const summaryText = summary.innerText;
expect(summaryText).toBe(
"user_1 and user_2 joined 2 times",
2017-01-17 12:01:54 +01:00
);
});
it('handles a summary length = 2, with 1 "other"', function() {
2017-01-17 12:01:54 +01:00
const events = generateEvents([
2017-01-25 11:52:55 +01: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 12:01:54 +01:00
]);
const props = {
2017-01-25 11:52:55 +01:00
events: events,
children: generateTiles(events),
summaryLength: 2,
avatarsMaxLength: 5,
threshold: 3,
2017-01-17 12:01:54 +01:00
};
2017-01-25 11:52:55 +01:00
const instance = ReactTestUtils.renderIntoDocument(
<MemberEventListSummary {...props} />,
2017-01-25 11:52:55 +01:00
);
const summary = ReactTestUtils.findRenderedDOMComponentWithClass(
instance, "mx_MemberEventListSummary_summary",
2017-01-25 11:52:55 +01:00
);
2017-01-17 12:01:54 +01:00
const summaryText = summary.innerText;
expect(summaryText).toBe(
"user_1, user_2 and one other joined",
2017-01-17 12:01:54 +01:00
);
});
it('handles a summary length = 2, with many "others"', function() {
2017-01-17 12:01:54 +01:00
const events = generateEventsForUsers("@user_$:some.domain", 20, [
{membership: "join"},
]);
const props = {
2017-01-25 11:52:55 +01:00
events: events,
children: generateTiles(events),
summaryLength: 2,
avatarsMaxLength: 5,
threshold: 3,
2017-01-17 12:01:54 +01:00
};
2017-01-25 11:52:55 +01:00
const instance = ReactTestUtils.renderIntoDocument(
<MemberEventListSummary {...props} />,
2017-01-25 11:52:55 +01:00
);
const summary = ReactTestUtils.findRenderedDOMComponentWithClass(
instance, "mx_MemberEventListSummary_summary",
2017-01-25 11:52:55 +01:00
);
2017-01-17 12:01:54 +01:00
const summaryText = summary.innerText;
expect(summaryText).toBe(
"user_0, user_1 and 18 others joined",
2017-01-17 12:01:54 +01:00
);
});
2017-01-25 11:52:55 +01:00
});