Skip to content

Commit fec4f85

Browse files
floriandurosDileep Bandla
authored andcommitted
New room list: fix missing/incorrect notification decoration (element-hq#29796)
* fix: recompute notification when room change in room list item vm * test: add use case when room list change * test(e2e): add screenshot to unread filter test
1 parent fca619b commit fec4f85

4 files changed

Lines changed: 52 additions & 23 deletions

File tree

playwright/e2e/left-panel/room-list-panel/room-list-filter-sort.spec.ts

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -140,29 +140,35 @@ test.describe("Room list filters and sort", () => {
140140
expect(await roomList.locator("role=gridcell").count()).toBe(3);
141141
});
142142

143-
test("unread filter should only match unread rooms that have a count", async ({ page, app, bot }) => {
144-
const roomListView = getRoomList(page);
145-
146-
// Let's configure unread dm room so that we only get notification for mentions and keywords
147-
await app.viewRoomById(unReadDmId);
148-
await app.settings.openRoomSettings("Notifications");
149-
await page.getByText("@mentions & keywords").click();
150-
await app.settings.closeDialog();
151-
152-
// Let's open a room other than unread room or unread dm
153-
await roomListView.getByRole("gridcell", { name: "Open room favourite room" }).click();
154-
155-
// Let's make the bot send a new message in both rooms
156-
await bot.sendMessage(unReadDmId, "Hello!");
157-
await bot.sendMessage(unReadRoomId, "Hello!");
158-
159-
// Let's activate the unread filter now
160-
await page.getByRole("option", { name: "Unread" }).click();
161-
162-
// Unread filter should only show unread room and not unread dm!
163-
await expect(roomListView.getByRole("gridcell", { name: "Open room unread room" })).toBeVisible();
164-
await expect(roomListView.getByRole("gridcell", { name: "Open room unread dm" })).not.toBeVisible();
165-
});
143+
test(
144+
"unread filter should only match unread rooms that have a count",
145+
{ tag: "@screenshot" },
146+
async ({ page, app, bot }) => {
147+
const roomListView = getRoomList(page);
148+
149+
// Let's configure unread dm room so that we only get notification for mentions and keywords
150+
await app.viewRoomById(unReadDmId);
151+
await app.settings.openRoomSettings("Notifications");
152+
await page.getByText("@mentions & keywords").click();
153+
await app.settings.closeDialog();
154+
155+
// Let's open a room other than unread room or unread dm
156+
await roomListView.getByRole("gridcell", { name: "Open room favourite room" }).click();
157+
158+
// Let's make the bot send a new message in both rooms
159+
await bot.sendMessage(unReadDmId, "Hello!");
160+
await bot.sendMessage(unReadRoomId, "Hello!");
161+
162+
// Let's activate the unread filter now
163+
await page.getByRole("option", { name: "Unread" }).click();
164+
165+
// Unread filter should only show unread room and not unread dm!
166+
const unreadDm = roomListView.getByRole("gridcell", { name: "Open room unread room" });
167+
await expect(unreadDm).toBeVisible();
168+
await expect(unreadDm).toMatchScreenshot("unread-dm.png");
169+
await expect(roomListView.getByRole("gridcell", { name: "Open room unread dm" })).not.toBeVisible();
170+
},
171+
);
166172
});
167173

168174
test.describe("Empty room list", () => {
3.04 KB
Loading

src/components/viewmodels/roomlist/RoomListItemViewModel.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@ export function useRoomListItemViewModel(room: Room): RoomListItemViewState {
9292
setNotificationValues(getNotificationValues(notificationState));
9393
});
9494

95+
// If the notification reference change due to room change, update the values
96+
useEffect(() => {
97+
setNotificationValues(getNotificationValues(notificationState));
98+
}, [notificationState]);
99+
95100
// We don't want to show the hover menu if
96101
// - there is an invitation for this room
97102
// - the user doesn't have access to both notification and more options menus

test/unit-tests/components/viewmodels/roomlist/RoomListItemViewModel-test.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,24 @@ describe("RoomListItemViewModel", () => {
128128
);
129129
expect(vm.current.isBold).toBe(true);
130130
});
131+
132+
it("should recompute notification state when room changes", () => {
133+
const newRoom = mkStubRoom("room2", "Room 2", room.client);
134+
const newNotificationState = new RoomNotificationState(newRoom, false);
135+
136+
const { result, rerender } = renderHook((room) => useRoomListItemViewModel(room), {
137+
...withClientContextRenderOptions(room.client),
138+
initialProps: room,
139+
});
140+
141+
expect(result.current.showNotificationDecoration).toBe(false);
142+
143+
jest.spyOn(newNotificationState, "hasAnyNotificationOrActivity", "get").mockReturnValue(true);
144+
jest.spyOn(RoomNotificationStateStore.instance, "getRoomState").mockReturnValue(newNotificationState);
145+
rerender(newRoom);
146+
147+
expect(result.current.showNotificationDecoration).toBe(true);
148+
});
131149
});
132150

133151
describe("a11yLabel", () => {

0 commit comments

Comments
 (0)