Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Room and user mentions for plain text editor #10665

Merged
Merged
Show file tree
Hide file tree
Changes from 43 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
2cfa778
update useSuggestion
Apr 27, 2023
b5c1f59
update useSuggestion-tests
Apr 27, 2023
7e846c0
add processMention tests
Apr 27, 2023
e4c65d2
add test
Apr 27, 2023
897f9f0
add getMentionOrCommand tests
Apr 27, 2023
e184a41
change mock href for codeQL reasons
Apr 27, 2023
8c1b3e6
fix TS issue in test
Apr 27, 2023
c0d0517
add a big old cypress test
Apr 28, 2023
47eeafe
Merge remote-tracking branch 'origin/develop' into alunturner/room-an…
Apr 28, 2023
e605977
fix lint error
Apr 28, 2023
f3a7c6f
update comments
Apr 28, 2023
2b281d8
reorganise functions in order of importance
Apr 28, 2023
c2ab234
rename functions and variables
Apr 28, 2023
790cbf3
Merge remote-tracking branch 'origin/develop' into alunturner/room-an…
May 5, 2023
4b8af0b
add endOffset to return object
May 5, 2023
89c2c78
fix failing tests
May 5, 2023
e0fe483
Merge remote-tracking branch 'origin/develop' into alunturner/room-an…
May 5, 2023
d1e5f52
update function names and comments
May 5, 2023
9f94d84
Merge branch 'develop' into alunturner/room-and-user-mentions-for-pla…
artcodespace May 5, 2023
3a7370d
Merge branch 'develop' into alunturner/room-and-user-mentions-for-pla…
artcodespace May 5, 2023
c531218
Merge remote-tracking branch 'origin/develop' into alunturner/room-an…
May 9, 2023
0e4aa06
Merge branch 'develop' into alunturner/room-and-user-mentions-for-pla…
artcodespace May 9, 2023
97915ad
Merge remote-tracking branch 'origin/develop' into alunturner/room-an…
May 10, 2023
79b5560
update comment, remove delay
May 10, 2023
276140b
update comments and early return
May 10, 2023
b1b4e01
nest mappedSuggestion inside Suggestion state and update test
May 10, 2023
92e7836
rename suggestion => suggestionData
May 10, 2023
41d095a
update comment
May 10, 2023
24b6b7d
add argument to findSuggestionInText
May 10, 2023
1c785ea
make findSuggestionInText return mappedSuggestion
May 10, 2023
2368e25
fix TS error
May 10, 2023
12a7583
update comments and index check from === -1 to < 0
May 10, 2023
3d74710
tidy logic in increment functions
May 10, 2023
c0d240a
rename variable
May 10, 2023
d292763
Big refactor to address multiple comments, improve behaviour and add …
May 10, 2023
be88d71
improve comments
May 10, 2023
246ed7c
tidy up comment
May 10, 2023
283884f
extend comment
May 10, 2023
86017bd
combine similar returns
May 10, 2023
be67256
update comment
May 10, 2023
14f8ecd
remove single use variable
May 10, 2023
ce19e46
Merge remote-tracking branch 'origin/develop' into alunturner/room-an…
May 10, 2023
06e9af6
Merge branch 'develop' into alunturner/room-and-user-mentions-for-pla…
artcodespace May 11, 2023
2658d62
Merge branch 'develop' into alunturner/room-and-user-mentions-for-pla…
May 11, 2023
45224cf
fix comments
May 11, 2023
3c15013
Merge branch 'develop' into alunturner/room-and-user-mentions-for-pla…
May 11, 2023
ed5caaa
Merge branch 'develop' into alunturner/room-and-user-mentions-for-pla…
artcodespace May 11, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions cypress/e2e/composer/composer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ limitations under the License.
*/

/// <reference types="cypress" />
import { EventType } from "matrix-js-sdk/src/@types/event";

import { HomeserverInstance } from "../../plugins/utils/homeserver";
import { SettingLevel } from "../../../src/settings/SettingLevel";
import { MatrixClient } from "../../global";

describe("Composer", () => {
let homeserver: HomeserverInstance;
Expand Down Expand Up @@ -181,6 +183,81 @@ describe("Composer", () => {
});
});

describe("Mentions", () => {
// TODO add tests for rich text mode

describe("Plain text mode", () => {
it("autocomplete behaviour tests", () => {
// Setup a private room so we have another user to mention
const otherUserName = "Bob";
let bobClient: MatrixClient;
cy.getBot(homeserver, {
displayName: otherUserName,
}).then((bob) => {
bobClient = bob;
});
// create DM with bob
cy.getClient().then(async (cli) => {
const bobRoom = await cli.createRoom({ is_direct: true });
await cli.invite(bobRoom.room_id, bobClient.getUserId());
await cli.setAccountData("m.direct" as EventType, {
[bobClient.getUserId()]: [bobRoom.room_id],
});
});

cy.viewRoomByName("Bob");

// Select plain text mode after composer is ready
cy.get("div[contenteditable=true]").should("exist");
cy.findByRole("button", { name: "Hide formatting" }).click();

// Typing a single @ does not display the autocomplete menu and contents
cy.findByRole("textbox").type("@");
cy.findByTestId("autocomplete-wrapper").should("be.empty");

// Entering the first letter of the other user's name opens the autocomplete...
cy.findByRole("textbox").type(otherUserName.slice(0, 1));
cy.findByTestId("autocomplete-wrapper")
.should("not.be.empty")
.within(() => {
// ...with the other user name visible, and clicking that username...
cy.findByText(otherUserName).should("exist").click();
});
// ...inserts the username into the composer
cy.findByRole("textbox").within(() => {
// TODO update this test when the mentions are inserted as pills, instead
// of as text
cy.findByText(otherUserName, { exact: false }).should("exist");
});

// Send the message to clear the composer
cy.findByRole("button", { name: "Send message" }).click();

// Typing an @, then other user's name, then trailing space closes the autocomplete
cy.findByRole("textbox").type(`@${otherUserName} `);
cy.findByTestId("autocomplete-wrapper").should("be.empty");

// Send the message to clear the composer
cy.findByRole("button", { name: "Send message" }).click();

// Moving the cursor back to an "incomplete" mention opens the autocomplete
cy.findByRole("textbox").type(`initial text @${otherUserName.slice(0, 1)} abc`);
cy.findByTestId("autocomplete-wrapper").should("be.empty");
// Move the cursor left by 4 to put it to: `@B| abc`, check autocomplete displays
cy.findByRole("textbox").type(`${"{leftArrow}".repeat(4)}`);
cy.findByTestId("autocomplete-wrapper").should("not.be.empty");

// Selecting the autocomplete option using Enter inserts it into the composer
cy.findByRole("textbox").type(`{Enter}`);
cy.findByRole("textbox").within(() => {
// TODO update this test when the mentions are inserted as pills, instead
// of as text
cy.findByText(otherUserName, { exact: false }).should("exist");
});
});
});
});

it("sends a message when you click send or press Enter", () => {
// Type a message
cy.get("div[contenteditable=true]").type("my message 0");
Expand Down
Loading