Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit d1f23fb

Browse files
committed
Partially added the tests [WIP]
1 parent 81f2e67 commit d1f23fb

File tree

2 files changed

+108
-4
lines changed

2 files changed

+108
-4
lines changed

test/components/structures/MessagePanel-test.js

Lines changed: 75 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ describe('MessagePanel', function() {
7777
DMRoomMap.makeShared();
7878
});
7979

80-
afterEach(function() {
80+
afterEach(function () {
8181
clock.uninstall();
8282
});
8383

@@ -88,7 +88,21 @@ describe('MessagePanel', function() {
8888
events.push(test_utils.mkMessage(
8989
{
9090
event: true, room: "!room:id", user: "@user:id",
91-
ts: ts0 + i*1000,
91+
ts: ts0 + i * 1000,
92+
}));
93+
}
94+
return events;
95+
}
96+
97+
//Just to avoid breaking Dateseparator tests that might run at 00hrs
98+
function mkOneDayEvents() {
99+
const events = [];
100+
const ts0 = Date.parse('09 May 2004 00:12:00 GMT');
101+
for (let i = 0; i < 10; i++) {
102+
events.push(test_utils.mkMessage(
103+
{
104+
event: true, room: "!room:id", user: "@user:id",
105+
ts: ts0 + i * 1000,
92106
}));
93107
}
94108
return events;
@@ -104,7 +118,7 @@ describe('MessagePanel', function() {
104118
let i = 0;
105119
events.push(test_utils.mkMessage({
106120
event: true, room: "!room:id", user: "@user:id",
107-
ts: ts0 + ++i*1000,
121+
ts: ts0 + ++i * 1000,
108122
}));
109123

110124
for (i = 0; i < 10; i++) {
@@ -151,7 +165,7 @@ describe('MessagePanel', function() {
151165
},
152166
getMxcAvatarUrl: () => 'mxc://avatar.url/image.png',
153167
},
154-
ts: ts0 + i*1000,
168+
ts: ts0 + i * 1000,
155169
mship: 'join',
156170
prevMship: 'join',
157171
name: 'A user',
@@ -251,6 +265,33 @@ describe('MessagePanel', function() {
251265
];
252266
}
253267

268+
//Create a few redacted events
269+
//isRedacted just checks the redacted_because
270+
function mkRedactionEvents() {
271+
const events = [];
272+
const ts0 = Date.now();
273+
let i=0
274+
275+
let redaction = test_utils.mkEvent({
276+
type: "m.room.redaction",
277+
event: true, room: "!room:id", user: "@user:id", ts: ts0 + ++i * 1000 ,
278+
content: {},
279+
});
280+
let event =test_utils.mkRedactedEvent({
281+
type: "m.room.message",
282+
event: true, room: "!room:id", user: "@user:id",
283+
ts: ts0 + i * 1000 ,
284+
// redacted_because: redaction This is not working at the moment
285+
})
286+
redaction.redacts = event.event_id;
287+
288+
events.push(event);
289+
events.push(redaction);
290+
291+
return events;
292+
293+
}
294+
254295
function isReadMarkerVisible(rmContainer) {
255296
return rmContainer && rmContainer.children.length > 0;
256297
}
@@ -437,4 +478,34 @@ describe('MessagePanel', function() {
437478
// read marker should be hidden given props and at the last event
438479
expect(isReadMarkerVisible(rm)).toBeFalsy();
439480
});
481+
482+
it('should render Date separators for the events', function () {
483+
const events = mkOneDayEvents()
484+
const res = mount(
485+
<WrappedMessagePanel
486+
className="cls"
487+
events={events}
488+
/>,
489+
);
490+
const Dates = res.find(sdk.getComponent('messages.DateSeparator'));
491+
492+
expect(Dates.length).toEqual(1);
493+
494+
495+
})
496+
497+
it('should render only one Date separator for redacted events', function () {
498+
const events = mkRedactionEvents()
499+
const res = mount(
500+
<WrappedMessagePanel
501+
className="cls"
502+
events={events}
503+
/>,
504+
);
505+
const Dates = res.find(sdk.getComponent('messages.DateSeparator'));
506+
507+
expect(Dates.length).toEqual(1);
508+
509+
510+
})
440511
});

test/test-utils.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,39 @@ export function mkMessage(opts) {
202202
return mkEvent(opts);
203203
}
204204

205+
206+
/**
207+
* Create an Redacted Event.
208+
* @param {Object} opts Values for the event.
209+
* @param {string} opts.type The event.type
210+
* @param {string} opts.room The event.room_id
211+
* @param {string} opts.user The event.user_id
212+
* @param {string} opts.skey Optional. The state key (auto inserts empty string)
213+
* @param {Number} opts.ts Optional. Timestamp for the event
214+
* @param {Object} opts.content The event.content
215+
* @param {boolean} opts.event True to make a MatrixEvent.
216+
* @return {Object} a JSON object representing this event.
217+
*/
218+
export function mkRedactedEvent(opts) {
219+
if (!opts.type ) {
220+
throw new Error("Missing .type =>" + JSON.stringify(opts));
221+
}
222+
const event = {
223+
type: opts.type,
224+
room_id: opts.room,
225+
sender: opts.user,
226+
content: {},
227+
prev_content: opts.prev_content,
228+
event_id: "$" + Math.random() + "-" + Math.random(),
229+
origin_server_ts: opts.ts,
230+
//isRedacted() only checks if redacted_because is true or not
231+
// unsigned :{redacted_because:opts.redacted_because} This is not working atm
232+
};
233+
//Might want to add the other parameters for generalized tests
234+
return opts.event ? new MatrixEvent(event) : event;
235+
}
236+
237+
205238
export function mkStubRoom(roomId = null) {
206239
const stubTimeline = { getEvents: () => [] };
207240
return {

0 commit comments

Comments
 (0)