Improve rendering of empty topics in the timeline (#29152)
* Improve display of empty topic events in the timeline. * Use topic parser for topic events. * Revert changes i18n for the moment * Use the correct import pattern * Add tests for topic rendering
This commit is contained in:
@@ -12,6 +12,7 @@ import {
|
||||
JoinRule,
|
||||
MatrixClient,
|
||||
MatrixEvent,
|
||||
MRoomTopicEventContent,
|
||||
Room,
|
||||
RoomMember,
|
||||
} from "matrix-js-sdk/src/matrix";
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user