From 0dc295e3b8c706cd2af036a6aa13d9e6bbec9c8f Mon Sep 17 00:00:00 2001 From: R Midhun Suresh Date: Fri, 21 Mar 2025 13:58:00 +0530 Subject: [PATCH] RoomListStore: Unread filter should only filter rooms having unread counts (#29555) * Use `hasUnreadCount` instead of `isUnread` * Fix broken test * Write test --- .../room-list-panel/room-list.spec.ts | 37 +++++++++++++++++++ .../skip-list/filters/UnreadFilter.ts | 2 +- .../room-list-v3/RoomListStoreV3-test.ts | 4 +- 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/playwright/e2e/left-panel/room-list-panel/room-list.spec.ts b/playwright/e2e/left-panel/room-list-panel/room-list.spec.ts index ed402bc625..6f19bf60d1 100644 --- a/playwright/e2e/left-panel/room-list-panel/room-list.spec.ts +++ b/playwright/e2e/left-panel/room-list-panel/room-list.spec.ts @@ -93,4 +93,41 @@ test.describe("Room list", () => { await filters.getByRole("option", { name: "People" }).click(); await expect(roomListView.getByRole("gridcell", { name: "Open room room0" })).toBeVisible(); }); + + test("unread filter should only match unread rooms that have a count", async ({ page, app, bot }) => { + const roomListView = getRoomList(page); + // Let's create a new room and invite the bot + const room1Id = await app.client.createRoom({ + name: "Unread Room 1", + invite: [bot.credentials?.userId], + }); + await bot.awaitRoomMembership(room1Id); + + // Let's create another room as well + const room2Id = await app.client.createRoom({ + name: "Unread Room 2", + invite: [bot.credentials?.userId], + }); + await bot.awaitRoomMembership(room2Id); + + // Let's configure unread room 1 so that we only get notification for mentions and keywords + await app.viewRoomById(room1Id); + await app.settings.openRoomSettings("Notifications"); + await page.getByText("@mentions & keywords").click(); + await app.settings.closeDialog(); + + // Let's open a room other than room 1 or room 2 + await roomListView.getByRole("gridcell", { name: "Open room room29" }).click(); + + // Let's make the bot send a new message in both room 1 and room 2 + await bot.sendMessage(room1Id, "Hello!"); + await bot.sendMessage(room2Id, "Hello!"); + + // Let's activate the unread filter now + await page.getByRole("option", { name: "Unread" }).click(); + + // Unread filter should only show room 2!! + await expect(roomListView.getByRole("gridcell", { name: "Open room Unread Room 2" })).toBeVisible(); + await expect(roomListView.getByRole("gridcell", { name: "Open room Unread Room 1" })).not.toBeVisible(); + }); }); diff --git a/src/stores/room-list-v3/skip-list/filters/UnreadFilter.ts b/src/stores/room-list-v3/skip-list/filters/UnreadFilter.ts index c830f1d55b..e2ffc8f0f4 100644 --- a/src/stores/room-list-v3/skip-list/filters/UnreadFilter.ts +++ b/src/stores/room-list-v3/skip-list/filters/UnreadFilter.ts @@ -11,7 +11,7 @@ import { RoomNotificationStateStore } from "../../../notifications/RoomNotificat export class UnreadFilter implements Filter { public matches(room: Room): boolean { - return RoomNotificationStateStore.instance.getRoomState(room).isUnread; + return RoomNotificationStateStore.instance.getRoomState(room).hasUnreadCount; } public get key(): FilterKey.UnreadFilter { diff --git a/test/unit-tests/stores/room-list-v3/RoomListStoreV3-test.ts b/test/unit-tests/stores/room-list-v3/RoomListStoreV3-test.ts index 0fdef53729..573e7a38b4 100644 --- a/test/unit-tests/stores/room-list-v3/RoomListStoreV3-test.ts +++ b/test/unit-tests/stores/room-list-v3/RoomListStoreV3-test.ts @@ -457,7 +457,7 @@ describe("RoomListStoreV3", () => { // Let's say 8, 27 are unread jest.spyOn(RoomNotificationStateStore.instance, "getRoomState").mockImplementation((room) => { const state = { - isUnread: [rooms[8], rooms[27]].includes(room), + hasUnreadCount: [rooms[8], rooms[27]].includes(room), } as unknown as RoomNotificationState; return state; }); @@ -588,7 +588,7 @@ describe("RoomListStoreV3", () => { // Let's say 8, 27 are unread jest.spyOn(RoomNotificationStateStore.instance, "getRoomState").mockImplementation((room) => { const state = { - isUnread: [rooms[8], rooms[27]].includes(room), + hasUnreadCount: [rooms[8], rooms[27]].includes(room), } as unknown as RoomNotificationState; return state; });