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

Commit 6796375

Browse files
authored
Fix dismissing edit composer when change was undone (#9109)
* Fix dismissing edit composer when change was undone * Add tests
1 parent 27ba1e5 commit 6796375

File tree

2 files changed

+73
-7
lines changed

2 files changed

+73
-7
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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+
});

src/components/views/rooms/EditMessageComposer.tsx

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,9 @@ class EditMessageComposer extends React.Component<IEditMessageComposerProps, ISt
213213
};
214214

215215
private endEdit(): void {
216+
localStorage.removeItem(this.editorRoomKey);
217+
localStorage.removeItem(this.editorStateKey);
218+
216219
// close the event editing and focus composer
217220
dis.dispatch({
218221
action: Action.EditEvent,
@@ -241,7 +244,6 @@ class EditMessageComposer extends React.Component<IEditMessageComposerProps, ISt
241244
}
242245

243246
private cancelEdit = (): void => {
244-
this.clearStoredEditorState();
245247
this.endEdit();
246248
};
247249

@@ -262,11 +264,6 @@ class EditMessageComposer extends React.Component<IEditMessageComposerProps, ISt
262264
}
263265
}
264266

265-
private clearStoredEditorState(): void {
266-
localStorage.removeItem(this.editorRoomKey);
267-
localStorage.removeItem(this.editorStateKey);
268-
}
269-
270267
private clearPreviousEdit(): void {
271268
if (localStorage.getItem(this.editorRoomKey)) {
272269
localStorage.removeItem(`mx_edit_state_${localStorage.getItem(this.editorRoomKey)}`);
@@ -354,7 +351,6 @@ class EditMessageComposer extends React.Component<IEditMessageComposerProps, ISt
354351
const threadId = event.threadRootId || null;
355352

356353
this.props.mxClient.sendMessage(roomId, threadId, editContent);
357-
this.clearStoredEditorState();
358354
dis.dispatch({ action: "message_sent" });
359355
}
360356
}

0 commit comments

Comments
 (0)