2022-10-19 05:07:21 +02:00
|
|
|
/*
|
|
|
|
Copyright 2022 The Matrix.org Foundation C.I.C.
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/// <reference types="cypress" />
|
2023-08-03 14:56:30 +02:00
|
|
|
import { EventType } from "matrix-js-sdk/src/matrix";
|
2022-10-19 05:07:21 +02:00
|
|
|
|
2023-01-11 00:29:56 +01:00
|
|
|
import { HomeserverInstance } from "../../plugins/utils/homeserver";
|
2022-10-19 05:07:21 +02:00
|
|
|
import { SettingLevel } from "../../../src/settings/SettingLevel";
|
2023-05-11 16:28:42 +02:00
|
|
|
import { MatrixClient } from "../../global";
|
2022-10-19 05:07:21 +02:00
|
|
|
|
|
|
|
describe("Composer", () => {
|
2023-01-11 00:29:56 +01:00
|
|
|
let homeserver: HomeserverInstance;
|
2022-10-19 05:07:21 +02:00
|
|
|
|
|
|
|
beforeEach(() => {
|
2023-01-11 00:29:56 +01:00
|
|
|
cy.startHomeserver("default").then((data) => {
|
|
|
|
homeserver = data;
|
2022-10-19 05:07:21 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
2023-01-11 00:29:56 +01:00
|
|
|
cy.stopHomeserver(homeserver);
|
2022-10-19 05:07:21 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
describe("CIDER", () => {
|
|
|
|
beforeEach(() => {
|
2023-07-25 23:55:13 +02:00
|
|
|
cy.initTestUser(homeserver, "Janet");
|
|
|
|
cy.createRoom({ name: "Composing Room" }).then((roomId) => cy.viewRoomById(roomId));
|
2022-10-19 05:07:21 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
it("sends a message when you click send or press Enter", () => {
|
|
|
|
// Type a message
|
2023-04-11 08:07:25 +02:00
|
|
|
cy.findByRole("textbox", { name: "Send a message…" }).type("my message 0");
|
2022-10-19 05:07:21 +02:00
|
|
|
// It has not been sent yet
|
2022-12-12 12:24:14 +01:00
|
|
|
cy.contains(".mx_EventTile_body", "my message 0").should("not.exist");
|
2022-10-19 05:07:21 +02:00
|
|
|
|
|
|
|
// Click send
|
2023-04-11 08:07:25 +02:00
|
|
|
cy.findByRole("button", { name: "Send message" }).click();
|
2022-10-19 05:07:21 +02:00
|
|
|
// It has been sent
|
2023-04-11 08:07:25 +02:00
|
|
|
cy.get(".mx_EventTile_last .mx_EventTile_body").within(() => {
|
|
|
|
cy.findByText("my message 0").should("exist");
|
|
|
|
});
|
2022-10-19 05:07:21 +02:00
|
|
|
|
|
|
|
// Type another and press Enter afterwards
|
2023-04-11 08:07:25 +02:00
|
|
|
cy.findByRole("textbox", { name: "Send a message…" }).type("my message 1{enter}");
|
2022-10-19 05:07:21 +02:00
|
|
|
// It was sent
|
2023-04-11 08:07:25 +02:00
|
|
|
cy.get(".mx_EventTile_last .mx_EventTile_body").within(() => {
|
|
|
|
cy.findByText("my message 1").should("exist");
|
|
|
|
});
|
2022-10-19 05:07:21 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
it("can write formatted text", () => {
|
2023-04-11 08:07:25 +02:00
|
|
|
cy.findByRole("textbox", { name: "Send a message…" }).type("my bold{ctrl+b} message");
|
|
|
|
cy.findByRole("button", { name: "Send message" }).click();
|
2022-10-19 05:07:21 +02:00
|
|
|
// Note: both "bold" and "message" are bold, which is probably surprising
|
2023-04-11 08:07:25 +02:00
|
|
|
cy.get(".mx_EventTile_body strong").within(() => {
|
|
|
|
cy.findByText("bold message").should("exist");
|
|
|
|
});
|
2022-10-19 05:07:21 +02:00
|
|
|
});
|
|
|
|
|
2022-10-26 14:58:40 +02:00
|
|
|
it("should allow user to input emoji via graphical picker", () => {
|
|
|
|
cy.getComposer(false).within(() => {
|
2023-04-11 08:07:25 +02:00
|
|
|
cy.findByRole("button", { name: "Emoji" }).click();
|
2022-10-26 14:58:40 +02:00
|
|
|
});
|
|
|
|
|
2023-04-11 08:07:25 +02:00
|
|
|
cy.findByTestId("mx_EmojiPicker").within(() => {
|
2022-10-26 14:58:40 +02:00
|
|
|
cy.contains(".mx_EmojiPicker_item", "😇").click();
|
|
|
|
});
|
|
|
|
|
|
|
|
cy.get(".mx_ContextualMenu_background").click(); // Close emoji picker
|
2023-04-11 08:07:25 +02:00
|
|
|
cy.findByRole("textbox", { name: "Send a message…" }).type("{enter}"); // Send message
|
2022-10-26 14:58:40 +02:00
|
|
|
|
2023-04-11 08:07:25 +02:00
|
|
|
cy.get(".mx_EventTile_body").within(() => {
|
|
|
|
cy.findByText("😇");
|
|
|
|
});
|
2022-10-26 14:58:40 +02:00
|
|
|
});
|
|
|
|
|
2022-10-19 05:07:21 +02:00
|
|
|
describe("when Ctrl+Enter is required to send", () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
cy.setSettingValue("MessageComposerInput.ctrlEnterToSend", null, SettingLevel.ACCOUNT, true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("only sends when you press Ctrl+Enter", () => {
|
|
|
|
// Type a message and press Enter
|
2023-04-11 08:07:25 +02:00
|
|
|
cy.findByRole("textbox", { name: "Send a message…" }).type("my message 3{enter}");
|
2022-10-19 05:07:21 +02:00
|
|
|
// It has not been sent yet
|
2022-12-12 12:24:14 +01:00
|
|
|
cy.contains(".mx_EventTile_body", "my message 3").should("not.exist");
|
2022-10-19 05:07:21 +02:00
|
|
|
|
|
|
|
// Press Ctrl+Enter
|
2023-04-11 08:07:25 +02:00
|
|
|
cy.findByRole("textbox", { name: "Send a message…" }).type("{ctrl+enter}");
|
2022-10-19 05:07:21 +02:00
|
|
|
// It was sent
|
2023-04-11 08:07:25 +02:00
|
|
|
cy.get(".mx_EventTile_last .mx_EventTile_body").within(() => {
|
|
|
|
cy.findByText("my message 3").should("exist");
|
|
|
|
});
|
2022-10-19 05:07:21 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2023-01-26 11:08:23 +01:00
|
|
|
describe("Rich text editor", () => {
|
2022-10-19 05:07:21 +02:00
|
|
|
beforeEach(() => {
|
|
|
|
cy.enableLabsFeature("feature_wysiwyg_composer");
|
2023-07-25 23:55:13 +02:00
|
|
|
cy.initTestUser(homeserver, "Janet");
|
|
|
|
cy.createRoom({ name: "Composing Room" }).then((roomId) => cy.viewRoomById(roomId));
|
2022-10-19 05:07:21 +02:00
|
|
|
});
|
|
|
|
|
2023-04-27 09:37:47 +02:00
|
|
|
describe("Commands", () => {
|
|
|
|
// TODO add tests for rich text mode
|
|
|
|
|
|
|
|
describe("Plain text mode", () => {
|
|
|
|
it("autocomplete behaviour tests", () => {
|
|
|
|
// 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 / displays the autocomplete menu and contents
|
|
|
|
cy.findByRole("textbox").type("/");
|
|
|
|
|
|
|
|
// Check that the autocomplete options are visible and there are more than 0 items
|
|
|
|
cy.findByTestId("autocomplete-wrapper").should("not.be.empty");
|
|
|
|
|
|
|
|
// Entering `//` or `/ ` hides the autocomplete contents
|
|
|
|
// Add an extra slash for `//`
|
|
|
|
cy.findByRole("textbox").type("/");
|
|
|
|
cy.findByTestId("autocomplete-wrapper").should("be.empty");
|
|
|
|
// Remove the extra slash to go back to `/`
|
|
|
|
cy.findByRole("textbox").type("{Backspace}");
|
|
|
|
cy.findByTestId("autocomplete-wrapper").should("not.be.empty");
|
|
|
|
// Add a trailing space for `/ `
|
|
|
|
cy.findByRole("textbox").type(" ");
|
|
|
|
cy.findByTestId("autocomplete-wrapper").should("be.empty");
|
|
|
|
|
|
|
|
// Typing a command that takes no arguments (/devtools) and selecting by click works
|
|
|
|
cy.findByRole("textbox").type("{Backspace}dev");
|
|
|
|
cy.findByTestId("autocomplete-wrapper").within(() => {
|
|
|
|
cy.findByText("/devtools").click();
|
|
|
|
});
|
|
|
|
// Check it has closed the autocomplete and put the text into the composer
|
|
|
|
cy.findByTestId("autocomplete-wrapper").should("not.be.visible");
|
|
|
|
cy.findByRole("textbox").within(() => {
|
|
|
|
cy.findByText("/devtools").should("exist");
|
|
|
|
});
|
|
|
|
// Send the message and check the devtools dialog appeared, then close it
|
|
|
|
cy.findByRole("button", { name: "Send message" }).click();
|
|
|
|
cy.findByRole("dialog").within(() => {
|
|
|
|
cy.findByText("Developer Tools").should("exist");
|
|
|
|
});
|
|
|
|
cy.findByRole("button", { name: "Close dialog" }).click();
|
|
|
|
|
|
|
|
// Typing a command that takes arguments (/spoiler) and selecting with enter works
|
|
|
|
cy.findByRole("textbox").type("/spoil");
|
|
|
|
cy.findByTestId("autocomplete-wrapper").within(() => {
|
|
|
|
cy.findByText("/spoiler").should("exist");
|
|
|
|
});
|
|
|
|
cy.findByRole("textbox").type("{Enter}");
|
|
|
|
// Check it has closed the autocomplete and put the text into the composer
|
|
|
|
cy.findByTestId("autocomplete-wrapper").should("not.be.visible");
|
|
|
|
cy.findByRole("textbox").within(() => {
|
|
|
|
cy.findByText("/spoiler").should("exist");
|
|
|
|
});
|
|
|
|
// Enter some more text, then send the message
|
|
|
|
cy.findByRole("textbox").type("this is the spoiler text ");
|
|
|
|
cy.findByRole("button", { name: "Send message" }).click();
|
|
|
|
// Check that a spoiler item has appeared in the timeline and contains the spoiler command text
|
|
|
|
cy.get("span.mx_EventTile_spoiler").should("exist");
|
|
|
|
cy.findByText("this is the spoiler text").should("exist");
|
|
|
|
});
|
|
|
|
});
|
2023-05-11 16:28:42 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
describe("Mentions", () => {
|
|
|
|
// TODO add tests for rich text mode
|
|
|
|
|
|
|
|
describe("Plain text mode", () => {
|
|
|
|
it("autocomplete behaviour tests", () => {
|
2023-07-25 23:55:13 +02:00
|
|
|
// Set up a private room so we have another user to mention
|
2023-05-11 16:28:42 +02:00
|
|
|
const otherUserName = "Bob";
|
|
|
|
let bobClient: MatrixClient;
|
|
|
|
cy.getBot(homeserver, {
|
|
|
|
displayName: otherUserName,
|
|
|
|
}).then((bob) => {
|
|
|
|
bobClient = bob;
|
|
|
|
});
|
|
|
|
// create DM with bob
|
2023-07-25 23:55:13 +02:00
|
|
|
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],
|
|
|
|
});
|
|
|
|
return bobRoom.room_id;
|
|
|
|
})
|
|
|
|
.then((bobRoomId) => cy.viewRoomById(bobRoomId));
|
2023-05-11 16:28:42 +02:00
|
|
|
|
|
|
|
// 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(() => {
|
2023-05-16 13:54:16 +02:00
|
|
|
cy.findByText(otherUserName, { exact: false })
|
|
|
|
.should("exist")
|
|
|
|
.should("have.attr", "contenteditable", "false")
|
|
|
|
.should("have.attr", "data-mention-type", "user");
|
2023-05-11 16:28:42 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
// 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(() => {
|
2023-05-16 13:54:16 +02:00
|
|
|
cy.findByText(otherUserName, { exact: false })
|
|
|
|
.should("exist")
|
|
|
|
.should("have.attr", "contenteditable", "false")
|
|
|
|
.should("have.attr", "data-mention-type", "user");
|
2023-05-11 16:28:42 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2023-04-27 09:37:47 +02:00
|
|
|
});
|
|
|
|
|
2022-10-19 05:07:21 +02:00
|
|
|
it("sends a message when you click send or press Enter", () => {
|
|
|
|
// Type a message
|
2022-12-12 12:24:14 +01:00
|
|
|
cy.get("div[contenteditable=true]").type("my message 0");
|
2022-10-19 05:07:21 +02:00
|
|
|
// It has not been sent yet
|
2022-12-12 12:24:14 +01:00
|
|
|
cy.contains(".mx_EventTile_body", "my message 0").should("not.exist");
|
2022-10-19 05:07:21 +02:00
|
|
|
|
|
|
|
// Click send
|
2023-04-11 08:07:25 +02:00
|
|
|
cy.findByRole("button", { name: "Send message" }).click();
|
2022-10-19 05:07:21 +02:00
|
|
|
// It has been sent
|
2023-04-11 08:07:25 +02:00
|
|
|
cy.get(".mx_EventTile_last .mx_EventTile_body").within(() => {
|
|
|
|
cy.findByText("my message 0").should("exist");
|
|
|
|
});
|
2022-10-19 05:07:21 +02:00
|
|
|
|
|
|
|
// Type another
|
2022-12-12 12:24:14 +01:00
|
|
|
cy.get("div[contenteditable=true]").type("my message 1");
|
2023-01-18 10:09:25 +01:00
|
|
|
// Send message
|
|
|
|
cy.get("div[contenteditable=true]").type("{enter}");
|
2022-10-19 05:07:21 +02:00
|
|
|
// It was sent
|
2023-04-11 08:07:25 +02:00
|
|
|
cy.get(".mx_EventTile_last .mx_EventTile_body").within(() => {
|
|
|
|
cy.findByText("my message 1").should("exist");
|
|
|
|
});
|
2022-10-19 05:07:21 +02:00
|
|
|
});
|
|
|
|
|
2023-01-18 14:20:49 +01:00
|
|
|
it("sends only one message when you press Enter multiple times", () => {
|
|
|
|
// Type a message
|
|
|
|
cy.get("div[contenteditable=true]").type("my message 0");
|
|
|
|
// It has not been sent yet
|
|
|
|
cy.contains(".mx_EventTile_body", "my message 0").should("not.exist");
|
|
|
|
|
|
|
|
// Click send
|
|
|
|
cy.get("div[contenteditable=true]").type("{enter}");
|
|
|
|
cy.get("div[contenteditable=true]").type("{enter}");
|
|
|
|
cy.get("div[contenteditable=true]").type("{enter}");
|
|
|
|
// It has been sent
|
2023-04-11 08:07:25 +02:00
|
|
|
cy.get(".mx_EventTile_last .mx_EventTile_body").within(() => {
|
|
|
|
cy.findByText("my message 0").should("exist");
|
|
|
|
});
|
|
|
|
cy.get(".mx_EventTile_last .mx_EventTile_body").should("have.length", 1);
|
2023-01-18 14:20:49 +01:00
|
|
|
});
|
|
|
|
|
2022-10-19 05:07:21 +02:00
|
|
|
it("can write formatted text", () => {
|
2022-12-12 12:24:14 +01:00
|
|
|
cy.get("div[contenteditable=true]").type("my {ctrl+b}bold{ctrl+b} message");
|
2023-04-11 08:07:25 +02:00
|
|
|
cy.findByRole("button", { name: "Send message" }).click();
|
|
|
|
cy.get(".mx_EventTile_body strong").within(() => {
|
|
|
|
cy.findByText("bold").should("exist");
|
|
|
|
});
|
2022-10-19 05:07:21 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
describe("when Ctrl+Enter is required to send", () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
cy.setSettingValue("MessageComposerInput.ctrlEnterToSend", null, SettingLevel.ACCOUNT, true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("only sends when you press Ctrl+Enter", () => {
|
|
|
|
// Type a message and press Enter
|
2022-12-12 12:24:14 +01:00
|
|
|
cy.get("div[contenteditable=true]").type("my message 3");
|
2023-01-18 10:09:25 +01:00
|
|
|
cy.get("div[contenteditable=true]").type("{enter}");
|
2022-10-19 05:07:21 +02:00
|
|
|
// It has not been sent yet
|
2022-12-12 12:24:14 +01:00
|
|
|
cy.contains(".mx_EventTile_body", "my message 3").should("not.exist");
|
2022-10-19 05:07:21 +02:00
|
|
|
|
|
|
|
// Press Ctrl+Enter
|
2022-12-12 12:24:14 +01:00
|
|
|
cy.get("div[contenteditable=true]").type("{ctrl+enter}");
|
2022-10-19 05:07:21 +02:00
|
|
|
// It was sent
|
2023-04-11 08:07:25 +02:00
|
|
|
cy.get(".mx_EventTile_last .mx_EventTile_body").within(() => {
|
|
|
|
cy.findByText("my message 3").should("exist");
|
|
|
|
});
|
2022-10-19 05:07:21 +02:00
|
|
|
});
|
|
|
|
});
|
2023-01-26 11:08:23 +01:00
|
|
|
|
|
|
|
describe("links", () => {
|
|
|
|
it("create link with a forward selection", () => {
|
|
|
|
// Type a message
|
|
|
|
cy.get("div[contenteditable=true]").type("my message 0{selectAll}");
|
|
|
|
|
|
|
|
// Open link modal
|
2023-04-11 08:07:25 +02:00
|
|
|
cy.findByRole("button", { name: "Link" }).click();
|
2023-01-26 11:08:23 +01:00
|
|
|
// Fill the link field
|
2023-04-11 08:07:25 +02:00
|
|
|
cy.findByRole("textbox", { name: "Link" }).type("https://matrix.org/");
|
2023-01-26 11:08:23 +01:00
|
|
|
// Click on save
|
2023-04-11 08:07:25 +02:00
|
|
|
cy.findByRole("button", { name: "Save" }).click();
|
2023-01-26 11:08:23 +01:00
|
|
|
// Send the message
|
2023-04-11 08:07:25 +02:00
|
|
|
cy.findByRole("button", { name: "Send message" }).click();
|
2023-01-26 11:08:23 +01:00
|
|
|
|
|
|
|
// It was sent
|
2023-04-11 08:07:25 +02:00
|
|
|
cy.get(".mx_EventTile_body a").within(() => {
|
|
|
|
cy.findByText("my message 0").should("exist");
|
|
|
|
});
|
2023-01-26 11:08:23 +01:00
|
|
|
cy.get(".mx_EventTile_body a").should("have.attr", "href").and("include", "https://matrix.org/");
|
|
|
|
});
|
|
|
|
});
|
2022-10-19 05:07:21 +02:00
|
|
|
});
|
|
|
|
});
|