|
| 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 { MessageEvent } from "matrix-events-sdk"; |
| 20 | + |
| 21 | +import type { ISendEventResponse } from "matrix-js-sdk/src/@types/requests"; |
| 22 | +import type { EventType } from "matrix-js-sdk/src/@types/event"; |
| 23 | +import { SynapseInstance } from "../../plugins/synapsedocker"; |
| 24 | +import Chainable = Cypress.Chainable; |
| 25 | + |
| 26 | +const sendEvent = (roomId: string): Chainable<ISendEventResponse> => { |
| 27 | + return cy.sendEvent( |
| 28 | + roomId, |
| 29 | + null, |
| 30 | + "m.room.message" as EventType, |
| 31 | + MessageEvent.from("Message").serialize().content, |
| 32 | + ); |
| 33 | +}; |
| 34 | + |
| 35 | +describe("Editing", () => { |
| 36 | + let synapse: SynapseInstance; |
| 37 | + |
| 38 | + beforeEach(() => { |
| 39 | + cy.startSynapse("default").then(data => { |
| 40 | + synapse = data; |
| 41 | + cy.initTestUser(synapse, "Edith").then(() => { |
| 42 | + cy.injectAxe(); |
| 43 | + return cy.createRoom({ name: "Test room" }).as("roomId"); |
| 44 | + }); |
| 45 | + }); |
| 46 | + }); |
| 47 | + |
| 48 | + afterEach(() => { |
| 49 | + cy.stopSynapse(synapse); |
| 50 | + }); |
| 51 | + |
| 52 | + it("should close the composer when clicking save after making a change and undoing it", () => { |
| 53 | + cy.get<string>("@roomId").then(roomId => { |
| 54 | + sendEvent(roomId); |
| 55 | + cy.visit("/#/room/" + roomId); |
| 56 | + }); |
| 57 | + |
| 58 | + // Edit message |
| 59 | + cy.contains(".mx_RoomView_body .mx_EventTile .mx_EventTile_line", "Message").within(() => { |
| 60 | + cy.get('[aria-label="Edit"]').click({ force: true }); // Cypress has no ability to hover |
| 61 | + cy.checkA11y(); |
| 62 | + cy.get(".mx_BasicMessageComposer_input").type("Foo{backspace}{backspace}{backspace}{enter}"); |
| 63 | + cy.checkA11y(); |
| 64 | + }); |
| 65 | + cy.get(".mx_RoomView_body .mx_EventTile").contains(".mx_EventTile[data-scroll-tokens]", "Message"); |
| 66 | + |
| 67 | + // Assert that the edit composer has gone away |
| 68 | + cy.get(".mx_EditMessageComposer").should("not.exist"); |
| 69 | + }); |
| 70 | +}); |
0 commit comments