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

Commit 3af777d

Browse files
committed
Add e2e tests for the pinned message banner
1 parent a38ffa6 commit 3af777d

11 files changed

+91
-0
lines changed

playwright/e2e/pinned-messages/index.ts

+30
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,36 @@ export class Helpers {
243243
await item.getByRole("button").click();
244244
await this.page.getByRole("menu", { name: "Open menu" }).getByRole("menuitem", { name: "Unpin" }).click();
245245
}
246+
247+
/**
248+
* Return the banner
249+
* @private
250+
*/
251+
public getBanner() {
252+
return this.page.getByTestId("pinned-message-banner");
253+
}
254+
255+
/**
256+
* Assert that the banner contains the given message
257+
* @param msg
258+
*/
259+
async assertMessageInBanner(msg: string) {
260+
await expect(this.getBanner().getByText(msg)).toBeVisible();
261+
}
262+
263+
/**
264+
* Return the view all button
265+
*/
266+
public getViewAllButton() {
267+
return this.page.getByRole("button", { name: "View all" });
268+
}
269+
270+
/**
271+
* Return the close list button
272+
*/
273+
public getCloseListButton() {
274+
return this.page.getByRole("button", { name: "Close list" });
275+
}
246276
}
247277

248278
export { expect };

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

+60
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,64 @@ test.describe("Pinned messages", () => {
8787
await util.pinMessagesFromQuickActions(["Msg1"], true);
8888
await util.assertPinnedCountInRoomInfo(0);
8989
});
90+
91+
test("should display one message in the banner", async ({ page, app, room1, util }) => {
92+
await util.goTo(room1);
93+
await util.receiveMessages(room1, ["Msg1"]);
94+
await util.pinMessages(["Msg1"]);
95+
await util.assertMessageInBanner("Msg1");
96+
await expect(util.getBanner()).toMatchScreenshot("pinned-message-banner-1-Msg1.png");
97+
});
98+
99+
test("should display 2 messages in the banner", async ({ page, app, room1, util }) => {
100+
await util.goTo(room1);
101+
await util.receiveMessages(room1, ["Msg1", "Msg2"]);
102+
await util.pinMessages(["Msg1", "Msg2"]);
103+
104+
await util.assertMessageInBanner("Msg1");
105+
await expect(util.getBanner()).toMatchScreenshot("pinned-message-banner-2-Msg1.png");
106+
107+
await util.getBanner().click();
108+
await util.assertMessageInBanner("Msg2");
109+
await expect(util.getBanner()).toMatchScreenshot("pinned-message-banner-2-Msg2.png");
110+
111+
await util.getBanner().click();
112+
await util.assertMessageInBanner("Msg1");
113+
await expect(util.getBanner()).toMatchScreenshot("pinned-message-banner-2-Msg1.png");
114+
});
115+
116+
test("should display 4 messages in the banner", async ({ page, app, room1, util }) => {
117+
await util.goTo(room1);
118+
await util.receiveMessages(room1, ["Msg1", "Msg2", "Msg3", "Msg4"]);
119+
await util.pinMessages(["Msg1", "Msg2", "Msg3", "Msg4"]);
120+
121+
for (const msg of ["Msg1", "Msg4", "Msg3", "Msg2"]) {
122+
await util.assertMessageInBanner(msg);
123+
await expect(util.getBanner()).toMatchScreenshot(`pinned-message-banner-4-${msg}.png`);
124+
await util.getBanner().click();
125+
}
126+
});
127+
128+
test("should open the pinned messages list from the banner", async ({ page, app, room1, util }) => {
129+
await util.goTo(room1);
130+
await util.receiveMessages(room1, ["Msg1", "Msg2"]);
131+
await util.pinMessages(["Msg1", "Msg2"]);
132+
133+
await util.getViewAllButton().click();
134+
await util.assertPinnedMessagesList(["Msg1", "Msg2"]);
135+
136+
await expect(util.getCloseListButton()).toBeVisible();
137+
});
138+
139+
test("banner should listen to pinned message list", async ({ page, app, room1, util }) => {
140+
await util.goTo(room1);
141+
await util.receiveMessages(room1, ["Msg1", "Msg2"]);
142+
await util.pinMessages(["Msg1", "Msg2"]);
143+
144+
await expect(util.getViewAllButton()).toBeVisible();
145+
146+
await util.openRoomInfo();
147+
await util.openPinnedMessagesList();
148+
await expect(util.getCloseListButton()).toBeVisible();
149+
});
90150
});

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)