Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 809790d

Browse files
committed
Add e2e tests for the pinned message banner
1 parent 7cf26e3 commit 809790d

15 files changed

+95
-3
lines changed

playwright/e2e/pinned-messages/index.ts

+31-3
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,8 @@ export class Helpers {
168168

169169
/**
170170
* Return the right panel
171-
* @private
172171
*/
173-
private getRightPanel() {
172+
public getRightPanel() {
174173
return this.page.locator("#mx_RightPanel");
175174
}
176175

@@ -183,7 +182,6 @@ export class Helpers {
183182
await expect(rightPanel.getByRole("heading", { name: "Pinned messages" })).toHaveText(
184183
`${messages.length} Pinned messages`,
185184
);
186-
await expect(rightPanel).toMatchScreenshot(`pinned-messages-list-messages-${messages.length}.png`);
187185

188186
const list = rightPanel.getByRole("list");
189187
await expect(list.getByRole("listitem")).toHaveCount(messages.length);
@@ -243,6 +241,36 @@ export class Helpers {
243241
await item.getByRole("button").click();
244242
await this.page.getByRole("menu", { name: "Open menu" }).getByRole("menuitem", { name: "Unpin" }).click();
245243
}
244+
245+
/**
246+
* Return the banner
247+
* @private
248+
*/
249+
public getBanner() {
250+
return this.page.getByTestId("pinned-message-banner");
251+
}
252+
253+
/**
254+
* Assert that the banner contains the given message
255+
* @param msg
256+
*/
257+
async assertMessageInBanner(msg: string) {
258+
await expect(this.getBanner().getByText(msg)).toBeVisible();
259+
}
260+
261+
/**
262+
* Return the view all button
263+
*/
264+
public getViewAllButton() {
265+
return this.page.getByRole("button", { name: "View all" });
266+
}
267+
268+
/**
269+
* Return the close list button
270+
*/
271+
public getCloseListButton() {
272+
return this.page.getByRole("button", { name: "Close list" });
273+
}
246274
}
247275

248276
export { expect };

playwright/e2e/pinned-messages/pinned-messages.spec.ts

+63
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ test.describe("Pinned messages", () => {
4848
await util.openRoomInfo();
4949
await util.openPinnedMessagesList();
5050
await util.assertPinnedMessagesList(["Msg1", "Msg2", "Msg4"]);
51+
await expect(util.getRightPanel()).toMatchScreenshot(`pinned-messages-list-pin-3.png`);
5152
});
5253

5354
test("should unpin one message", async ({ page, app, room1, util }) => {
@@ -59,6 +60,7 @@ test.describe("Pinned messages", () => {
5960
await util.openPinnedMessagesList();
6061
await util.unpinMessageFromMessageList("Msg2");
6162
await util.assertPinnedMessagesList(["Msg1", "Msg4"]);
63+
await expect(util.getRightPanel()).toMatchScreenshot(`pinned-messages-list-unpin-2.png`);
6264
await util.backPinnedMessagesList();
6365
await util.assertPinnedCountInRoomInfo(2);
6466
});
@@ -87,4 +89,65 @@ test.describe("Pinned messages", () => {
8789
await util.pinMessagesFromQuickActions(["Msg1"], true);
8890
await util.assertPinnedCountInRoomInfo(0);
8991
});
92+
93+
test("should display one message in the banner", async ({ page, app, room1, util }) => {
94+
await util.goTo(room1);
95+
await util.receiveMessages(room1, ["Msg1"]);
96+
await util.pinMessages(["Msg1"]);
97+
await util.assertMessageInBanner("Msg1");
98+
await expect(util.getBanner()).toMatchScreenshot("pinned-message-banner-1-Msg1.png");
99+
});
100+
101+
test("should display 2 messages in the banner", async ({ page, app, room1, util }) => {
102+
await util.goTo(room1);
103+
await util.receiveMessages(room1, ["Msg1", "Msg2"]);
104+
await util.pinMessages(["Msg1", "Msg2"]);
105+
106+
await util.assertMessageInBanner("Msg1");
107+
await expect(util.getBanner()).toMatchScreenshot("pinned-message-banner-2-Msg1.png");
108+
109+
await util.getBanner().click();
110+
await util.assertMessageInBanner("Msg2");
111+
await expect(util.getBanner()).toMatchScreenshot("pinned-message-banner-2-Msg2.png");
112+
113+
await util.getBanner().click();
114+
await util.assertMessageInBanner("Msg1");
115+
await expect(util.getBanner()).toMatchScreenshot("pinned-message-banner-2-Msg1.png");
116+
});
117+
118+
test("should display 4 messages in the banner", async ({ page, app, room1, util }) => {
119+
await util.goTo(room1);
120+
await util.receiveMessages(room1, ["Msg1", "Msg2", "Msg3", "Msg4"]);
121+
await util.pinMessages(["Msg1", "Msg2", "Msg3", "Msg4"]);
122+
123+
for (const msg of ["Msg1", "Msg4", "Msg3", "Msg2"]) {
124+
await util.assertMessageInBanner(msg);
125+
await expect(util.getBanner()).toMatchScreenshot(`pinned-message-banner-4-${msg}.png`);
126+
await util.getBanner().click();
127+
}
128+
});
129+
130+
test("should open the pinned messages list from the banner", async ({ page, app, room1, util }) => {
131+
await util.goTo(room1);
132+
await util.receiveMessages(room1, ["Msg1", "Msg2"]);
133+
await util.pinMessages(["Msg1", "Msg2"]);
134+
135+
await util.getViewAllButton().click();
136+
await util.assertPinnedMessagesList(["Msg1", "Msg2"]);
137+
await expect(util.getRightPanel()).toMatchScreenshot("pinned-message-banner-2.png");
138+
139+
await expect(util.getCloseListButton()).toBeVisible();
140+
});
141+
142+
test("banner should listen to pinned message list", async ({ page, app, room1, util }) => {
143+
await util.goTo(room1);
144+
await util.receiveMessages(room1, ["Msg1", "Msg2"]);
145+
await util.pinMessages(["Msg1", "Msg2"]);
146+
147+
await expect(util.getViewAllButton()).toBeVisible();
148+
149+
await util.openRoomInfo();
150+
await util.openPinnedMessagesList();
151+
await expect(util.getCloseListButton()).toBeVisible();
152+
});
90153
});

src/components/views/rooms/PinnedMessageBanner.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ export function PinnedMessageBanner({ room, permalinkCreator }: PinnedMessageBan
8282
className="mx_PinnedMessageBanner"
8383
data-single-message={isSinglePinnedEvent}
8484
aria-label={_t("room|pinned_message_banner|description")}
85+
data-testid="pinned-message-banner"
8586
>
8687
<button
8788
aria-label={_t("room|pinned_message_banner|go_to_message")}

0 commit comments

Comments
 (0)