You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-07-30 04:23:07 +03:00
Add support for HTML renderings of room topics (#2272)
* Add support for HTML renderings of room topics Based on extensible events as defined in [MSC1767] Relates to: vector-im/element-web#5180 Signed-off-by: Johannes Marbach <johannesm@element.io> [MSC1767]: https://github.com/matrix-org/matrix-spec-proposals/pull/1767 * Use correct MSC * Add overloads for setRoomTopic * Fix indentation * Add more tests to pass the quality gate Co-authored-by: Johannes Marbach <jm@Johanness-Mini.fritz.box> Co-authored-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
@ -33,7 +33,7 @@ import { ReceiptType } from "../../src/@types/read_receipts";
|
||||
import * as testUtils from "../test-utils/test-utils";
|
||||
import { makeBeaconInfoContent } from "../../src/content-helpers";
|
||||
import { M_BEACON_INFO } from "../../src/@types/beacon";
|
||||
import { Room } from "../../src";
|
||||
import { ContentHelpers, Room } from "../../src";
|
||||
import { makeBeaconEvent } from "../test-utils/beacon";
|
||||
|
||||
jest.useFakeTimers();
|
||||
@ -1104,6 +1104,41 @@ describe("MatrixClient", function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe("setRoomTopic", () => {
|
||||
const roomId = "!foofoofoofoofoofoo:matrix.org";
|
||||
const createSendStateEventMock = (topic: string, htmlTopic?: string) => {
|
||||
return jest.fn()
|
||||
.mockImplementation((roomId: string, eventType: string, content: any, stateKey: string) => {
|
||||
expect(roomId).toEqual(roomId);
|
||||
expect(eventType).toEqual(EventType.RoomTopic);
|
||||
expect(content).toMatchObject(ContentHelpers.makeTopicContent(topic, htmlTopic));
|
||||
expect(stateKey).toBeUndefined();
|
||||
return Promise.resolve();
|
||||
});
|
||||
};
|
||||
|
||||
it("is called with plain text topic and sends state event", async () => {
|
||||
const sendStateEvent = createSendStateEventMock("pizza");
|
||||
client.sendStateEvent = sendStateEvent;
|
||||
await client.setRoomTopic(roomId, "pizza");
|
||||
expect(sendStateEvent).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it("is called with plain text topic and callback and sends state event", async () => {
|
||||
const sendStateEvent = createSendStateEventMock("pizza");
|
||||
client.sendStateEvent = sendStateEvent;
|
||||
await client.setRoomTopic(roomId, "pizza", () => {});
|
||||
expect(sendStateEvent).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it("is called with plain text and HTML topic and sends state event", async () => {
|
||||
const sendStateEvent = createSendStateEventMock("pizza", "<b>pizza</b>");
|
||||
client.sendStateEvent = sendStateEvent;
|
||||
await client.setRoomTopic(roomId, "pizza", "<b>pizza</b>");
|
||||
expect(sendStateEvent).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe("setPassword", () => {
|
||||
const auth = { session: 'abcdef', type: 'foo' };
|
||||
const newPassword = 'newpassword';
|
||||
|
Reference in New Issue
Block a user