Skip to content

Commit

Permalink
Add tests for topic rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
Half-Shot committed Jan 31, 2025
1 parent a94125b commit 3014ee4
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions test/unit-tests/TextForEvent-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
JoinRule,
MatrixClient,
MatrixEvent,
MRoomTopicEventContent,
Room,
RoomMember,
} from "matrix-js-sdk/src/matrix";
Expand Down Expand Up @@ -613,4 +614,47 @@ describe("TextForEvent", () => {
},
);
});

describe("textForTopicEvent()", () => {
type TestCase = [string, MRoomTopicEventContent, { result: string }];
const testCases: TestCase[] = [
["the legacy key", { topic: "My topic" }, { result: '@a changed the topic to "My topic".' }],
[
"the legacy key with an empty m.topic key",
{ "topic": "My topic", "m.topic": [] },
{ result: '@a changed the topic to "My topic".' },
],
[
"the m.topic key",
{ "topic": "Ignore this", "m.topic": [{ mimetype: "text/plain", body: "My topic" }] },
{ result: '@a changed the topic to "My topic".' },
],
[
"the m.topic key and the legacy key undefined",
{ "topic": undefined, "m.topic": [{ mimetype: "text/plain", body: "My topic" }] },
{ result: '@a changed the topic to "My topic".' },
],
["the legacy key undefined", { topic: undefined }, { result: "@a removed the topic." }],
["the legacy key empty string", { topic: "" }, { result: "@a removed the topic." }],
[
"both the legacy and new keys removed",
{ "topic": undefined, "m.topic": [] },
{ result: "@a removed the topic." },
],
];

it.each(testCases)("returns correct message for topic event with %s", (_caseName, content, { result }) => {
expect(
textForEvent(
new MatrixEvent({
type: "m.room.topic",
sender: "@a",
content: content,
state_key: "",
}),
mockClient,
),
).toEqual(result);
});
});
});

0 comments on commit 3014ee4

Please sign in to comment.