Skip to content

Commit 2ef37b8

Browse files
committed
test(e2e): add tests for primary filters
1 parent 1790fa3 commit 2ef37b8

File tree

1 file changed

+88
-0
lines changed

1 file changed

+88
-0
lines changed
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/*
2+
* Copyright 2025 New Vector Ltd.
3+
*
4+
* SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
5+
* Please see LICENSE files in the repository root for full details.
6+
*/
7+
8+
import { expect, test } from "../../../element-web-test";
9+
import type { Page } from "@playwright/test";
10+
11+
test.describe("Room list filters and sort", () => {
12+
test.use({
13+
displayName: "Alice",
14+
botCreateOpts: {
15+
displayName: "BotBob",
16+
autoAcceptInvites: true,
17+
},
18+
labsFlags: ["feature_new_room_list"],
19+
});
20+
21+
/**
22+
* Get the room list
23+
* @param page
24+
*/
25+
function getRoomList(page: Page) {
26+
return page.getByTestId("room-list");
27+
}
28+
29+
function getPrimaryFilters(page: Page) {
30+
return page.getByRole("listbox", { name: "Room list primary filters" });
31+
}
32+
33+
test.beforeEach(async ({ page, app, bot, user }) => {
34+
// The notification toast is displayed above the search section
35+
await app.closeNotificationToast();
36+
37+
await app.client.createRoom({ name: "empty room" });
38+
39+
const unReadDmId = await bot.createRoom({
40+
name: "unread dm",
41+
invite: [user.userId],
42+
is_direct: true,
43+
});
44+
await bot.sendMessage(unReadDmId, "I am a robot. Beep.");
45+
46+
const unReadRoomId = await app.client.createRoom({ name: "unread room" });
47+
await app.client.inviteUser(unReadRoomId, bot.credentials.userId);
48+
await bot.joinRoom(unReadRoomId);
49+
await bot.sendMessage(unReadRoomId, "I am a robot. Beep.");
50+
51+
const favouriteId = await app.client.createRoom({ name: "favourite room" });
52+
await app.client.evaluate(async (client, favouriteId) => {
53+
await client.setRoomTag(favouriteId, "m.favourite", { order: 0.5 });
54+
}, favouriteId);
55+
});
56+
57+
test("should filter the list (with primary filters)", { tag: "@screenshot" }, async ({ page, app, user }) => {
58+
const roomList = getRoomList(page);
59+
const primaryFilters = getPrimaryFilters(page);
60+
61+
const allFilters = await primaryFilters.locator("option").all();
62+
for (const filter of allFilters) {
63+
expect(await filter.getAttribute("aria-selected")).toBe("false");
64+
}
65+
await expect(primaryFilters).toMatchScreenshot("unselected-primary-filters.png");
66+
67+
await primaryFilters.getByRole("option", { name: "Unread" }).click();
68+
// only one room should be visible
69+
await expect(roomList.getByRole("gridcell", { name: "unread dm" })).toBeVisible();
70+
await expect(roomList.getByRole("gridcell", { name: "unread room" })).toBeVisible();
71+
expect(await roomList.locator("role=gridcell").count()).toBe(2);
72+
await expect(primaryFilters).toMatchScreenshot("unread-primary-filters.png");
73+
74+
await primaryFilters.getByRole("option", { name: "Favourite" }).click();
75+
await expect(roomList.getByRole("gridcell", { name: "favourite room" })).toBeVisible();
76+
expect(await roomList.locator("role=gridcell").count()).toBe(1);
77+
78+
await primaryFilters.getByRole("option", { name: "People" }).click();
79+
await expect(roomList.getByRole("gridcell", { name: "unread dm" })).toBeVisible();
80+
expect(await roomList.locator("role=gridcell").count()).toBe(1);
81+
82+
await primaryFilters.getByRole("option", { name: "Rooms" }).click();
83+
await expect(roomList.getByRole("gridcell", { name: "unread room" })).toBeVisible();
84+
await expect(roomList.getByRole("gridcell", { name: "favourite room" })).toBeVisible();
85+
await expect(roomList.getByRole("gridcell", { name: "empty room" })).toBeVisible();
86+
expect(await roomList.locator("role=gridcell").count()).toBe(3);
87+
});
88+
});

0 commit comments

Comments
 (0)