|
| 1 | +/* |
| 2 | +Copyright 2022 The Matrix.org Foundation C.I.C. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +/// <reference types="cypress" /> |
| 18 | + |
| 19 | +import { SynapseInstance } from "../../plugins/synapsedocker"; |
| 20 | +import { SettingLevel } from "../../../src/settings/SettingLevel"; |
| 21 | + |
| 22 | +describe("Composer", () => { |
| 23 | + let synapse: SynapseInstance; |
| 24 | + |
| 25 | + beforeEach(() => { |
| 26 | + cy.startSynapse("default").then(data => { |
| 27 | + synapse = data; |
| 28 | + }); |
| 29 | + }); |
| 30 | + |
| 31 | + afterEach(() => { |
| 32 | + cy.stopSynapse(synapse); |
| 33 | + }); |
| 34 | + |
| 35 | + describe("CIDER", () => { |
| 36 | + beforeEach(() => { |
| 37 | + cy.initTestUser(synapse, "Janet").then(() => { |
| 38 | + cy.createRoom({ name: "Composing Room" }); |
| 39 | + }); |
| 40 | + cy.viewRoomByName("Composing Room"); |
| 41 | + }); |
| 42 | + |
| 43 | + it("sends a message when you click send or press Enter", () => { |
| 44 | + // Type a message |
| 45 | + cy.get('div[contenteditable=true]').type('my message 0'); |
| 46 | + // It has not been sent yet |
| 47 | + cy.contains('.mx_EventTile_body', 'my message 0').should('not.exist'); |
| 48 | + |
| 49 | + // Click send |
| 50 | + cy.get('div[aria-label="Send message"]').click(); |
| 51 | + // It has been sent |
| 52 | + cy.contains('.mx_EventTile_body', 'my message 0'); |
| 53 | + |
| 54 | + // Type another and press Enter afterwards |
| 55 | + cy.get('div[contenteditable=true]').type('my message 1{enter}'); |
| 56 | + // It was sent |
| 57 | + cy.contains('.mx_EventTile_body', 'my message 1'); |
| 58 | + }); |
| 59 | + |
| 60 | + it("can write formatted text", () => { |
| 61 | + cy.get('div[contenteditable=true]').type('my bold{ctrl+b} message'); |
| 62 | + cy.get('div[aria-label="Send message"]').click(); |
| 63 | + // Note: both "bold" and "message" are bold, which is probably surprising |
| 64 | + cy.contains('.mx_EventTile_body strong', 'bold message'); |
| 65 | + }); |
| 66 | + |
| 67 | + describe("when Ctrl+Enter is required to send", () => { |
| 68 | + beforeEach(() => { |
| 69 | + cy.setSettingValue("MessageComposerInput.ctrlEnterToSend", null, SettingLevel.ACCOUNT, true); |
| 70 | + }); |
| 71 | + |
| 72 | + it("only sends when you press Ctrl+Enter", () => { |
| 73 | + // Type a message and press Enter |
| 74 | + cy.get('div[contenteditable=true]').type('my message 3{enter}'); |
| 75 | + // It has not been sent yet |
| 76 | + cy.contains('.mx_EventTile_body', 'my message 3').should('not.exist'); |
| 77 | + |
| 78 | + // Press Ctrl+Enter |
| 79 | + cy.get('div[contenteditable=true]').type('{ctrl+enter}'); |
| 80 | + // It was sent |
| 81 | + cy.contains('.mx_EventTile_body', 'my message 3'); |
| 82 | + }); |
| 83 | + }); |
| 84 | + }); |
| 85 | + |
| 86 | + describe("WYSIWYG", () => { |
| 87 | + beforeEach(() => { |
| 88 | + cy.enableLabsFeature("feature_wysiwyg_composer"); |
| 89 | + cy.initTestUser(synapse, "Janet").then(() => { |
| 90 | + cy.createRoom({ name: "Composing Room" }); |
| 91 | + }); |
| 92 | + cy.viewRoomByName("Composing Room"); |
| 93 | + }); |
| 94 | + |
| 95 | + it("sends a message when you click send or press Enter", () => { |
| 96 | + // Type a message |
| 97 | + cy.get('div[contenteditable=true]').type('my message 0'); |
| 98 | + // It has not been sent yet |
| 99 | + cy.contains('.mx_EventTile_body', 'my message 0').should('not.exist'); |
| 100 | + |
| 101 | + // Click send |
| 102 | + cy.get('div[aria-label="Send message"]').click(); |
| 103 | + // It has been sent |
| 104 | + cy.contains('.mx_EventTile_body', 'my message 0'); |
| 105 | + |
| 106 | + // Type another |
| 107 | + cy.get('div[contenteditable=true]').type('my message 1'); |
| 108 | + // Press enter. Would be nice to just use {enter} but we can't because Cypress |
| 109 | + // does not trigger an insertParagraph when you do that. |
| 110 | + cy.get('div[contenteditable=true]').trigger('input', { inputType: "insertParagraph" }); |
| 111 | + // It was sent |
| 112 | + cy.contains('.mx_EventTile_body', 'my message 1'); |
| 113 | + }); |
| 114 | + |
| 115 | + it("can write formatted text", () => { |
| 116 | + cy.get('div[contenteditable=true]').type('my {ctrl+b}bold{ctrl+b} message'); |
| 117 | + cy.get('div[aria-label="Send message"]').click(); |
| 118 | + cy.contains('.mx_EventTile_body strong', 'bold'); |
| 119 | + }); |
| 120 | + |
| 121 | + describe("when Ctrl+Enter is required to send", () => { |
| 122 | + beforeEach(() => { |
| 123 | + cy.setSettingValue("MessageComposerInput.ctrlEnterToSend", null, SettingLevel.ACCOUNT, true); |
| 124 | + }); |
| 125 | + |
| 126 | + it("only sends when you press Ctrl+Enter", () => { |
| 127 | + // Type a message and press Enter |
| 128 | + cy.get('div[contenteditable=true]').type('my message 3'); |
| 129 | + cy.get('div[contenteditable=true]').trigger('input', { inputType: "insertParagraph" }); |
| 130 | + // It has not been sent yet |
| 131 | + cy.contains('.mx_EventTile_body', 'my message 3').should('not.exist'); |
| 132 | + |
| 133 | + // Press Ctrl+Enter |
| 134 | + cy.get('div[contenteditable=true]').type('{ctrl+enter}'); |
| 135 | + // It was sent |
| 136 | + cy.contains('.mx_EventTile_body', 'my message 3'); |
| 137 | + }); |
| 138 | + }); |
| 139 | + }); |
| 140 | +}); |
0 commit comments