2022-10-19 03:07:21 +00: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-01-10 23:29:56 +00:00
|
|
|
import { HomeserverInstance } from "../../plugins/utils/homeserver";
|
2022-10-19 03:07:21 +00:00
|
|
|
import { SettingLevel } from "../../../src/settings/SettingLevel";
|
|
|
|
|
|
|
|
describe("Composer", () => {
|
2023-01-10 23:29:56 +00:00
|
|
|
let homeserver: HomeserverInstance;
|
2022-10-19 03:07:21 +00:00
|
|
|
|
|
|
|
beforeEach(() => {
|
2023-01-10 23:29:56 +00:00
|
|
|
cy.startHomeserver("default").then((data) => {
|
|
|
|
homeserver = data;
|
2022-10-19 03:07:21 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
2023-01-10 23:29:56 +00:00
|
|
|
cy.stopHomeserver(homeserver);
|
2022-10-19 03:07:21 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
describe("CIDER", () => {
|
|
|
|
beforeEach(() => {
|
2023-01-10 23:29:56 +00:00
|
|
|
cy.initTestUser(homeserver, "Janet").then(() => {
|
2022-10-19 03:07:21 +00:00
|
|
|
cy.createRoom({ name: "Composing Room" });
|
|
|
|
});
|
|
|
|
cy.viewRoomByName("Composing Room");
|
|
|
|
});
|
|
|
|
|
|
|
|
it("sends a message when you click send or press Enter", () => {
|
|
|
|
// Type a message
|
2022-12-12 11:24:14 +00:00
|
|
|
cy.get("div[contenteditable=true]").type("my message 0");
|
2022-10-19 03:07:21 +00:00
|
|
|
// It has not been sent yet
|
2022-12-12 11:24:14 +00:00
|
|
|
cy.contains(".mx_EventTile_body", "my message 0").should("not.exist");
|
2022-10-19 03:07:21 +00:00
|
|
|
|
|
|
|
// Click send
|
|
|
|
cy.get('div[aria-label="Send message"]').click();
|
|
|
|
// It has been sent
|
2022-12-12 11:24:14 +00:00
|
|
|
cy.contains(".mx_EventTile_body", "my message 0");
|
2022-10-19 03:07:21 +00:00
|
|
|
|
|
|
|
// Type another and press Enter afterwards
|
2022-12-12 11:24:14 +00:00
|
|
|
cy.get("div[contenteditable=true]").type("my message 1{enter}");
|
2022-10-19 03:07:21 +00:00
|
|
|
// It was sent
|
2022-12-12 11:24:14 +00:00
|
|
|
cy.contains(".mx_EventTile_body", "my message 1");
|
2022-10-19 03:07:21 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("can write formatted text", () => {
|
2022-12-12 11:24:14 +00:00
|
|
|
cy.get("div[contenteditable=true]").type("my bold{ctrl+b} message");
|
2022-10-19 03:07:21 +00:00
|
|
|
cy.get('div[aria-label="Send message"]').click();
|
|
|
|
// Note: both "bold" and "message" are bold, which is probably surprising
|
2022-12-12 11:24:14 +00:00
|
|
|
cy.contains(".mx_EventTile_body strong", "bold message");
|
2022-10-19 03:07:21 +00:00
|
|
|
});
|
|
|
|
|
2022-10-26 12:58:40 +00:00
|
|
|
it("should allow user to input emoji via graphical picker", () => {
|
|
|
|
cy.getComposer(false).within(() => {
|
|
|
|
cy.get('[aria-label="Emoji"]').click();
|
|
|
|
});
|
|
|
|
|
|
|
|
cy.get('[data-testid="mx_EmojiPicker"]').within(() => {
|
|
|
|
cy.contains(".mx_EmojiPicker_item", "😇").click();
|
|
|
|
});
|
|
|
|
|
|
|
|
cy.get(".mx_ContextualMenu_background").click(); // Close emoji picker
|
2022-12-12 11:24:14 +00:00
|
|
|
cy.get("div[contenteditable=true]").type("{enter}"); // Send message
|
2022-10-26 12:58:40 +00:00
|
|
|
|
|
|
|
cy.contains(".mx_EventTile_body", "😇");
|
|
|
|
});
|
|
|
|
|
2022-10-19 03:07:21 +00: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 11:24:14 +00:00
|
|
|
cy.get("div[contenteditable=true]").type("my message 3{enter}");
|
2022-10-19 03:07:21 +00:00
|
|
|
// It has not been sent yet
|
2022-12-12 11:24:14 +00:00
|
|
|
cy.contains(".mx_EventTile_body", "my message 3").should("not.exist");
|
2022-10-19 03:07:21 +00:00
|
|
|
|
|
|
|
// Press Ctrl+Enter
|
2022-12-12 11:24:14 +00:00
|
|
|
cy.get("div[contenteditable=true]").type("{ctrl+enter}");
|
2022-10-19 03:07:21 +00:00
|
|
|
// It was sent
|
2022-12-12 11:24:14 +00:00
|
|
|
cy.contains(".mx_EventTile_body", "my message 3");
|
2022-10-19 03:07:21 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2023-01-26 10:08:23 +00:00
|
|
|
describe("Rich text editor", () => {
|
2022-10-19 03:07:21 +00:00
|
|
|
beforeEach(() => {
|
|
|
|
cy.enableLabsFeature("feature_wysiwyg_composer");
|
2023-01-10 23:29:56 +00:00
|
|
|
cy.initTestUser(homeserver, "Janet").then(() => {
|
2022-10-19 03:07:21 +00:00
|
|
|
cy.createRoom({ name: "Composing Room" });
|
|
|
|
});
|
|
|
|
cy.viewRoomByName("Composing Room");
|
|
|
|
});
|
|
|
|
|
|
|
|
it("sends a message when you click send or press Enter", () => {
|
|
|
|
// Type a message
|
2022-12-12 11:24:14 +00:00
|
|
|
cy.get("div[contenteditable=true]").type("my message 0");
|
2022-10-19 03:07:21 +00:00
|
|
|
// It has not been sent yet
|
2022-12-12 11:24:14 +00:00
|
|
|
cy.contains(".mx_EventTile_body", "my message 0").should("not.exist");
|
2022-10-19 03:07:21 +00:00
|
|
|
|
|
|
|
// Click send
|
|
|
|
cy.get('div[aria-label="Send message"]').click();
|
|
|
|
// It has been sent
|
2022-12-12 11:24:14 +00:00
|
|
|
cy.contains(".mx_EventTile_body", "my message 0");
|
2022-10-19 03:07:21 +00:00
|
|
|
|
|
|
|
// Type another
|
2022-12-12 11:24:14 +00:00
|
|
|
cy.get("div[contenteditable=true]").type("my message 1");
|
2023-01-18 09:09:25 +00:00
|
|
|
// Send message
|
|
|
|
cy.get("div[contenteditable=true]").type("{enter}");
|
2022-10-19 03:07:21 +00:00
|
|
|
// It was sent
|
2022-12-12 11:24:14 +00:00
|
|
|
cy.contains(".mx_EventTile_body", "my message 1");
|
2022-10-19 03:07:21 +00:00
|
|
|
});
|
|
|
|
|
2023-01-18 13:20:49 +00: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
|
|
|
|
cy.contains(".mx_EventTile_body", "my message 0");
|
|
|
|
cy.get(".mx_EventTile_body").should("have.length", 1);
|
|
|
|
});
|
|
|
|
|
2022-10-19 03:07:21 +00:00
|
|
|
it("can write formatted text", () => {
|
2022-12-12 11:24:14 +00:00
|
|
|
cy.get("div[contenteditable=true]").type("my {ctrl+b}bold{ctrl+b} message");
|
2022-10-19 03:07:21 +00:00
|
|
|
cy.get('div[aria-label="Send message"]').click();
|
2022-12-12 11:24:14 +00:00
|
|
|
cy.contains(".mx_EventTile_body strong", "bold");
|
2022-10-19 03:07:21 +00: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 11:24:14 +00:00
|
|
|
cy.get("div[contenteditable=true]").type("my message 3");
|
2023-01-18 09:09:25 +00:00
|
|
|
cy.get("div[contenteditable=true]").type("{enter}");
|
2022-10-19 03:07:21 +00:00
|
|
|
// It has not been sent yet
|
2022-12-12 11:24:14 +00:00
|
|
|
cy.contains(".mx_EventTile_body", "my message 3").should("not.exist");
|
2022-10-19 03:07:21 +00:00
|
|
|
|
|
|
|
// Press Ctrl+Enter
|
2022-12-12 11:24:14 +00:00
|
|
|
cy.get("div[contenteditable=true]").type("{ctrl+enter}");
|
2022-10-19 03:07:21 +00:00
|
|
|
// It was sent
|
2022-12-12 11:24:14 +00:00
|
|
|
cy.contains(".mx_EventTile_body", "my message 3");
|
2022-10-19 03:07:21 +00:00
|
|
|
});
|
|
|
|
});
|
2023-01-26 10:08:23 +00: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
|
|
|
|
cy.get('button[aria-label="Link"]').click();
|
|
|
|
// Fill the link field
|
|
|
|
cy.get('input[label="Link"]').type("https://matrix.org/");
|
|
|
|
// Click on save
|
|
|
|
cy.get('button[type="submit"]').click();
|
|
|
|
// Send the message
|
|
|
|
cy.get('div[aria-label="Send message"]').click();
|
|
|
|
|
|
|
|
// It was sent
|
|
|
|
cy.contains(".mx_EventTile_body a", "my message 0");
|
|
|
|
cy.get(".mx_EventTile_body a").should("have.attr", "href").and("include", "https://matrix.org/");
|
|
|
|
});
|
|
|
|
});
|
2022-10-19 03:07:21 +00:00
|
|
|
});
|
|
|
|
});
|