Partially added the tests [WIP]

This commit is contained in:
Ayush PS 2021-05-07 11:45:52 +05:30
parent 81f2e67443
commit d1f23fb994
2 changed files with 108 additions and 4 deletions

View file

@ -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(
<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);
})
});