Skip to content

Commit

Permalink
bugfix: fix in-reply-to previews not disappearing when swapping rooms
Browse files Browse the repository at this point in the history
This was caused by the fix for another issue:
  - element-hq/element-web#21462

Both bugs are now fixed with cypress regression tests.
  • Loading branch information
kegsay committed Sep 14, 2022
1 parent 236ca2e commit e5b081e
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 2 deletions.
61 changes: 61 additions & 0 deletions cypress/e2e/sliding-sync/sliding-sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,4 +331,65 @@ describe("Sliding Sync", () => {
cy.get('.mx_RoomSublist[aria-label="Favourites"]').contains(".mx_RoomTile", "Favourite DM").should("exist");
cy.get('.mx_RoomSublist[aria-label="People"]').contains(".mx_RoomTile", "Favourite DM").should("not.exist");
});

// Regression test for a bug in SS mode, but would be useful to have in non-SS mode too.
// This ensures we are setting RoomViewStore state correctly.
it("should clear the reply to field when swapping rooms", () => {
cy.createRoom({ name: "Other Room" }).as("roomA").then(() => cy.contains(".mx_RoomSublist", "Other Room"));
cy.get<string>("@roomId").then((roomId) => {
return cy.sendEvent(roomId, null, "m.room.message", {
body: "Hello world",
msgtype: "m.text",
});
});
// wait for the message to arrive
checkOrder([
"Test Room", "Other Room",
]);
// select the room
cy.contains(".mx_RoomTile", "Test Room").click();
cy.get(".mx_ReplyPreview").should("not.exist");
// click reply-to on the Hello World message
cy.contains(".mx_EventTile", "Hello world").find('.mx_AccessibleButton[aria-label="Reply"]').click({ force: true });
// check it's visible
cy.get(".mx_ReplyPreview").should("exist");
// now click Other Room
cy.contains(".mx_RoomTile", "Other Room").click();
// ensure the reply-to disappears
cy.get(".mx_ReplyPreview").should("not.exist");
});

// Regression test for https://github.com/vector-im/element-web/issues/21462
it("should not cancel replies when permalinks are clicked ", () => {
cy.get<string>("@roomId").then((roomId) => {
// we require a first message as you cannot click the permalink text with the avatar in the way
return cy.sendEvent(roomId, null, "m.room.message", {
body: "First message",
msgtype: "m.text",
}).then(() => {
return cy.sendEvent(roomId, null, "m.room.message", {
body: "Permalink me",
msgtype: "m.text",
});
}).then(() => {
cy.sendEvent(roomId, null, "m.room.message", {
body: "Reply to me",
msgtype: "m.text",
})
});
});
// select the room
cy.contains(".mx_RoomTile", "Test Room").click();
cy.get(".mx_ReplyPreview").should("not.exist");
// click reply-to on the Reply to me message
cy.contains(".mx_EventTile", "Reply to me").find('.mx_AccessibleButton[aria-label="Reply"]').click({ force: true });
// check it's visible
cy.get(".mx_ReplyPreview").should("exist");
// now click on the permalink for Permalink me
cy.contains(".mx_EventTile", "Permalink me").find("a").click({ force: true });
// make sure it is now selected with the little green |
cy.contains(".mx_EventTile_selected", "Permalink me").should("exist");
// ensure the reply-to does not disappear
cy.get(".mx_ReplyPreview").should("exist");
});
});
5 changes: 3 additions & 2 deletions src/stores/RoomViewStore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,9 @@ export class RoomViewStore extends Store<ActionPayload> {
// Allow being given an event to be replied to when switching rooms but sanity check its for this room
if (payload.replyingToEvent?.getRoomId() === payload.room_id) {
newState.replyingToEvent = payload.replyingToEvent;
} else if (this.state.roomId === payload.room_id) {
// if the room isn't being changed, e.g visiting a permalink then maintain replyingToEvent
} else if (this.state.replyingToEvent?.getRoomId() === payload.room_id) {
// if the reply-to matches the desired room, e.g visiting a permalink then maintain replyingToEvent
// See https://github.com/vector-im/element-web/issues/21462
newState.replyingToEvent = this.state.replyingToEvent;
}

Expand Down

0 comments on commit e5b081e

Please sign in to comment.