Partially added the tests [WIP]
This commit is contained in:
parent
81f2e67443
commit
d1f23fb994
2 changed files with 108 additions and 4 deletions
|
@ -77,7 +77,7 @@ describe('MessagePanel', function() {
|
||||||
DMRoomMap.makeShared();
|
DMRoomMap.makeShared();
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(function() {
|
afterEach(function () {
|
||||||
clock.uninstall();
|
clock.uninstall();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -88,7 +88,21 @@ describe('MessagePanel', function() {
|
||||||
events.push(test_utils.mkMessage(
|
events.push(test_utils.mkMessage(
|
||||||
{
|
{
|
||||||
event: true, room: "!room:id", user: "@user:id",
|
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;
|
return events;
|
||||||
|
@ -104,7 +118,7 @@ describe('MessagePanel', function() {
|
||||||
let i = 0;
|
let i = 0;
|
||||||
events.push(test_utils.mkMessage({
|
events.push(test_utils.mkMessage({
|
||||||
event: true, room: "!room:id", user: "@user:id",
|
event: true, room: "!room:id", user: "@user:id",
|
||||||
ts: ts0 + ++i*1000,
|
ts: ts0 + ++i * 1000,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
for (i = 0; i < 10; i++) {
|
for (i = 0; i < 10; i++) {
|
||||||
|
@ -151,7 +165,7 @@ describe('MessagePanel', function() {
|
||||||
},
|
},
|
||||||
getMxcAvatarUrl: () => 'mxc://avatar.url/image.png',
|
getMxcAvatarUrl: () => 'mxc://avatar.url/image.png',
|
||||||
},
|
},
|
||||||
ts: ts0 + i*1000,
|
ts: ts0 + i * 1000,
|
||||||
mship: 'join',
|
mship: 'join',
|
||||||
prevMship: 'join',
|
prevMship: 'join',
|
||||||
name: 'A user',
|
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) {
|
function isReadMarkerVisible(rmContainer) {
|
||||||
return rmContainer && rmContainer.children.length > 0;
|
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
|
// read marker should be hidden given props and at the last event
|
||||||
expect(isReadMarkerVisible(rm)).toBeFalsy();
|
expect(isReadMarkerVisible(rm)).toBeFalsy();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should render Date separators for the events', function () {
|
||||||
|
const events = mkOneDayEvents()
|
||||||
|
const res = mount(
|
||||||
|
<WrappedMessagePanel
|
||||||
|
className="cls"
|
||||||
|
events={events}
|
||||||
|
/>,
|
||||||
|
);
|
||||||
|
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(
|
||||||
|
<WrappedMessagePanel
|
||||||
|
className="cls"
|
||||||
|
events={events}
|
||||||
|
/>,
|
||||||
|
);
|
||||||
|
const Dates = res.find(sdk.getComponent('messages.DateSeparator'));
|
||||||
|
|
||||||
|
expect(Dates.length).toEqual(1);
|
||||||
|
|
||||||
|
|
||||||
|
})
|
||||||
});
|
});
|
||||||
|
|
|
@ -202,6 +202,39 @@ export function mkMessage(opts) {
|
||||||
return mkEvent(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) {
|
export function mkStubRoom(roomId = null) {
|
||||||
const stubTimeline = { getEvents: () => [] };
|
const stubTimeline = { getEvents: () => [] };
|
||||||
return {
|
return {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue