From 310bf2282cc757bedace903fd4705f5f12fce48d Mon Sep 17 00:00:00 2001 From: Cadence Ember Date: Wed, 14 Feb 2024 11:39:50 +1300 Subject: [PATCH] Code coverage for silly reply previews --- m2d/converters/event-to-message.test.js | 93 +++++++++++++++++++++++++ 1 file changed, 93 insertions(+) diff --git a/m2d/converters/event-to-message.test.js b/m2d/converters/event-to-message.test.js index 7cc0fdd8..2b354e06 100644 --- a/m2d/converters/event-to-message.test.js +++ b/m2d/converters/event-to-message.test.js @@ -1433,6 +1433,99 @@ test("event2message: reply preview uses emoji title text when replying to an unk ) }) +test("event2message: reply preview ignores garbage image", async t => { + t.deepEqual( + await eventToMessage({ + type: "m.room.message", + sender: "@cadence:cadence.moe", + content: { + msgtype: "m.text", + body: "> <@cadence:cadence.moe> I am having AAAA a nice day\n\nreply", + format: "org.matrix.custom.html", + formatted_body: "
In reply to @cadence:cadence.moe
I am having a nice day
reply", + "m.relates_to": { + "m.in_reply_to": { + event_id: "$zmO-dtPO6FubBkDxJZ5YmutPIsG1RgV5JJku-9LeGWs" + } + } + }, + event_id: "$bCMLaLiMfoRajaGTgzaxAci-g8hJfkspVJIKwYktnvc", + room_id: "!TqlyQmifxGUggEmdBN:cadence.moe" + }, data.guild.general, { + api: { + getEvent: mockGetEvent(t, "!TqlyQmifxGUggEmdBN:cadence.moe", "$zmO-dtPO6FubBkDxJZ5YmutPIsG1RgV5JJku-9LeGWs", { + type: "m.room.message", + sender: "@cadence:cadence.moe", + content: { + msgtype: "m.text", + body: "I am having AAAA a nice day", + format: "org.matrix.custom.html", + formatted_body: "I am having a nice day" + } + }) + } + }), + { + ensureJoined: [], + messagesToDelete: [], + messagesToEdit: [], + messagesToSend: [{ + username: "cadence [they]", + content: "> <:L1:1144820033948762203><:L2:1144820084079087647>Ⓜ️**cadence [they]**:" + + "\n> I am having a nice day" + + "\nreply", + avatar_url: undefined + }] + } + ) +}) + +test("event2message: reply to empty message doesn't show an extra line or anything", async t => { + t.deepEqual( + await eventToMessage({ + type: "m.room.message", + sender: "@cadence:cadence.moe", + content: { + msgtype: "m.text", + body: "> <@cadence:cadence.moe> \n\nreply", + format: "org.matrix.custom.html", + formatted_body: "
In reply to @cadence:cadence.moe
reply", + "m.relates_to": { + "m.in_reply_to": { + event_id: "$zmO-dtPO6FubBkDxJZ5YmutPIsG1RgV5JJku-9LeGWs" + } + } + }, + event_id: "$bCMLaLiMfoRajaGTgzaxAci-g8hJfkspVJIKwYktnvc", + room_id: "!TqlyQmifxGUggEmdBN:cadence.moe" + }, data.guild.general, { + api: { + getEvent: mockGetEvent(t, "!TqlyQmifxGUggEmdBN:cadence.moe", "$zmO-dtPO6FubBkDxJZ5YmutPIsG1RgV5JJku-9LeGWs", { + type: "m.room.message", + sender: "@cadence:cadence.moe", + content: { + msgtype: "m.text", + body: "", + format: "org.matrix.custom.html", + formatted_body: "" + } + }) + } + }), + { + ensureJoined: [], + messagesToDelete: [], + messagesToEdit: [], + messagesToSend: [{ + username: "cadence [they]", + content: "> <:L1:1144820033948762203><:L2:1144820084079087647>Ⓜ️**cadence [they]**" + + "\nreply", + avatar_url: undefined + }] + } + ) +}) + test("event2message: editing a rich reply to a sim user", async t => { const eventsFetched = [] t.deepEqual(