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

Commit 6cff984

Browse files
artcodespacerichvdh
authored andcommitted
Room and user mentions for plain text editor (#10665)
* update useSuggestion * update useSuggestion-tests * add processMention tests * add test * add getMentionOrCommand tests * change mock href for codeQL reasons * fix TS issue in test * add a big old cypress test * fix lint error * update comments * reorganise functions in order of importance * rename functions and variables * add endOffset to return object * fix failing tests * update function names and comments * update comment, remove delay * update comments and early return * nest mappedSuggestion inside Suggestion state and update test * rename suggestion => suggestionData * update comment * add argument to findSuggestionInText * make findSuggestionInText return mappedSuggestion * fix TS error * update comments and index check from === -1 to < 0 * tidy logic in increment functions * rename variable * Big refactor to address multiple comments, improve behaviour and add tests * improve comments * tidy up comment * extend comment * combine similar returns * update comment * remove single use variable * fix comments
1 parent 6711e07 commit 6cff984

File tree

3 files changed

+505
-125
lines changed

3 files changed

+505
-125
lines changed

cypress/e2e/composer/composer.spec.ts

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@ limitations under the License.
1515
*/
1616

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

1920
import { HomeserverInstance } from "../../plugins/utils/homeserver";
2021
import { SettingLevel } from "../../../src/settings/SettingLevel";
22+
import { MatrixClient } from "../../global";
2123

2224
describe("Composer", () => {
2325
let homeserver: HomeserverInstance;
@@ -181,6 +183,81 @@ describe("Composer", () => {
181183
});
182184
});
183185

186+
describe("Mentions", () => {
187+
// TODO add tests for rich text mode
188+
189+
describe("Plain text mode", () => {
190+
it("autocomplete behaviour tests", () => {
191+
// Setup a private room so we have another user to mention
192+
const otherUserName = "Bob";
193+
let bobClient: MatrixClient;
194+
cy.getBot(homeserver, {
195+
displayName: otherUserName,
196+
}).then((bob) => {
197+
bobClient = bob;
198+
});
199+
// create DM with bob
200+
cy.getClient().then(async (cli) => {
201+
const bobRoom = await cli.createRoom({ is_direct: true });
202+
await cli.invite(bobRoom.room_id, bobClient.getUserId());
203+
await cli.setAccountData("m.direct" as EventType, {
204+
[bobClient.getUserId()]: [bobRoom.room_id],
205+
});
206+
});
207+
208+
cy.viewRoomByName("Bob");
209+
210+
// Select plain text mode after composer is ready
211+
cy.get("div[contenteditable=true]").should("exist");
212+
cy.findByRole("button", { name: "Hide formatting" }).click();
213+
214+
// Typing a single @ does not display the autocomplete menu and contents
215+
cy.findByRole("textbox").type("@");
216+
cy.findByTestId("autocomplete-wrapper").should("be.empty");
217+
218+
// Entering the first letter of the other user's name opens the autocomplete...
219+
cy.findByRole("textbox").type(otherUserName.slice(0, 1));
220+
cy.findByTestId("autocomplete-wrapper")
221+
.should("not.be.empty")
222+
.within(() => {
223+
// ...with the other user name visible, and clicking that username...
224+
cy.findByText(otherUserName).should("exist").click();
225+
});
226+
// ...inserts the username into the composer
227+
cy.findByRole("textbox").within(() => {
228+
// TODO update this test when the mentions are inserted as pills, instead
229+
// of as text
230+
cy.findByText(otherUserName, { exact: false }).should("exist");
231+
});
232+
233+
// Send the message to clear the composer
234+
cy.findByRole("button", { name: "Send message" }).click();
235+
236+
// Typing an @, then other user's name, then trailing space closes the autocomplete
237+
cy.findByRole("textbox").type(`@${otherUserName} `);
238+
cy.findByTestId("autocomplete-wrapper").should("be.empty");
239+
240+
// Send the message to clear the composer
241+
cy.findByRole("button", { name: "Send message" }).click();
242+
243+
// Moving the cursor back to an "incomplete" mention opens the autocomplete
244+
cy.findByRole("textbox").type(`initial text @${otherUserName.slice(0, 1)} abc`);
245+
cy.findByTestId("autocomplete-wrapper").should("be.empty");
246+
// Move the cursor left by 4 to put it to: `@B| abc`, check autocomplete displays
247+
cy.findByRole("textbox").type(`${"{leftArrow}".repeat(4)}`);
248+
cy.findByTestId("autocomplete-wrapper").should("not.be.empty");
249+
250+
// Selecting the autocomplete option using Enter inserts it into the composer
251+
cy.findByRole("textbox").type(`{Enter}`);
252+
cy.findByRole("textbox").within(() => {
253+
// TODO update this test when the mentions are inserted as pills, instead
254+
// of as text
255+
cy.findByText(otherUserName, { exact: false }).should("exist");
256+
});
257+
});
258+
});
259+
});
260+
184261
it("sends a message when you click send or press Enter", () => {
185262
// Type a message
186263
cy.get("div[contenteditable=true]").type("my message 0");

0 commit comments

Comments
 (0)