diff --git a/src/utils/exportUtils/HtmlExport.tsx b/src/utils/exportUtils/HtmlExport.tsx
index 124914a210..daa411826e 100644
--- a/src/utils/exportUtils/HtmlExport.tsx
+++ b/src/utils/exportUtils/HtmlExport.tsx
@@ -303,13 +303,17 @@ export default class HTMLExporter extends Exporter {
return eventTileMarkup;
}
- protected createModifiedEvent(text: string, mxEv: MatrixEvent) {
+ protected createModifiedEvent(text: string, mxEv: MatrixEvent, italic=true) {
const modifiedContent = {
msgtype: "m.text",
- body: `*${text}*`,
+ body: `${text}`,
format: "org.matrix.custom.html",
- formatted_body: `${text}`,
+ formatted_body: `${text}`,
};
+ if (italic) {
+ modifiedContent.formatted_body = '' + modifiedContent.formatted_body + '';
+ modifiedContent.body = '*' + modifiedContent.body + '*';
+ }
const modifiedEvent = new MatrixEvent();
modifiedEvent.event = mxEv.event;
modifiedEvent.sender = mxEv.sender;
@@ -356,7 +360,10 @@ export default class HTMLExporter extends Exporter {
} catch (e) {
// TODO: Handle callEvent errors
console.error(e);
- eventTile = await this.getEventTileMarkup(this.createModifiedEvent(textForEvent(mxEv), mxEv), joined);
+ eventTile = await this.getEventTileMarkup(
+ this.createModifiedEvent(textForEvent(mxEv), mxEv, false),
+ joined,
+ );
}
return eventTile;
diff --git a/test/test-utils.js b/test/test-utils.js
index d25fbe5207..46b8e9bbc9 100644
--- a/test/test-utils.js
+++ b/test/test-utils.js
@@ -113,6 +113,7 @@ export function createTestClient() {
* @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.
+ * @param {unsigned=} opts.unsigned
* @return {Object} a JSON object representing this event.
*/
export function mkEvent(opts) {
@@ -167,12 +168,13 @@ export function mkPresence(opts) {
* @param {string} opts.room The room ID for the event.
* @param {string} opts.mship The content.membership for the event.
* @param {string} opts.prevMship The prev_content.membership for the event.
+ * @param {number=} opts.ts Optional. Timestamp for the event
* @param {string} opts.user The user ID for the event.
* @param {RoomMember} opts.target The target of the event.
- * @param {string} opts.skey The other user ID for the event if applicable
+ * @param {string=} opts.skey The other user ID for the event if applicable
* e.g. for invites/bans.
* @param {string} opts.name The content.displayname for the event.
- * @param {string} opts.url The content.avatar_url for the event.
+ * @param {string=} opts.url The content.avatar_url for the event.
* @param {boolean} opts.event True to make a MatrixEvent.
* @return {Object|MatrixEvent} The event
*/
diff --git a/test/utils/export-test.tsx b/test/utils/export-test.tsx
index 1b8fc9c31b..e3811ea957 100644
--- a/test/utils/export-test.tsx
+++ b/test/utils/export-test.tsx
@@ -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();
}