2016-03-30 23:48:46 +00:00
|
|
|
/*
|
|
|
|
Copyright 2016 OpenMarket Ltd
|
2021-07-01 19:54:04 +00:00
|
|
|
Copyright 2019, 2021 The Matrix.org Foundation C.I.C.
|
2016-03-30 23:48:46 +00:00
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
2019-09-06 14:04:46 +00:00
|
|
|
import React from 'react';
|
|
|
|
import ReactDOM from "react-dom";
|
2019-03-15 08:57:26 +00:00
|
|
|
import { EventEmitter } from "events";
|
2022-03-01 20:42:05 +00:00
|
|
|
import * as Matrix from 'matrix-js-sdk/src/matrix';
|
2021-07-01 20:52:15 +00:00
|
|
|
import FakeTimers from '@sinonjs/fake-timers';
|
2021-10-13 10:09:43 +00:00
|
|
|
import { mount } from "enzyme";
|
2022-03-09 11:22:36 +00:00
|
|
|
import * as TestUtils from "react-dom/test-utils";
|
2020-02-13 22:25:54 +00:00
|
|
|
|
2021-10-22 22:23:32 +00:00
|
|
|
import { MatrixClientPeg } from '../../../src/MatrixClientPeg';
|
2022-03-26 22:06:25 +00:00
|
|
|
import MessagePanel, { shouldFormContinuation } from "../../../src/components/structures/MessagePanel";
|
2021-10-22 22:23:32 +00:00
|
|
|
import SettingsStore from "../../../src/settings/SettingsStore";
|
2019-12-17 17:26:12 +00:00
|
|
|
import MatrixClientContext from "../../../src/contexts/MatrixClientContext";
|
|
|
|
import RoomContext from "../../../src/contexts/RoomContext";
|
2020-11-05 16:27:41 +00:00
|
|
|
import DMRoomMap from "../../../src/utils/DMRoomMap";
|
2022-03-09 11:22:36 +00:00
|
|
|
import { UnwrappedEventTile } from "../../../src/components/views/rooms/EventTile";
|
|
|
|
import * as TestUtilsMatrix from "../../test-utils";
|
2022-03-02 21:09:24 +00:00
|
|
|
import EventListSummary from "../../../src/components/views/elements/EventListSummary";
|
|
|
|
import GenericEventListSummary from "../../../src/components/views/elements/GenericEventListSummary";
|
|
|
|
import DateSeparator from "../../../src/components/views/messages/DateSeparator";
|
2022-05-03 09:04:47 +00:00
|
|
|
import { makeBeaconInfoEvent } from '../../test-utils';
|
|
|
|
|
|
|
|
jest.mock('../../../src/utils/beacon', () => ({
|
|
|
|
useBeacon: jest.fn(),
|
|
|
|
}));
|
2021-10-22 22:23:32 +00:00
|
|
|
|
2017-10-11 16:56:17 +00:00
|
|
|
let client;
|
2021-06-18 16:56:18 +00:00
|
|
|
const room = new Matrix.Room("!roomId:server_name");
|
2016-11-14 18:20:15 +00:00
|
|
|
|
|
|
|
// wrap MessagePanel with a component which provides the MatrixClient in the context.
|
2020-08-29 11:14:16 +00:00
|
|
|
class WrappedMessagePanel extends React.Component {
|
2022-01-27 11:08:28 +00:00
|
|
|
resizeNotifier = new EventEmitter();
|
|
|
|
callEventGroupers = new Map();
|
2020-08-29 11:14:16 +00:00
|
|
|
|
|
|
|
render() {
|
2022-04-21 16:57:08 +00:00
|
|
|
const { showHiddenEvents, ...props } = this.props;
|
|
|
|
|
2021-06-05 14:49:44 +00:00
|
|
|
const roomContext = {
|
|
|
|
room,
|
|
|
|
roomId: room.roomId,
|
|
|
|
canReact: true,
|
2022-03-04 15:53:22 +00:00
|
|
|
canSendMessages: true,
|
2021-06-05 14:49:44 +00:00
|
|
|
showReadReceipts: true,
|
|
|
|
showRedactions: false,
|
|
|
|
showJoinLeaves: false,
|
|
|
|
showAvatarChanges: false,
|
|
|
|
showDisplaynameChanges: true,
|
2022-04-21 16:57:08 +00:00
|
|
|
showHiddenEvents,
|
2021-06-05 14:49:44 +00:00
|
|
|
};
|
|
|
|
|
2019-12-17 17:26:12 +00:00
|
|
|
return <MatrixClientContext.Provider value={client}>
|
2021-06-05 14:49:44 +00:00
|
|
|
<RoomContext.Provider value={roomContext}>
|
2022-01-27 11:08:28 +00:00
|
|
|
<MessagePanel
|
|
|
|
room={room}
|
2022-04-21 16:57:08 +00:00
|
|
|
{...props}
|
2022-01-27 11:08:28 +00:00
|
|
|
resizeNotifier={this.resizeNotifier}
|
|
|
|
callEventGroupers={this.callEventGroupers}
|
|
|
|
/>
|
2019-12-17 17:26:12 +00:00
|
|
|
</RoomContext.Provider>
|
|
|
|
</MatrixClientContext.Provider>;
|
2020-08-29 11:14:16 +00:00
|
|
|
}
|
|
|
|
}
|
2016-11-14 18:20:15 +00:00
|
|
|
|
2017-10-11 16:56:17 +00:00
|
|
|
describe('MessagePanel', function() {
|
2021-07-01 20:52:15 +00:00
|
|
|
let clock = null;
|
2017-10-11 16:56:17 +00:00
|
|
|
const realSetTimeout = window.setTimeout;
|
|
|
|
const events = mkEvents();
|
2016-03-30 23:48:46 +00:00
|
|
|
|
2016-04-07 15:47:17 +00:00
|
|
|
beforeEach(function() {
|
2021-07-01 19:54:04 +00:00
|
|
|
TestUtilsMatrix.stubClient();
|
2017-09-15 02:47:24 +00:00
|
|
|
client = MatrixClientPeg.get();
|
2021-07-01 19:43:05 +00:00
|
|
|
client.credentials = { userId: '@me:here' };
|
2017-10-29 07:43:52 +00:00
|
|
|
|
|
|
|
// HACK: We assume all settings want to be disabled
|
2019-12-16 11:55:01 +00:00
|
|
|
SettingsStore.getValue = jest.fn((arg) => {
|
|
|
|
return arg === "showDisplaynameChanges";
|
|
|
|
});
|
2019-03-20 17:43:19 +00:00
|
|
|
|
2020-11-05 16:27:41 +00:00
|
|
|
DMRoomMap.makeShared();
|
2016-04-07 15:47:17 +00:00
|
|
|
});
|
|
|
|
|
2021-06-09 10:57:29 +00:00
|
|
|
afterEach(function() {
|
2021-07-01 20:52:15 +00:00
|
|
|
if (clock) {
|
|
|
|
clock.uninstall();
|
|
|
|
clock = null;
|
|
|
|
}
|
2016-03-30 23:48:46 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
function mkEvents() {
|
2017-10-11 16:56:17 +00:00
|
|
|
const events = [];
|
|
|
|
const ts0 = Date.now();
|
|
|
|
for (let i = 0; i < 10; i++) {
|
2021-07-01 19:54:04 +00:00
|
|
|
events.push(TestUtilsMatrix.mkMessage(
|
2016-03-30 23:48:46 +00:00
|
|
|
{
|
|
|
|
event: true, room: "!room:id", user: "@user:id",
|
2021-05-07 06:15:52 +00:00
|
|
|
ts: ts0 + i * 1000,
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
return events;
|
|
|
|
}
|
|
|
|
|
2021-05-11 01:56:30 +00:00
|
|
|
// Just to avoid breaking Dateseparator tests that might run at 00hrs
|
2021-05-07 06:15:52 +00:00
|
|
|
function mkOneDayEvents() {
|
|
|
|
const events = [];
|
|
|
|
const ts0 = Date.parse('09 May 2004 00:12:00 GMT');
|
|
|
|
for (let i = 0; i < 10; i++) {
|
2021-07-01 19:54:04 +00:00
|
|
|
events.push(TestUtilsMatrix.mkMessage(
|
2021-05-07 06:15:52 +00:00
|
|
|
{
|
|
|
|
event: true, room: "!room:id", user: "@user:id",
|
|
|
|
ts: ts0 + i * 1000,
|
2016-03-30 23:48:46 +00:00
|
|
|
}));
|
|
|
|
}
|
|
|
|
return events;
|
|
|
|
}
|
|
|
|
|
2022-02-09 10:51:12 +00:00
|
|
|
// make a collection of events with some member events that should be collapsed with an EventListSummary
|
2019-11-26 19:06:02 +00:00
|
|
|
function mkMelsEvents() {
|
|
|
|
const events = [];
|
|
|
|
const ts0 = Date.now();
|
|
|
|
|
|
|
|
let i = 0;
|
2021-07-01 19:54:04 +00:00
|
|
|
events.push(TestUtilsMatrix.mkMessage({
|
2019-11-26 19:06:02 +00:00
|
|
|
event: true, room: "!room:id", user: "@user:id",
|
2021-05-07 06:15:52 +00:00
|
|
|
ts: ts0 + ++i * 1000,
|
2019-11-26 19:06:02 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
for (i = 0; i < 10; i++) {
|
2021-07-01 19:54:04 +00:00
|
|
|
events.push(TestUtilsMatrix.mkMembership({
|
2019-11-26 19:06:02 +00:00
|
|
|
event: true, room: "!room:id", user: "@user:id",
|
|
|
|
target: {
|
|
|
|
userId: "@user:id",
|
|
|
|
name: "Bob",
|
|
|
|
getAvatarUrl: () => {
|
|
|
|
return "avatar.jpeg";
|
|
|
|
},
|
2021-03-11 16:42:55 +00:00
|
|
|
getMxcAvatarUrl: () => 'mxc://avatar.url/image.png',
|
2019-11-26 19:06:02 +00:00
|
|
|
},
|
|
|
|
ts: ts0 + i*1000,
|
|
|
|
mship: 'join',
|
|
|
|
prevMship: 'join',
|
|
|
|
name: 'A user',
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
2021-07-01 19:54:04 +00:00
|
|
|
events.push(TestUtilsMatrix.mkMessage({
|
2019-11-26 19:06:02 +00:00
|
|
|
event: true, room: "!room:id", user: "@user:id",
|
|
|
|
ts: ts0 + ++i*1000,
|
|
|
|
}));
|
|
|
|
|
|
|
|
return events;
|
|
|
|
}
|
|
|
|
|
2020-04-02 14:07:50 +00:00
|
|
|
// A list of membership events only with nothing else
|
|
|
|
function mkMelsEventsOnly() {
|
|
|
|
const events = [];
|
|
|
|
const ts0 = Date.now();
|
|
|
|
|
|
|
|
let i = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < 10; i++) {
|
2021-07-01 19:54:04 +00:00
|
|
|
events.push(TestUtilsMatrix.mkMembership({
|
2020-04-02 14:07:50 +00:00
|
|
|
event: true, room: "!room:id", user: "@user:id",
|
|
|
|
target: {
|
|
|
|
userId: "@user:id",
|
|
|
|
name: "Bob",
|
|
|
|
getAvatarUrl: () => {
|
|
|
|
return "avatar.jpeg";
|
|
|
|
},
|
2021-03-11 16:42:55 +00:00
|
|
|
getMxcAvatarUrl: () => 'mxc://avatar.url/image.png',
|
2020-04-02 14:07:50 +00:00
|
|
|
},
|
2021-05-07 06:15:52 +00:00
|
|
|
ts: ts0 + i * 1000,
|
2020-04-02 14:07:50 +00:00
|
|
|
mship: 'join',
|
|
|
|
prevMship: 'join',
|
|
|
|
name: 'A user',
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
|
|
|
return events;
|
|
|
|
}
|
|
|
|
|
|
|
|
// A list of room creation, encryption, and invite events.
|
|
|
|
function mkCreationEvents() {
|
2021-07-01 19:54:04 +00:00
|
|
|
const mkEvent = TestUtilsMatrix.mkEvent;
|
|
|
|
const mkMembership = TestUtilsMatrix.mkMembership;
|
2020-04-02 14:07:50 +00:00
|
|
|
const roomId = "!someroom";
|
|
|
|
const alice = "@alice:example.org";
|
|
|
|
const ts0 = Date.now();
|
|
|
|
|
|
|
|
return [
|
|
|
|
mkEvent({
|
|
|
|
event: true,
|
|
|
|
type: "m.room.create",
|
2022-02-21 16:57:44 +00:00
|
|
|
sender: '@test:example.org',
|
2020-04-02 14:07:50 +00:00
|
|
|
room: roomId,
|
|
|
|
user: alice,
|
|
|
|
content: {
|
|
|
|
creator: alice,
|
|
|
|
room_version: "5",
|
|
|
|
predecessor: {
|
|
|
|
room_id: "!prevroom",
|
|
|
|
event_id: "$someevent",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
ts: ts0,
|
|
|
|
}),
|
|
|
|
mkMembership({
|
|
|
|
event: true,
|
|
|
|
room: roomId,
|
|
|
|
user: alice,
|
|
|
|
target: {
|
|
|
|
userId: alice,
|
|
|
|
name: "Alice",
|
|
|
|
getAvatarUrl: () => {
|
|
|
|
return "avatar.jpeg";
|
|
|
|
},
|
2021-03-11 16:42:55 +00:00
|
|
|
getMxcAvatarUrl: () => 'mxc://avatar.url/image.png',
|
2020-04-02 14:07:50 +00:00
|
|
|
},
|
|
|
|
ts: ts0 + 1,
|
|
|
|
mship: 'join',
|
|
|
|
name: 'Alice',
|
|
|
|
}),
|
|
|
|
mkEvent({
|
|
|
|
event: true,
|
|
|
|
type: "m.room.join_rules",
|
|
|
|
room: roomId,
|
|
|
|
user: alice,
|
|
|
|
content: {
|
2020-08-29 11:14:16 +00:00
|
|
|
"join_rule": "invite",
|
2020-04-02 14:07:50 +00:00
|
|
|
},
|
|
|
|
ts: ts0 + 2,
|
|
|
|
}),
|
|
|
|
mkEvent({
|
|
|
|
event: true,
|
|
|
|
type: "m.room.history_visibility",
|
|
|
|
room: roomId,
|
|
|
|
user: alice,
|
|
|
|
content: {
|
|
|
|
"history_visibility": "invited",
|
|
|
|
},
|
|
|
|
ts: ts0 + 3,
|
|
|
|
}),
|
|
|
|
mkEvent({
|
|
|
|
event: true,
|
|
|
|
type: "m.room.encryption",
|
|
|
|
room: roomId,
|
|
|
|
user: alice,
|
|
|
|
content: {
|
|
|
|
"algorithm": "m.megolm.v1.aes-sha2",
|
|
|
|
},
|
|
|
|
ts: ts0 + 4,
|
|
|
|
}),
|
|
|
|
mkMembership({
|
|
|
|
event: true,
|
|
|
|
room: roomId,
|
|
|
|
user: alice,
|
|
|
|
skey: "@bob:example.org",
|
|
|
|
target: {
|
|
|
|
userId: "@bob:example.org",
|
|
|
|
name: "Bob",
|
|
|
|
getAvatarUrl: () => {
|
|
|
|
return "avatar.jpeg";
|
|
|
|
},
|
2021-03-11 16:42:55 +00:00
|
|
|
getMxcAvatarUrl: () => 'mxc://avatar.url/image.png',
|
2020-04-02 14:07:50 +00:00
|
|
|
},
|
|
|
|
ts: ts0 + 5,
|
|
|
|
mship: 'invite',
|
|
|
|
name: 'Bob',
|
|
|
|
}),
|
|
|
|
];
|
|
|
|
}
|
2022-04-14 23:23:22 +00:00
|
|
|
|
|
|
|
function mkMixedHiddenAndShownEvents() {
|
|
|
|
const roomId = "!room:id";
|
|
|
|
const userId = "@alice:example.org";
|
|
|
|
const ts0 = Date.now();
|
|
|
|
|
|
|
|
return [
|
|
|
|
TestUtilsMatrix.mkMessage({
|
|
|
|
event: true,
|
|
|
|
room: roomId,
|
|
|
|
user: userId,
|
|
|
|
ts: ts0,
|
|
|
|
}),
|
|
|
|
TestUtilsMatrix.mkEvent({
|
|
|
|
event: true,
|
|
|
|
type: "org.example.a_hidden_event",
|
|
|
|
room: roomId,
|
|
|
|
user: userId,
|
|
|
|
content: {},
|
|
|
|
ts: ts0 + 1,
|
|
|
|
}),
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2020-04-02 14:07:50 +00:00
|
|
|
function isReadMarkerVisible(rmContainer) {
|
|
|
|
return rmContainer && rmContainer.children.length > 0;
|
|
|
|
}
|
|
|
|
|
2016-03-30 23:48:46 +00:00
|
|
|
it('should show the events', function() {
|
2017-10-11 16:56:17 +00:00
|
|
|
const res = TestUtils.renderIntoDocument(
|
2021-06-09 10:57:29 +00:00
|
|
|
<WrappedMessagePanel className="cls" events={events} />,
|
2016-03-30 23:48:46 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
// just check we have the right number of tiles for now
|
2022-03-09 11:22:36 +00:00
|
|
|
const tiles = TestUtils.scryRenderedComponentsWithType(res, UnwrappedEventTile);
|
2016-03-30 23:48:46 +00:00
|
|
|
expect(tiles.length).toEqual(10);
|
|
|
|
});
|
|
|
|
|
2019-11-26 19:06:02 +00:00
|
|
|
it('should collapse adjacent member events', function() {
|
|
|
|
const res = TestUtils.renderIntoDocument(
|
|
|
|
<WrappedMessagePanel className="cls" events={mkMelsEvents()} />,
|
|
|
|
);
|
|
|
|
|
|
|
|
// just check we have the right number of tiles for now
|
2022-03-09 11:22:36 +00:00
|
|
|
const tiles = TestUtils.scryRenderedComponentsWithType(res, UnwrappedEventTile);
|
2019-11-26 19:06:02 +00:00
|
|
|
expect(tiles.length).toEqual(2);
|
|
|
|
|
|
|
|
const summaryTiles = TestUtils.scryRenderedComponentsWithType(
|
2022-03-02 21:09:24 +00:00
|
|
|
res, EventListSummary,
|
2019-11-26 19:06:02 +00:00
|
|
|
);
|
|
|
|
expect(summaryTiles.length).toEqual(1);
|
|
|
|
});
|
|
|
|
|
2020-04-02 14:07:50 +00:00
|
|
|
it('should insert the read-marker in the right place', function() {
|
2017-10-11 16:56:17 +00:00
|
|
|
const res = TestUtils.renderIntoDocument(
|
2021-07-23 09:23:45 +00:00
|
|
|
<WrappedMessagePanel
|
|
|
|
className="cls"
|
|
|
|
events={events}
|
|
|
|
readMarkerEventId={events[4].getId()}
|
|
|
|
readMarkerVisible={true}
|
|
|
|
/>,
|
2016-03-30 23:48:46 +00:00
|
|
|
);
|
|
|
|
|
2022-03-09 11:22:36 +00:00
|
|
|
const tiles = TestUtils.scryRenderedComponentsWithType(res, UnwrappedEventTile);
|
2016-03-30 23:48:46 +00:00
|
|
|
|
|
|
|
// find the <li> which wraps the read marker
|
2017-10-11 16:56:17 +00:00
|
|
|
const rm = TestUtils.findRenderedDOMComponentWithClass(res, 'mx_RoomView_myReadMarker_container');
|
2016-03-30 23:48:46 +00:00
|
|
|
|
|
|
|
// it should follow the <li> which wraps the event tile for event 4
|
2021-05-21 13:59:26 +00:00
|
|
|
const eventContainer = ReactDOM.findDOMNode(tiles[4]);
|
2016-03-30 23:48:46 +00:00
|
|
|
expect(rm.previousSibling).toEqual(eventContainer);
|
|
|
|
});
|
|
|
|
|
2019-11-26 19:06:02 +00:00
|
|
|
it('should show the read-marker that fall in summarised events after the summary', function() {
|
|
|
|
const melsEvents = mkMelsEvents();
|
|
|
|
const res = TestUtils.renderIntoDocument(
|
2021-07-23 09:23:45 +00:00
|
|
|
<WrappedMessagePanel
|
|
|
|
className="cls"
|
|
|
|
events={melsEvents}
|
|
|
|
readMarkerEventId={melsEvents[4].getId()}
|
|
|
|
readMarkerVisible={true}
|
|
|
|
/>,
|
2019-11-26 19:06:02 +00:00
|
|
|
);
|
|
|
|
|
2022-02-09 10:51:12 +00:00
|
|
|
const summary = TestUtils.findRenderedDOMComponentWithClass(res, 'mx_GenericEventListSummary');
|
2019-11-26 19:06:02 +00:00
|
|
|
|
|
|
|
// find the <li> which wraps the read marker
|
|
|
|
const rm = TestUtils.findRenderedDOMComponentWithClass(res, 'mx_RoomView_myReadMarker_container');
|
|
|
|
|
|
|
|
expect(rm.previousSibling).toEqual(summary);
|
2020-04-02 14:07:50 +00:00
|
|
|
|
|
|
|
// read marker should be visible given props and not at the last event
|
|
|
|
expect(isReadMarkerVisible(rm)).toBeTruthy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should hide the read-marker at the end of summarised events', function() {
|
|
|
|
const melsEvents = mkMelsEventsOnly();
|
|
|
|
const res = TestUtils.renderIntoDocument(
|
2021-07-23 09:23:45 +00:00
|
|
|
<WrappedMessagePanel
|
|
|
|
className="cls"
|
|
|
|
events={melsEvents}
|
|
|
|
readMarkerEventId={melsEvents[9].getId()}
|
|
|
|
readMarkerVisible={true}
|
|
|
|
/>,
|
2020-04-02 14:07:50 +00:00
|
|
|
);
|
|
|
|
|
2022-02-09 10:51:12 +00:00
|
|
|
const summary = TestUtils.findRenderedDOMComponentWithClass(res, 'mx_GenericEventListSummary');
|
2020-04-02 14:07:50 +00:00
|
|
|
|
|
|
|
// find the <li> which wraps the read marker
|
|
|
|
const rm = TestUtils.findRenderedDOMComponentWithClass(res, 'mx_RoomView_myReadMarker_container');
|
|
|
|
|
|
|
|
expect(rm.previousSibling).toEqual(summary);
|
|
|
|
|
|
|
|
// read marker should be hidden given props and at the last event
|
|
|
|
expect(isReadMarkerVisible(rm)).toBeFalsy();
|
2019-11-26 19:06:02 +00:00
|
|
|
});
|
|
|
|
|
2016-03-30 23:48:46 +00:00
|
|
|
it('shows a ghost read-marker when the read-marker moves', function(done) {
|
|
|
|
// fake the clock so that we can test the velocity animation.
|
2021-07-01 20:52:15 +00:00
|
|
|
clock = FakeTimers.install();
|
2016-03-30 23:48:46 +00:00
|
|
|
|
2017-10-11 16:56:17 +00:00
|
|
|
const parentDiv = document.createElement('div');
|
2016-03-30 23:48:46 +00:00
|
|
|
|
|
|
|
// first render with the RM in one place
|
2017-10-11 16:56:17 +00:00
|
|
|
let mp = ReactDOM.render(
|
2021-07-23 09:23:45 +00:00
|
|
|
<WrappedMessagePanel
|
|
|
|
className="cls"
|
|
|
|
events={events}
|
|
|
|
readMarkerEventId={events[4].getId()}
|
2021-06-09 10:57:29 +00:00
|
|
|
readMarkerVisible={true}
|
|
|
|
/>, parentDiv);
|
2016-03-30 23:48:46 +00:00
|
|
|
|
2022-03-09 11:22:36 +00:00
|
|
|
const tiles = TestUtils.scryRenderedComponentsWithType(mp, UnwrappedEventTile);
|
2017-10-11 16:56:17 +00:00
|
|
|
const tileContainers = tiles.map(function(t) {
|
2021-05-21 13:59:26 +00:00
|
|
|
return ReactDOM.findDOMNode(t);
|
2016-03-31 16:01:11 +00:00
|
|
|
});
|
2016-03-30 23:48:46 +00:00
|
|
|
|
|
|
|
// find the <li> which wraps the read marker
|
2017-10-11 16:56:17 +00:00
|
|
|
const rm = TestUtils.findRenderedDOMComponentWithClass(mp, 'mx_RoomView_myReadMarker_container');
|
2016-03-31 16:01:11 +00:00
|
|
|
expect(rm.previousSibling).toEqual(tileContainers[4]);
|
2016-03-30 23:48:46 +00:00
|
|
|
|
|
|
|
// now move the RM
|
|
|
|
mp = ReactDOM.render(
|
2021-07-23 09:23:45 +00:00
|
|
|
<WrappedMessagePanel
|
|
|
|
className="cls"
|
|
|
|
events={events}
|
|
|
|
readMarkerEventId={events[6].getId()}
|
2021-06-09 10:57:29 +00:00
|
|
|
readMarkerVisible={true}
|
|
|
|
/>, parentDiv);
|
2016-03-30 23:48:46 +00:00
|
|
|
|
|
|
|
// now there should be two RM containers
|
2017-10-11 16:56:17 +00:00
|
|
|
const found = TestUtils.scryRenderedDOMComponentsWithClass(mp, 'mx_RoomView_myReadMarker_container');
|
2016-03-30 23:48:46 +00:00
|
|
|
expect(found.length).toEqual(2);
|
2016-04-19 20:10:23 +00:00
|
|
|
|
2016-03-30 23:48:46 +00:00
|
|
|
// the first should be the ghost
|
2016-03-31 16:01:11 +00:00
|
|
|
expect(found[0].previousSibling).toEqual(tileContainers[4]);
|
2017-10-11 16:56:17 +00:00
|
|
|
const hr = found[0].children[0];
|
2016-03-30 23:48:46 +00:00
|
|
|
|
|
|
|
// the second should be the real thing
|
2016-03-31 16:01:11 +00:00
|
|
|
expect(found[1].previousSibling).toEqual(tileContainers[6]);
|
2016-03-30 23:48:46 +00:00
|
|
|
|
|
|
|
// advance the clock, and then let the browser run an animation frame,
|
|
|
|
// to let the animation start
|
|
|
|
clock.tick(1500);
|
2016-04-19 20:10:23 +00:00
|
|
|
|
2016-03-30 23:48:46 +00:00
|
|
|
realSetTimeout(() => {
|
|
|
|
// then advance it again to let it complete
|
|
|
|
clock.tick(1000);
|
|
|
|
realSetTimeout(() => {
|
|
|
|
// the ghost should now have finished
|
2016-03-31 00:01:49 +00:00
|
|
|
expect(hr.style.opacity).toEqual('0');
|
2016-03-30 23:48:46 +00:00
|
|
|
done();
|
|
|
|
}, 100);
|
|
|
|
}, 100);
|
|
|
|
});
|
2020-02-13 22:25:54 +00:00
|
|
|
|
|
|
|
it('should collapse creation events', function() {
|
2020-04-02 14:07:50 +00:00
|
|
|
const events = mkCreationEvents();
|
2022-03-09 11:22:36 +00:00
|
|
|
TestUtilsMatrix.upsertRoomStateEvents(room, events);
|
2020-02-13 22:25:54 +00:00
|
|
|
const res = mount(
|
|
|
|
<WrappedMessagePanel className="cls" events={events} />,
|
|
|
|
);
|
|
|
|
|
|
|
|
// we expect that
|
|
|
|
// - the room creation event, the room encryption event, and Alice inviting Bob,
|
|
|
|
// should be outside of the room creation summary
|
|
|
|
// - all other events should be inside the room creation summary
|
|
|
|
|
2022-03-09 11:22:36 +00:00
|
|
|
const tiles = res.find(UnwrappedEventTile);
|
2020-02-13 22:25:54 +00:00
|
|
|
|
|
|
|
expect(tiles.at(0).props().mxEvent.getType()).toEqual("m.room.create");
|
|
|
|
expect(tiles.at(1).props().mxEvent.getType()).toEqual("m.room.encryption");
|
|
|
|
|
2022-03-02 21:09:24 +00:00
|
|
|
const summaryTiles = res.find(GenericEventListSummary);
|
2020-02-13 22:25:54 +00:00
|
|
|
const summaryTile = summaryTiles.at(0);
|
|
|
|
|
2022-03-09 11:22:36 +00:00
|
|
|
const summaryEventTiles = summaryTile.find(UnwrappedEventTile);
|
2020-02-13 22:25:54 +00:00
|
|
|
// every event except for the room creation, room encryption, and Bob's
|
|
|
|
// invite event should be in the event summary
|
|
|
|
expect(summaryEventTiles.length).toEqual(tiles.length - 3);
|
|
|
|
});
|
2020-04-02 14:07:50 +00:00
|
|
|
|
2022-05-03 09:04:47 +00:00
|
|
|
it('should not collapse beacons as part of creation events', function() {
|
|
|
|
const [creationEvent] = mkCreationEvents();
|
|
|
|
const beaconInfoEvent = makeBeaconInfoEvent(
|
|
|
|
creationEvent.getSender(),
|
|
|
|
creationEvent.getRoomId(),
|
|
|
|
{ isLive: true },
|
|
|
|
);
|
|
|
|
const combinedEvents = [creationEvent, beaconInfoEvent];
|
|
|
|
TestUtilsMatrix.upsertRoomStateEvents(room, combinedEvents);
|
|
|
|
const res = mount(
|
|
|
|
<WrappedMessagePanel className="cls" events={combinedEvents} />,
|
|
|
|
);
|
|
|
|
|
|
|
|
const summaryTiles = res.find(GenericEventListSummary);
|
|
|
|
const summaryTile = summaryTiles.at(0);
|
|
|
|
|
|
|
|
const summaryEventTiles = summaryTile.find(UnwrappedEventTile);
|
|
|
|
// nothing in the summary
|
|
|
|
expect(summaryEventTiles.length).toEqual(0);
|
|
|
|
});
|
|
|
|
|
2020-04-02 14:07:50 +00:00
|
|
|
it('should hide read-marker at the end of creation event summary', function() {
|
|
|
|
const events = mkCreationEvents();
|
2022-03-09 11:22:36 +00:00
|
|
|
TestUtilsMatrix.upsertRoomStateEvents(room, events);
|
2020-04-02 14:07:50 +00:00
|
|
|
const res = mount(
|
|
|
|
<WrappedMessagePanel
|
|
|
|
className="cls"
|
|
|
|
events={events}
|
|
|
|
readMarkerEventId={events[5].getId()}
|
|
|
|
readMarkerVisible={true}
|
|
|
|
/>,
|
|
|
|
);
|
|
|
|
|
|
|
|
// find the <li> which wraps the read marker
|
|
|
|
const rm = res.find('.mx_RoomView_myReadMarker_container').getDOMNode();
|
|
|
|
|
|
|
|
const rows = res.find('.mx_RoomView_MessageList').children();
|
2020-11-05 16:57:51 +00:00
|
|
|
expect(rows.length).toEqual(7); // 6 events + the NewRoomIntro
|
|
|
|
expect(rm.previousSibling).toEqual(rows.at(5).getDOMNode());
|
2020-04-02 14:07:50 +00:00
|
|
|
|
|
|
|
// read marker should be hidden given props and at the last event
|
|
|
|
expect(isReadMarkerVisible(rm)).toBeFalsy();
|
|
|
|
});
|
2021-05-07 06:15:52 +00:00
|
|
|
|
2021-06-09 10:57:29 +00:00
|
|
|
it('should render Date separators for the events', function() {
|
2021-05-11 01:56:30 +00:00
|
|
|
const events = mkOneDayEvents();
|
2021-05-07 06:15:52 +00:00
|
|
|
const res = mount(
|
|
|
|
<WrappedMessagePanel
|
|
|
|
className="cls"
|
|
|
|
events={events}
|
|
|
|
/>,
|
|
|
|
);
|
2022-03-02 21:09:24 +00:00
|
|
|
const Dates = res.find(DateSeparator);
|
2021-05-21 13:59:26 +00:00
|
|
|
|
2021-05-07 06:15:52 +00:00
|
|
|
expect(Dates.length).toEqual(1);
|
2021-05-11 01:56:30 +00:00
|
|
|
});
|
2022-03-01 08:33:07 +00:00
|
|
|
|
|
|
|
it('appends events into summaries during forward pagination without changing key', () => {
|
|
|
|
const events = mkMelsEvents().slice(1, 11);
|
|
|
|
|
|
|
|
const res = mount(<WrappedMessagePanel events={events} />);
|
|
|
|
let els = res.find("EventListSummary");
|
|
|
|
expect(els.length).toEqual(1);
|
|
|
|
expect(els.key()).toEqual("eventlistsummary-" + events[0].getId());
|
|
|
|
expect(els.prop("events").length).toEqual(10);
|
|
|
|
|
|
|
|
res.setProps({
|
|
|
|
events: [
|
|
|
|
...events,
|
|
|
|
TestUtilsMatrix.mkMembership({
|
|
|
|
event: true,
|
|
|
|
room: "!room:id",
|
|
|
|
user: "@user:id",
|
|
|
|
target: {
|
|
|
|
userId: "@user:id",
|
|
|
|
name: "Bob",
|
|
|
|
getAvatarUrl: () => {
|
|
|
|
return "avatar.jpeg";
|
|
|
|
},
|
|
|
|
getMxcAvatarUrl: () => 'mxc://avatar.url/image.png',
|
|
|
|
},
|
|
|
|
ts: Date.now(),
|
|
|
|
mship: 'join',
|
|
|
|
prevMship: 'join',
|
|
|
|
name: 'A user',
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
});
|
|
|
|
|
|
|
|
els = res.find("EventListSummary");
|
|
|
|
expect(els.length).toEqual(1);
|
|
|
|
expect(els.key()).toEqual("eventlistsummary-" + events[0].getId());
|
|
|
|
expect(els.prop("events").length).toEqual(11);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('prepends events into summaries during backward pagination without changing key', () => {
|
|
|
|
const events = mkMelsEvents().slice(1, 11);
|
|
|
|
|
|
|
|
const res = mount(<WrappedMessagePanel events={events} />);
|
|
|
|
let els = res.find("EventListSummary");
|
|
|
|
expect(els.length).toEqual(1);
|
|
|
|
expect(els.key()).toEqual("eventlistsummary-" + events[0].getId());
|
|
|
|
expect(els.prop("events").length).toEqual(10);
|
|
|
|
|
|
|
|
res.setProps({
|
|
|
|
events: [
|
|
|
|
TestUtilsMatrix.mkMembership({
|
|
|
|
event: true,
|
|
|
|
room: "!room:id",
|
|
|
|
user: "@user:id",
|
|
|
|
target: {
|
|
|
|
userId: "@user:id",
|
|
|
|
name: "Bob",
|
|
|
|
getAvatarUrl: () => {
|
|
|
|
return "avatar.jpeg";
|
|
|
|
},
|
|
|
|
getMxcAvatarUrl: () => 'mxc://avatar.url/image.png',
|
|
|
|
},
|
|
|
|
ts: Date.now(),
|
|
|
|
mship: 'join',
|
|
|
|
prevMship: 'join',
|
|
|
|
name: 'A user',
|
|
|
|
}),
|
|
|
|
...events,
|
|
|
|
],
|
|
|
|
});
|
|
|
|
|
|
|
|
els = res.find("EventListSummary");
|
|
|
|
expect(els.length).toEqual(1);
|
|
|
|
expect(els.key()).toEqual("eventlistsummary-" + events[0].getId());
|
|
|
|
expect(els.prop("events").length).toEqual(11);
|
|
|
|
});
|
2022-03-02 16:46:51 +00:00
|
|
|
|
|
|
|
it('assigns different keys to summaries that get split up', () => {
|
|
|
|
const events = mkMelsEvents().slice(1, 11);
|
|
|
|
|
|
|
|
const res = mount(<WrappedMessagePanel events={events} />);
|
|
|
|
let els = res.find("EventListSummary");
|
|
|
|
expect(els.length).toEqual(1);
|
|
|
|
expect(els.key()).toEqual("eventlistsummary-" + events[0].getId());
|
|
|
|
expect(els.prop("events").length).toEqual(10);
|
|
|
|
|
|
|
|
res.setProps({
|
|
|
|
events: [
|
|
|
|
...events.slice(0, 5),
|
|
|
|
TestUtilsMatrix.mkMessage({
|
|
|
|
event: true,
|
|
|
|
room: "!room:id",
|
|
|
|
user: "@user:id",
|
|
|
|
msg: "Hello!",
|
|
|
|
}),
|
|
|
|
...events.slice(5, 10),
|
|
|
|
],
|
|
|
|
});
|
|
|
|
|
|
|
|
els = res.find("EventListSummary");
|
|
|
|
expect(els.length).toEqual(2);
|
|
|
|
expect(els.first().key()).not.toEqual(els.last().key());
|
|
|
|
expect(els.first().prop("events").length).toEqual(5);
|
|
|
|
expect(els.last().prop("events").length).toEqual(5);
|
|
|
|
});
|
2022-04-14 23:23:22 +00:00
|
|
|
|
|
|
|
// We test this because setting lookups can be *slow*, and we don't want
|
|
|
|
// them to happen in this code path
|
|
|
|
it("doesn't lookup showHiddenEventsInTimeline while rendering", () => {
|
|
|
|
// We're only interested in the setting lookups that happen on every render,
|
|
|
|
// rather than those happening on first mount, so let's get those out of the way
|
|
|
|
const res = mount(<WrappedMessagePanel events={[]} />);
|
|
|
|
|
|
|
|
// Set up our spy and re-render with new events
|
|
|
|
const settingsSpy = jest.spyOn(SettingsStore, "getValue").mockClear();
|
|
|
|
res.setProps({ events: mkMixedHiddenAndShownEvents() });
|
|
|
|
|
|
|
|
expect(settingsSpy).not.toHaveBeenCalledWith("showHiddenEventsInTimeline");
|
|
|
|
settingsSpy.mockRestore();
|
|
|
|
});
|
2022-04-21 16:57:08 +00:00
|
|
|
|
|
|
|
it("should group hidden event reactions into an event list summary", () => {
|
|
|
|
const events = [
|
|
|
|
TestUtilsMatrix.mkEvent({
|
|
|
|
event: true,
|
|
|
|
type: "m.reaction",
|
|
|
|
room: "!room:id",
|
|
|
|
user: "@user:id",
|
|
|
|
content: {},
|
|
|
|
ts: 1,
|
|
|
|
}),
|
|
|
|
TestUtilsMatrix.mkEvent({
|
|
|
|
event: true,
|
|
|
|
type: "m.reaction",
|
|
|
|
room: "!room:id",
|
|
|
|
user: "@user:id",
|
|
|
|
content: {},
|
|
|
|
ts: 2,
|
|
|
|
}),
|
|
|
|
TestUtilsMatrix.mkEvent({
|
|
|
|
event: true,
|
|
|
|
type: "m.reaction",
|
|
|
|
room: "!room:id",
|
|
|
|
user: "@user:id",
|
|
|
|
content: {},
|
|
|
|
ts: 3,
|
|
|
|
}),
|
|
|
|
];
|
|
|
|
const res = mount(<WrappedMessagePanel showHiddenEvents={true} events={events} />);
|
|
|
|
|
|
|
|
const els = res.find("EventListSummary");
|
|
|
|
expect(els.length).toEqual(1);
|
|
|
|
expect(els.prop("events").length).toEqual(3);
|
|
|
|
});
|
2016-03-30 23:48:46 +00:00
|
|
|
});
|
2022-03-26 22:06:25 +00:00
|
|
|
|
|
|
|
describe("shouldFormContinuation", () => {
|
2022-05-13 11:59:50 +00:00
|
|
|
it("does not form continuations from thread roots which have summaries", () => {
|
2022-04-26 08:30:36 +00:00
|
|
|
const message1 = TestUtilsMatrix.mkMessage({
|
|
|
|
event: true,
|
|
|
|
room: "!room:id",
|
|
|
|
user: "@user:id",
|
|
|
|
msg: "Here is a message in the main timeline",
|
|
|
|
});
|
|
|
|
|
|
|
|
const message2 = TestUtilsMatrix.mkMessage({
|
|
|
|
event: true,
|
|
|
|
room: "!room:id",
|
|
|
|
user: "@user:id",
|
|
|
|
msg: "And here's another message in the main timeline",
|
|
|
|
});
|
|
|
|
|
2022-03-26 22:06:25 +00:00
|
|
|
const threadRoot = TestUtilsMatrix.mkMessage({
|
|
|
|
event: true,
|
|
|
|
room: "!room:id",
|
|
|
|
user: "@user:id",
|
|
|
|
msg: "Here is a thread",
|
|
|
|
});
|
|
|
|
jest.spyOn(threadRoot, "isThreadRoot", "get").mockReturnValue(true);
|
|
|
|
|
2022-04-26 08:30:36 +00:00
|
|
|
const message3 = TestUtilsMatrix.mkMessage({
|
2022-03-26 22:06:25 +00:00
|
|
|
event: true,
|
|
|
|
room: "!room:id",
|
|
|
|
user: "@user:id",
|
2022-04-26 08:30:36 +00:00
|
|
|
msg: "And here's another message in the main timeline after the thread root",
|
2022-03-26 22:06:25 +00:00
|
|
|
});
|
|
|
|
|
2022-04-26 08:30:36 +00:00
|
|
|
expect(shouldFormContinuation(message1, message2, false, true)).toEqual(true);
|
2022-05-13 11:59:50 +00:00
|
|
|
expect(shouldFormContinuation(message2, threadRoot, false, true)).toEqual(true);
|
|
|
|
expect(shouldFormContinuation(threadRoot, message3, false, true)).toEqual(true);
|
|
|
|
|
|
|
|
const thread = {
|
|
|
|
length: 1,
|
|
|
|
replyToEvent: {},
|
|
|
|
};
|
|
|
|
jest.spyOn(threadRoot, "getThread").mockReturnValue(thread);
|
2022-04-26 08:30:36 +00:00
|
|
|
expect(shouldFormContinuation(message2, threadRoot, false, true)).toEqual(false);
|
|
|
|
expect(shouldFormContinuation(threadRoot, message3, false, true)).toEqual(false);
|
2022-03-26 22:06:25 +00:00
|
|
|
});
|
|
|
|
});
|