Test for different types of events
This commit is contained in:
parent
900accd823
commit
ecf0aba97c
3 changed files with 104 additions and 18 deletions
|
@ -67,25 +67,103 @@ describe('export', function() {
|
|||
},
|
||||
];
|
||||
|
||||
const events: MatrixEvent[] = mkEvents();
|
||||
const room = createRoom();
|
||||
function createRoom() {
|
||||
const room = new Room(generateRoomId(), null, client.getUserId());
|
||||
return room;
|
||||
}
|
||||
const mockRoom = createRoom();
|
||||
|
||||
function mkEvents() {
|
||||
const events = [];
|
||||
const matrixEvents = [];
|
||||
const ts0 = Date.now();
|
||||
for (let i = 0; i < 10; i++) {
|
||||
events.push(TestUtilsMatrix.mkMessage({
|
||||
let i: number;
|
||||
// plain text
|
||||
for (i = 0; i < 10; i++) {
|
||||
matrixEvents.push(TestUtilsMatrix.mkMessage({
|
||||
event: true, room: "!room:id", user: "@user:id",
|
||||
ts: ts0 + i * 1000,
|
||||
}));
|
||||
}
|
||||
return events;
|
||||
// reply events
|
||||
for (i = 0; i < 10; i++) {
|
||||
matrixEvents.push(TestUtilsMatrix.mkEvent({
|
||||
"content": {
|
||||
"body": "> <@me:here> Hi\n\nTest",
|
||||
"format": "org.matrix.custom.html",
|
||||
"m.relates_to": {
|
||||
"m.in_reply_to": {
|
||||
"event_id": "$" + Math.random() + "-" + Math.random(),
|
||||
},
|
||||
},
|
||||
"msgtype": "m.text",
|
||||
},
|
||||
"user": "@me:here",
|
||||
"type": "m.room.message",
|
||||
"room": mockRoom.roomId,
|
||||
"event": true,
|
||||
}));
|
||||
}
|
||||
// membership events
|
||||
for (i = 0; i < 10; i++) {
|
||||
matrixEvents.push(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: ts0 + i*1000,
|
||||
mship: 'join',
|
||||
prevMship: 'join',
|
||||
name: 'A user',
|
||||
}));
|
||||
}
|
||||
// emote
|
||||
matrixEvents.push(TestUtilsMatrix.mkEvent({
|
||||
"content": {
|
||||
"body": "waves",
|
||||
"msgtype": "m.emote",
|
||||
},
|
||||
"user": "@me:here",
|
||||
"type": "m.room.message",
|
||||
"room": mockRoom.roomId,
|
||||
"event": true,
|
||||
}));
|
||||
// redacted events
|
||||
for (i = 0; i < 10; i++) {
|
||||
matrixEvents.push(new MatrixEvent({
|
||||
type: "m.room.message",
|
||||
sender: MY_USER_ID,
|
||||
content: {},
|
||||
unsigned: {
|
||||
"age": 72,
|
||||
"transaction_id": "m1212121212.23",
|
||||
"redacted_because": {
|
||||
"content": {},
|
||||
"origin_server_ts": ts0 + i*1000,
|
||||
"redacts": "$9999999999999999999999999999999999999999998",
|
||||
"sender": "@me:here",
|
||||
"type": "m.room.redaction",
|
||||
"unsigned": {
|
||||
"age": 94,
|
||||
"transaction_id": "m1111111111.1",
|
||||
},
|
||||
"event_id": "$9999999999999999999999999999999999999999998",
|
||||
"room_id": mockRoom.roomId,
|
||||
},
|
||||
},
|
||||
event_id: "$9999999999999999999999999999999999999999999",
|
||||
room_id: mockRoom.roomId,
|
||||
}));
|
||||
}
|
||||
return matrixEvents;
|
||||
}
|
||||
|
||||
const events: MatrixEvent[] = mkEvents();
|
||||
|
||||
it('checks if the export format is valid', function() {
|
||||
expect(textForFormat('HTML')).toBeTruthy();
|
||||
expect(textForFormat('JSON')).toBeTruthy();
|
||||
|
@ -101,7 +179,7 @@ describe('export', function() {
|
|||
it('checks if the export options are valid', function() {
|
||||
for (const exportOption of invalidExportOptions) {
|
||||
try {
|
||||
new PlainTextExporter(room, ExportTypes.BEGINNING, exportOption, null);
|
||||
new PlainTextExporter(mockRoom, ExportTypes.BEGINNING, exportOption, null);
|
||||
throw new Error("Expected to throw an error");
|
||||
} catch (e) {
|
||||
expect(e.message).toBe("Invalid export options");
|
||||
|
@ -110,7 +188,7 @@ describe('export', function() {
|
|||
});
|
||||
|
||||
it('tests the file extension splitter', function() {
|
||||
const exporter = new PlainTextExporter(room, ExportTypes.BEGINNING, mockExportOptions, null);
|
||||
const exporter = new PlainTextExporter(mockRoom, ExportTypes.BEGINNING, mockExportOptions, null);
|
||||
const fileNameWithExtensions = {
|
||||
"": ["", ""],
|
||||
"name": ["name", ""],
|
||||
|
@ -147,15 +225,14 @@ describe('export', function() {
|
|||
"expectedText": "<@me:here \"This\"> Reply",
|
||||
},
|
||||
];
|
||||
const exporter = new PlainTextExporter(room, ExportTypes.BEGINNING, mockExportOptions, null);
|
||||
const exporter = new PlainTextExporter(mockRoom, ExportTypes.BEGINNING, mockExportOptions, null);
|
||||
for (const content of eventContents) {
|
||||
expect(exporter.textForReplyEvent(content)).toBe(content.expectedText);
|
||||
}
|
||||
});
|
||||
|
||||
it('checks if the render to string works for eventTile', function() {
|
||||
// Todo: Generate different event types
|
||||
const exporter = new HTMLExporter(room, ExportTypes.BEGINNING, mockExportOptions, null);
|
||||
it("checks if the render to string doesn't throw any error for different kinds of strings", function() {
|
||||
const exporter = new HTMLExporter(mockRoom, ExportTypes.BEGINNING, mockExportOptions, null);
|
||||
for (const event of events) {
|
||||
expect(renderToString(exporter.getEventTile(event, false))).toBeTruthy();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue