Handle more completion types in rte autocomplete (#10560)

* handle at-room

* remove console log

* update and add tests

* tidy up

* refactor to switch statement

* fix TS error

* expand tests

* consolidate similar if/else if blocks
This commit is contained in:
alunturner 2023-04-14 10:09:38 +01:00 committed by GitHub
parent 1ae0662872
commit e4ebcf5731
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 113 additions and 23 deletions

View file

@ -100,8 +100,8 @@ describe("getRoomFromCompletion", () => {
});
describe("getMentionDisplayText", () => {
it("returns an empty string if we are not handling a user or a room type", () => {
const nonHandledCompletionTypes = ["at-room", "community", "command"] as const;
it("returns an empty string if we are not handling a user, room or at-room type", () => {
const nonHandledCompletionTypes = ["community", "command"] as const;
const nonHandledCompletions = nonHandledCompletionTypes.map((type) => createMockCompletion({ type }));
nonHandledCompletions.forEach((completion) => {
@ -131,12 +131,18 @@ describe("getMentionDisplayText", () => {
// as this uses the mockClient, the name will be the mock room name returned from there
expect(getMentionDisplayText(userCompletion, mockClient)).toBe(testCompletion);
});
it("returns the completion if we are handling an at-room completion", () => {
const testCompletion = "display this";
const atRoomCompletion = createMockCompletion({ type: "at-room", completion: testCompletion });
expect(getMentionDisplayText(atRoomCompletion, mockClient)).toBe(testCompletion);
});
});
describe("getMentionAttributes", () => {
// TODO handle all completion types
it("returns an empty object for completion types other than room or user", () => {
const nonHandledCompletionTypes = ["at-room", "community", "command"] as const;
it("returns an empty object for completion types other than room, user or at-room", () => {
const nonHandledCompletionTypes = ["community", "command"] as const;
const nonHandledCompletions = nonHandledCompletionTypes.map((type) => createMockCompletion({ type }));
nonHandledCompletions.forEach((completion) => {
@ -218,4 +224,14 @@ describe("getMentionAttributes", () => {
});
});
});
describe("at-room mentions", () => {
it("returns expected attributes", () => {
const atRoomCompletion = createMockCompletion({ type: "at-room" });
const result = getMentionAttributes(atRoomCompletion, mockClient, mockRoom);
expect(result).toEqual({ "data-mention-type": "at-room" });
});
});
});