From 1dc3038e94ed56d0e6b8e9c65314c99e4fd68625 Mon Sep 17 00:00:00 2001 From: Andy Balaam Date: Thu, 31 Aug 2023 13:40:09 +0100 Subject: [PATCH] Make edits more realistic in receipt tests --- cypress/e2e/read-receipts/high-level.spec.ts | 79 ++++++++++++++++---- 1 file changed, 66 insertions(+), 13 deletions(-) diff --git a/cypress/e2e/read-receipts/high-level.spec.ts b/cypress/e2e/read-receipts/high-level.spec.ts index 28f6c944d580..7c87351b7300 100644 --- a/cypress/e2e/read-receipts/high-level.spec.ts +++ b/cypress/e2e/read-receipts/high-level.spec.ts @@ -103,6 +103,11 @@ describe("Read receipts", () => { }); } + function backToThreadsList() { + cy.log("Back to threads list"); + cy.get(".mx_RightPanel").findByTitle("Threads").click(); + } + function openThread(rootMessage: string) { cy.log("Open thread", rootMessage); cy.get(".mx_RoomView_body", { log: false }).within(() => { @@ -191,6 +196,10 @@ describe("Read receipts", () => { msgtype: content.msgtype, body: newMessage, }, + "m.relates_to": { + rel_type: "m.replace", + event_id: ev.getId(), + }, }; } })(); @@ -666,21 +675,34 @@ describe("Read receipts", () => { }); it.skip("Reading a thread root within the thread view marks it as read in the main timeline", () => {}); it("Creating a new thread based on a reply makes the room unread", () => { + // Given a message and reply exist and are read goTo(room1); - receiveMessages(room2, ["Msg1", replyTo("Msg1", "Reply1"), threadedOff("Reply1", "Resp1")]); - assertUnread(room2, 3); + receiveMessages(room2, ["Msg1", replyTo("Msg1", "Reply1")]); + goTo(room2); + goTo(room1); + assertRead(room2); + + // When I receive a thread message created on the reply + receiveMessages(room2, [threadedOff("Reply1", "Resp1")]); + + // Then the room is unread + assertUnread(room2, 1); }); it("Reading a thread whose root is a reply makes the room read", () => { + // Given an unread thread off a reply exists goTo(room1); receiveMessages(room2, ["Msg1", replyTo("Msg1", "Reply1"), threadedOff("Reply1", "Resp1")]); assertUnread(room2, 3); - goTo(room2); assertUnread(room2, 1); assertUnreadThread("Reply1"); + // When I read the thread openThread("Reply1"); + + // Then the room and thread are read assertRead(room2); + assertReadThread("Reply1"); }); }); }); @@ -821,36 +843,48 @@ describe("Read receipts", () => { describe("in threads", () => { it("An edit of a threaded message makes the room unread", () => { + // Given we have read the thread goTo(room1); receiveMessages(room2, ["Msg1", threadedOff("Msg1", "Resp1")]); assertUnread(room2, 2); - goTo(room2); openThread("Msg1"); assertRead(room2); + backToThreadsList(); goTo(room1); + // When a message inside it is edited receiveMessages(room2, [editOf("Resp1", "Edit1")]); + + // Then the room and thread are unread assertUnread(room2, 1); + goTo(room2); + assertUnreadThread("Msg1"); }); it("Reading an edit of a threaded message makes the room read", () => { + // Given an edited thread message is making the room unread goTo(room1); receiveMessages(room2, ["Msg1", threadedOff("Msg1", "Resp1")]); assertUnread(room2, 2); - goTo(room2); openThread("Msg1"); assertRead(room2); + backToThreadsList(); goTo(room1); - receiveMessages(room2, [editOf("Resp1", "Edit1")]); assertUnread(room2, 1); + // When I read it goTo(room2); openThread("Msg1"); + + // Then the room and thread are read assertRead(room2); + assertReadThread("Msg1"); }); - it("Marking a room as read after an edit in a thread makes it read", () => { + // XXX: fails because the room is still bold/dot even after marking as read + it.skip("Marking a room as read after an edit in a thread makes it read", () => { + // Given an edit in a thread is making the room unread goTo(room1); receiveMessages(room2, ["Msg1", threadedOff("Msg1", "Resp1"), editOf("Resp1", "Edit1")]); assertUnread(room2, 3); // TODO: the edit counts as a message! @@ -876,39 +910,58 @@ describe("Read receipts", () => { assertUnread(room2, 1); // TODO: should this edit make us unread? }); it("A room with an edited threaded message is still unread after restart", () => { + // Given an edit in a thread is making a room unread goTo(room1); - receiveMessages(room2, ["Msg1", threadedOff("Msg1", "Resp1"), editOf("Resp1", "Edit1")]); - assertUnread(room2, 3); + receiveMessages(room2, ["Msg1", threadedOff("Msg1", "Resp1")]); + markAsRead(room2); + receiveMessages(room2, [editOf("Resp1", "Edit1")]); + assertUnread(room2, 1); + // When I restart saveAndReload(); - assertUnread(room2, 3); + + // Then is it still unread + assertUnread(room2, 1); }); - it("A room where all threaded edits are read is still read after restart", () => { + // XXX: fails for the same reason as "Marking a room as read after an edit in a thread makes it read" + it.skip("A room where all threaded edits are read is still read after restart", () => { + // Given I have marked an edit in a thread as read goTo(room1); receiveMessages(room2, ["Msg1", threadedOff("Msg1", "Resp1"), editOf("Resp1", "Edit1")]); assertUnread(room2, 3); - markAsRead(room2); assertRead(room2); + // When I restart saveAndReload(); + + // It is still read assertRead(room2); }); }); describe("thread roots", () => { it("An edit of a thread root makes the room unread", () => { + // Given I have read a thread goTo(room1); receiveMessages(room2, ["Msg1", threadedOff("Msg1", "Resp1")]); assertUnread(room2, 2); - goTo(room2); openThread("Msg1"); + backToThreadsList(); assertRead(room2); goTo(room1); + // When the thread root is edited receiveMessages(room2, [editOf("Msg1", "Edit1")]); + + // Then the room is unread assertUnread(room2, 1); + + // But the thread is read + goTo(room2); + assertRead(room2); + assertReadThread("Edit1"); }); it.skip("Reading an edit of a thread root makes the room read", () => { // Given a fully-read thread exists