mirror of
https://github.com/Novaloop-AG/healthchat-web.git
synced 2026-11-30 21:42:00 +00:00
Apply prettier formatting
This commit is contained in:
@@ -14,23 +14,23 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import React from "react";
|
||||
// eslint-disable-next-line deprecate/import
|
||||
import { mount, ReactWrapper } from 'enzyme';
|
||||
import { MatrixEvent, RoomMember } from 'matrix-js-sdk/src/matrix';
|
||||
import { mount, ReactWrapper } from "enzyme";
|
||||
import { MatrixEvent, RoomMember } from "matrix-js-sdk/src/matrix";
|
||||
|
||||
import {
|
||||
getMockClientWithEventEmitter,
|
||||
mkMembership,
|
||||
mockClientMethodsUser,
|
||||
unmockClientPeg,
|
||||
} from '../../../test-utils';
|
||||
} from "../../../test-utils";
|
||||
import EventListSummary from "../../../../src/components/views/elements/EventListSummary";
|
||||
import { Layout } from '../../../../src/settings/enums/Layout';
|
||||
import MatrixClientContext from '../../../../src/contexts/MatrixClientContext';
|
||||
import { Layout } from "../../../../src/settings/enums/Layout";
|
||||
import MatrixClientContext from "../../../../src/contexts/MatrixClientContext";
|
||||
|
||||
describe('EventListSummary', function() {
|
||||
const roomId = '!room:server.org';
|
||||
describe("EventListSummary", function () {
|
||||
const roomId = "!room:server.org";
|
||||
// Generate dummy event tiles for use in simulating an expanded MELS
|
||||
const generateTiles = (events: MatrixEvent[]) => {
|
||||
return events.map((e) => {
|
||||
@@ -64,13 +64,14 @@ describe('EventListSummary', function() {
|
||||
prevMembership?: string;
|
||||
}
|
||||
const generateMembershipEvent = (
|
||||
eventId: string, { senderId, userId, membership, prevMembership }: MembershipEventParams,
|
||||
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');
|
||||
jest.spyOn(member, "getAvatarUrl").mockReturnValue("avatar.jpeg");
|
||||
jest.spyOn(member, "getMxcAvatarUrl").mockReturnValue("mxc://avatar.url/image.png");
|
||||
const e = mkMembership({
|
||||
event: true,
|
||||
room: roomId,
|
||||
@@ -102,7 +103,7 @@ describe('EventListSummary', function() {
|
||||
let eventsForUsers = [];
|
||||
let userId = "";
|
||||
for (let i = 0; i < n; i++) {
|
||||
userId = userIdTemplate.replace('$', i);
|
||||
userId = userIdTemplate.replace("$", i);
|
||||
events.forEach((e) => {
|
||||
e.userId = userId;
|
||||
});
|
||||
@@ -121,13 +122,14 @@ describe('EventListSummary', function() {
|
||||
children: [],
|
||||
};
|
||||
const renderComponent = (props = {}): ReactWrapper => {
|
||||
return mount(<MatrixClientContext.Provider value={mockClient}>
|
||||
<EventListSummary {...defaultProps} {...props} />
|
||||
</MatrixClientContext.Provider>,
|
||||
return mount(
|
||||
<MatrixClientContext.Provider value={mockClient}>
|
||||
<EventListSummary {...defaultProps} {...props} />
|
||||
</MatrixClientContext.Provider>,
|
||||
);
|
||||
};
|
||||
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
@@ -135,10 +137,8 @@ describe('EventListSummary', function() {
|
||||
unmockClientPeg();
|
||||
});
|
||||
|
||||
it('renders expanded events if there are less than props.threshold', function() {
|
||||
const events = generateEvents([
|
||||
{ userId: "@user_1:some.domain", prevMembership: "leave", membership: "join" },
|
||||
]);
|
||||
it("renders expanded events if there are less than props.threshold", function () {
|
||||
const events = generateEvents([{ userId: "@user_1:some.domain", prevMembership: "leave", membership: "join" }]);
|
||||
const props = {
|
||||
events: events,
|
||||
children: generateTiles(events),
|
||||
@@ -149,12 +149,14 @@ describe('EventListSummary', function() {
|
||||
|
||||
const wrapper = renderComponent(props); // matrix cli context wrapper
|
||||
|
||||
expect(wrapper.find('GenericEventListSummary').props().children).toEqual([
|
||||
<div className="event_tile" key="event0">Expanded membership</div>,
|
||||
expect(wrapper.find("GenericEventListSummary").props().children).toEqual([
|
||||
<div className="event_tile" key="event0">
|
||||
Expanded membership
|
||||
</div>,
|
||||
]);
|
||||
});
|
||||
|
||||
it('renders expanded events if there are less than props.threshold', function() {
|
||||
it("renders expanded events if there are less than props.threshold", function () {
|
||||
const events = generateEvents([
|
||||
{ userId: "@user_1:some.domain", prevMembership: "leave", membership: "join" },
|
||||
{ userId: "@user_1:some.domain", prevMembership: "join", membership: "leave" },
|
||||
@@ -169,13 +171,17 @@ describe('EventListSummary', function() {
|
||||
|
||||
const wrapper = renderComponent(props); // matrix cli context wrapper
|
||||
|
||||
expect(wrapper.find('GenericEventListSummary').props().children).toEqual([
|
||||
<div className="event_tile" key="event0">Expanded membership</div>,
|
||||
<div className="event_tile" key="event1">Expanded membership</div>,
|
||||
expect(wrapper.find("GenericEventListSummary").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() {
|
||||
it("renders collapsed events if events.length = props.threshold", function () {
|
||||
const events = generateEvents([
|
||||
{ userId: "@user_1:some.domain", prevMembership: "leave", membership: "join" },
|
||||
{ userId: "@user_1:some.domain", prevMembership: "join", membership: "leave" },
|
||||
@@ -196,7 +202,7 @@ describe('EventListSummary', function() {
|
||||
expect(summaryText).toBe("user_1 joined and left and joined");
|
||||
});
|
||||
|
||||
it('truncates long join,leave repetitions', function() {
|
||||
it("truncates long join,leave repetitions", function () {
|
||||
const events = generateEvents([
|
||||
{ userId: "@user_1:some.domain", prevMembership: "leave", membership: "join" },
|
||||
{ userId: "@user_1:some.domain", prevMembership: "join", membership: "leave" },
|
||||
@@ -228,7 +234,7 @@ describe('EventListSummary', function() {
|
||||
expect(summaryText).toBe("user_1 joined and left 7 times");
|
||||
});
|
||||
|
||||
it('truncates long join,leave repetitions between other events', function() {
|
||||
it("truncates long join,leave repetitions between other events", function () {
|
||||
const events = generateEvents([
|
||||
{
|
||||
userId: "@user_1:some.domain",
|
||||
@@ -269,12 +275,10 @@ describe('EventListSummary', function() {
|
||||
const summary = wrapper.find(".mx_GenericEventListSummary_summary");
|
||||
const summaryText = summary.text();
|
||||
|
||||
expect(summaryText).toBe(
|
||||
"user_1 was unbanned, joined and left 7 times and was invited",
|
||||
);
|
||||
expect(summaryText).toBe("user_1 was unbanned, joined and left 7 times and was invited");
|
||||
});
|
||||
|
||||
it('truncates multiple sequences of repetitions with other events between', function() {
|
||||
it("truncates multiple sequences of repetitions with other events between", function () {
|
||||
const events = generateEvents([
|
||||
{
|
||||
userId: "@user_1:some.domain",
|
||||
@@ -318,12 +322,11 @@ describe('EventListSummary', function() {
|
||||
const summaryText = summary.text();
|
||||
|
||||
expect(summaryText).toBe(
|
||||
"user_1 was unbanned, joined and left 2 times, was banned, " +
|
||||
"joined and left 3 times and was invited",
|
||||
"user_1 was unbanned, joined and left 2 times, was banned, " + "joined and left 3 times and was invited",
|
||||
);
|
||||
});
|
||||
|
||||
it('handles multiple users following the same sequence of memberships', function() {
|
||||
it("handles multiple users following the same sequence of memberships", function () {
|
||||
const events = generateEvents([
|
||||
// user_1
|
||||
{
|
||||
@@ -372,12 +375,10 @@ describe('EventListSummary', function() {
|
||||
const summary = wrapper.find(".mx_GenericEventListSummary_summary");
|
||||
const summaryText = summary.text();
|
||||
|
||||
expect(summaryText).toBe(
|
||||
"user_1 and one other were unbanned, joined and left 2 times and were banned",
|
||||
);
|
||||
expect(summaryText).toBe("user_1 and one other were unbanned, joined and left 2 times and were banned");
|
||||
});
|
||||
|
||||
it('handles many users following the same sequence of memberships', function() {
|
||||
it("handles many users following the same sequence of memberships", function () {
|
||||
const events = generateEventsForUsers("@user_$:some.domain", 20, [
|
||||
{
|
||||
prevMembership: "ban",
|
||||
@@ -406,12 +407,10 @@ describe('EventListSummary', function() {
|
||||
const summary = wrapper.find(".mx_GenericEventListSummary_summary");
|
||||
const summaryText = summary.text();
|
||||
|
||||
expect(summaryText).toBe(
|
||||
"user_0 and 19 others were unbanned, joined and left 2 times and were banned",
|
||||
);
|
||||
expect(summaryText).toBe("user_0 and 19 others were unbanned, joined and left 2 times and were banned");
|
||||
});
|
||||
|
||||
it('correctly orders sequences of transitions by the order of their first event', function() {
|
||||
it("correctly orders sequences of transitions by the order of their first event", function () {
|
||||
const events = generateEvents([
|
||||
{
|
||||
userId: "@user_2:some.domain",
|
||||
@@ -454,11 +453,11 @@ describe('EventListSummary', function() {
|
||||
|
||||
expect(summaryText).toBe(
|
||||
"user_2 was unbanned and joined and left 2 times, user_1 was unbanned, " +
|
||||
"joined and left 2 times and was banned",
|
||||
"joined and left 2 times and was banned",
|
||||
);
|
||||
});
|
||||
|
||||
it('correctly identifies transitions', function() {
|
||||
it("correctly identifies transitions", function () {
|
||||
const events = generateEvents([
|
||||
// invited
|
||||
{ userId: "@user_1:some.domain", membership: "invite" },
|
||||
@@ -524,11 +523,11 @@ describe('EventListSummary', function() {
|
||||
|
||||
expect(summaryText).toBe(
|
||||
"user_1 was invited, was banned, joined, rejected their invitation, left, " +
|
||||
"had their invitation withdrawn, was unbanned, was removed, left and was removed",
|
||||
"had their invitation withdrawn, was unbanned, was removed, left and was removed",
|
||||
);
|
||||
});
|
||||
|
||||
it('handles invitation plurals correctly when there are multiple users', function() {
|
||||
it("handles invitation plurals correctly when there are multiple users", function () {
|
||||
const events = generateEvents([
|
||||
{
|
||||
userId: "@user_1:some.domain",
|
||||
@@ -566,12 +565,11 @@ describe('EventListSummary', function() {
|
||||
const summaryText = summary.text();
|
||||
|
||||
expect(summaryText).toBe(
|
||||
"user_1 and one other rejected their invitations and " +
|
||||
"had their invitations withdrawn",
|
||||
"user_1 and one other rejected their invitations and " + "had their invitations withdrawn",
|
||||
);
|
||||
});
|
||||
|
||||
it('handles invitation plurals correctly when there are multiple invites', function() {
|
||||
it("handles invitation plurals correctly when there are multiple invites", function () {
|
||||
const events = generateEvents([
|
||||
{
|
||||
userId: "@user_1:some.domain",
|
||||
@@ -596,12 +594,10 @@ describe('EventListSummary', function() {
|
||||
const summary = wrapper.find(".mx_GenericEventListSummary_summary");
|
||||
const summaryText = summary.text();
|
||||
|
||||
expect(summaryText).toBe(
|
||||
"user_1 rejected their invitation 2 times",
|
||||
);
|
||||
expect(summaryText).toBe("user_1 rejected their invitation 2 times");
|
||||
});
|
||||
|
||||
it('handles a summary length = 2, with no "others"', function() {
|
||||
it('handles a summary length = 2, with no "others"', function () {
|
||||
const events = generateEvents([
|
||||
{ userId: "@user_1:some.domain", membership: "join" },
|
||||
{ userId: "@user_1:some.domain", membership: "join" },
|
||||
@@ -620,12 +616,10 @@ describe('EventListSummary', function() {
|
||||
const summary = wrapper.find(".mx_GenericEventListSummary_summary");
|
||||
const summaryText = summary.text();
|
||||
|
||||
expect(summaryText).toBe(
|
||||
"user_1 and user_2 joined 2 times",
|
||||
);
|
||||
expect(summaryText).toBe("user_1 and user_2 joined 2 times");
|
||||
});
|
||||
|
||||
it('handles a summary length = 2, with 1 "other"', function() {
|
||||
it('handles a summary length = 2, with 1 "other"', function () {
|
||||
const events = generateEvents([
|
||||
{ userId: "@user_1:some.domain", membership: "join" },
|
||||
{ userId: "@user_2:some.domain", membership: "join" },
|
||||
@@ -643,15 +637,11 @@ describe('EventListSummary', function() {
|
||||
const summary = wrapper.find(".mx_GenericEventListSummary_summary");
|
||||
const summaryText = summary.text();
|
||||
|
||||
expect(summaryText).toBe(
|
||||
"user_1, user_2 and one other joined",
|
||||
);
|
||||
expect(summaryText).toBe("user_1, user_2 and one other joined");
|
||||
});
|
||||
|
||||
it('handles a summary length = 2, with many "others"', function() {
|
||||
const events = generateEventsForUsers("@user_$:some.domain", 20, [
|
||||
{ membership: "join" },
|
||||
]);
|
||||
it('handles a summary length = 2, with many "others"', function () {
|
||||
const events = generateEventsForUsers("@user_$:some.domain", 20, [{ membership: "join" }]);
|
||||
const props = {
|
||||
events: events,
|
||||
children: generateTiles(events),
|
||||
@@ -664,8 +654,6 @@ describe('EventListSummary', function() {
|
||||
const summary = wrapper.find(".mx_GenericEventListSummary_summary");
|
||||
const summaryText = summary.text();
|
||||
|
||||
expect(summaryText).toBe(
|
||||
"user_0, user_1 and 18 others joined",
|
||||
);
|
||||
expect(summaryText).toBe("user_0, user_1 and 18 others joined");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user