diff --git a/test/components/structures/MessagePanel-test.js b/test/components/structures/MessagePanel-test.js
index 7347ff2658..55879a2f5c 100644
--- a/test/components/structures/MessagePanel-test.js
+++ b/test/components/structures/MessagePanel-test.js
@@ -77,7 +77,7 @@ describe('MessagePanel', function() {
DMRoomMap.makeShared();
});
- afterEach(function() {
+ afterEach(function () {
clock.uninstall();
});
@@ -88,7 +88,21 @@ describe('MessagePanel', function() {
events.push(test_utils.mkMessage(
{
event: true, room: "!room:id", user: "@user:id",
- ts: ts0 + i*1000,
+ ts: ts0 + i * 1000,
+ }));
+ }
+ return events;
+ }
+
+ //Just to avoid breaking Dateseparator tests that might run at 00hrs
+ function mkOneDayEvents() {
+ const events = [];
+ const ts0 = Date.parse('09 May 2004 00:12:00 GMT');
+ for (let i = 0; i < 10; i++) {
+ events.push(test_utils.mkMessage(
+ {
+ event: true, room: "!room:id", user: "@user:id",
+ ts: ts0 + i * 1000,
}));
}
return events;
@@ -104,7 +118,7 @@ describe('MessagePanel', function() {
let i = 0;
events.push(test_utils.mkMessage({
event: true, room: "!room:id", user: "@user:id",
- ts: ts0 + ++i*1000,
+ ts: ts0 + ++i * 1000,
}));
for (i = 0; i < 10; i++) {
@@ -151,7 +165,7 @@ describe('MessagePanel', function() {
},
getMxcAvatarUrl: () => 'mxc://avatar.url/image.png',
},
- ts: ts0 + i*1000,
+ ts: ts0 + i * 1000,
mship: 'join',
prevMship: 'join',
name: 'A user',
@@ -251,6 +265,33 @@ describe('MessagePanel', function() {
];
}
+ //Create a few redacted events
+ //isRedacted just checks the redacted_because
+ function mkRedactionEvents() {
+ const events = [];
+ const ts0 = Date.now();
+ let i=0
+
+ let redaction = test_utils.mkEvent({
+ type: "m.room.redaction",
+ event: true, room: "!room:id", user: "@user:id", ts: ts0 + ++i * 1000 ,
+ content: {},
+ });
+ let event =test_utils.mkRedactedEvent({
+ type: "m.room.message",
+ event: true, room: "!room:id", user: "@user:id",
+ ts: ts0 + i * 1000 ,
+ // redacted_because: redaction This is not working at the moment
+ })
+ redaction.redacts = event.event_id;
+
+ events.push(event);
+ events.push(redaction);
+
+ return events;
+
+ }
+
function isReadMarkerVisible(rmContainer) {
return rmContainer && rmContainer.children.length > 0;
}
@@ -437,4 +478,34 @@ describe('MessagePanel', function() {
// read marker should be hidden given props and at the last event
expect(isReadMarkerVisible(rm)).toBeFalsy();
});
+
+ it('should render Date separators for the events', function () {
+ const events = mkOneDayEvents()
+ const res = mount(
+ ,
+ );
+ const Dates = res.find(sdk.getComponent('messages.DateSeparator'));
+
+ expect(Dates.length).toEqual(1);
+
+
+ })
+
+ it('should render only one Date separator for redacted events', function () {
+ const events = mkRedactionEvents()
+ const res = mount(
+ ,
+ );
+ const Dates = res.find(sdk.getComponent('messages.DateSeparator'));
+
+ expect(Dates.length).toEqual(1);
+
+
+ })
});
diff --git a/test/test-utils.js b/test/test-utils.js
index d259fcb95f..4d31241624 100644
--- a/test/test-utils.js
+++ b/test/test-utils.js
@@ -202,6 +202,39 @@ export function mkMessage(opts) {
return mkEvent(opts);
}
+
+/**
+ * Create an Redacted Event.
+ * @param {Object} opts Values for the event.
+ * @param {string} opts.type The event.type
+ * @param {string} opts.room The event.room_id
+ * @param {string} opts.user The event.user_id
+ * @param {string} opts.skey Optional. The state key (auto inserts empty string)
+ * @param {Number} opts.ts Optional. Timestamp for the event
+ * @param {Object} opts.content The event.content
+ * @param {boolean} opts.event True to make a MatrixEvent.
+ * @return {Object} a JSON object representing this event.
+ */
+ export function mkRedactedEvent(opts) {
+ if (!opts.type ) {
+ throw new Error("Missing .type =>" + JSON.stringify(opts));
+ }
+ const event = {
+ type: opts.type,
+ room_id: opts.room,
+ sender: opts.user,
+ content: {},
+ prev_content: opts.prev_content,
+ event_id: "$" + Math.random() + "-" + Math.random(),
+ origin_server_ts: opts.ts,
+ //isRedacted() only checks if redacted_because is true or not
+ // unsigned :{redacted_because:opts.redacted_because} This is not working atm
+ };
+ //Might want to add the other parameters for generalized tests
+ return opts.event ? new MatrixEvent(event) : event;
+}
+
+
export function mkStubRoom(roomId = null) {
const stubTimeline = { getEvents: () => [] };
return {