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

Commit 5831e47

Browse files
committed
e2e: add tests for message layout
1 parent 7aaadb4 commit 5831e47

File tree

6 files changed

+135
-80
lines changed

6 files changed

+135
-80
lines changed

playwright/e2e/settings/appearance-user-settings-tab/appearance-user-settings-tab.spec.ts

Lines changed: 54 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -33,43 +33,6 @@ test.describe("Appearance user settings tab", () => {
3333
await expect(tab).toMatchScreenshot("appearance-tab.png");
3434
});
3535

36-
test("should support switching layouts", async ({ page, user, app }) => {
37-
// Create and view a room first
38-
await app.client.createRoom({ name: "Test Room" });
39-
await app.viewRoomByName("Test Room");
40-
41-
await app.settings.openUserSettings("Appearance");
42-
43-
const buttons = page.locator(".mx_LayoutSwitcher_RadioButton");
44-
45-
// Assert that the layout selected by default is "Modern"
46-
await expect(
47-
buttons.locator(".mx_StyledRadioButton_enabled", {
48-
hasText: "Modern",
49-
}),
50-
).toBeVisible();
51-
52-
// Assert that the room layout is set to group (modern) layout
53-
await expect(page.locator(".mx_RoomView_body[data-layout='group']")).toBeVisible();
54-
55-
// Select the first layout
56-
await buttons.first().click();
57-
// Assert that the layout selected is "IRC (Experimental)"
58-
await expect(buttons.locator(".mx_StyledRadioButton_enabled", { hasText: "IRC (Experimental)" })).toBeVisible();
59-
60-
// Assert that the room layout is set to IRC layout
61-
await expect(page.locator(".mx_RoomView_body[data-layout='irc']")).toBeVisible();
62-
63-
// Select the last layout
64-
await buttons.last().click();
65-
66-
// Assert that the layout selected is "Message bubbles"
67-
await expect(buttons.locator(".mx_StyledRadioButton_enabled", { hasText: "Message bubbles" })).toBeVisible();
68-
69-
// Assert that the room layout is set to bubble layout
70-
await expect(page.locator(".mx_RoomView_body[data-layout='bubble']")).toBeVisible();
71-
});
72-
7336
test("should support changing font size by using the font size dropdown", async ({ page, app, user }) => {
7437
await app.settings.openUserSettings("Appearance");
7538

@@ -84,69 +47,80 @@ test.describe("Appearance user settings tab", () => {
8447
await expect(page).toMatchScreenshot("window-12px.png");
8548
});
8649

87-
test("should support enabling compact group (modern) layout", async ({ page, app, user }) => {
88-
// Create and view a room first
89-
await app.client.createRoom({ name: "Test Room" });
90-
await app.viewRoomByName("Test Room");
91-
50+
test("should support enabling system font", async ({ page, app, user }) => {
9251
await app.settings.openUserSettings("Appearance");
52+
const tab = page.getByTestId("mx_AppearanceUserSettingsTab");
9353

9454
// Click "Show advanced" link button
95-
const tab = page.getByTestId("mx_AppearanceUserSettingsTab");
9655
await tab.getByRole("button", { name: "Show advanced" }).click();
9756

98-
await tab.locator("label", { hasText: "Use a more compact 'Modern' layout" }).click();
57+
await tab.locator(".mx_Checkbox", { hasText: "Use bundled emoji font" }).click();
58+
await tab.locator(".mx_Checkbox", { hasText: "Use a system font" }).click();
9959

100-
// Assert that the room layout is set to compact group (modern) layout
101-
await expect(page.locator("#matrixchat .mx_MatrixChat_wrapper.mx_MatrixChat_useCompactLayout")).toBeVisible();
60+
// Assert that the font-family value was removed
61+
await expect(page.locator("body")).toHaveCSS("font-family", '""');
10262
});
10363

104-
test("should disable compact group (modern) layout option on IRC layout and bubble layout", async ({
105-
page,
106-
app,
107-
user,
108-
}) => {
109-
await app.settings.openUserSettings("Appearance");
110-
const tab = page.getByTestId("mx_AppearanceUserSettingsTab");
111-
112-
const checkDisabled = async () => {
113-
await expect(tab.getByRole("checkbox", { name: "Use a more compact 'Modern' layout" })).toBeDisabled();
114-
};
64+
test.describe("Message Layout Panel", () => {
65+
test.beforeEach(async ({ app, user, util }) => {
66+
await util.createAndDisplayRoom();
67+
await util.assertModernLayout();
68+
await util.openAppearanceTab();
69+
});
11570

116-
// Click "Show advanced" link button
117-
await tab.getByRole("button", { name: "Show advanced" }).click();
71+
test("should change the message layout from modern to bubble", async ({ page, app, user, util }) => {
72+
await expect(util.getMessageLayoutPanel()).toMatchScreenshot("message-layout-panel-modern.png");
11873

119-
const buttons = page.locator(".mx_LayoutSwitcher_RadioButton");
74+
await util.getBubbleLayout().click();
12075

121-
// Enable IRC layout
122-
await buttons.first().click();
76+
// Assert that modern are irc layout are not selected
77+
await expect(util.getBubbleLayout()).toBeChecked();
78+
await expect(util.getModernLayout()).not.toBeChecked();
79+
await expect(util.getIRCLayout()).not.toBeChecked();
12380

124-
// Assert that the layout selected is "IRC (Experimental)"
125-
await expect(buttons.locator(".mx_StyledRadioButton_enabled", { hasText: "IRC (Experimental)" })).toBeVisible();
81+
// Assert that the room layout is set to bubble layout
82+
await util.assertBubbleLayout();
83+
await expect(util.getMessageLayoutPanel()).toMatchScreenshot("message-layout-panel-bubble.png");
84+
});
12685

127-
await checkDisabled();
86+
test("should enable compact layout when the modern layout is selected", async ({ page, app, user, util }) => {
87+
await expect(util.getCompactLayoutCheckbox()).not.toBeChecked();
12888

129-
// Enable bubble layout
130-
await buttons.last().click();
89+
await util.getCompactLayoutCheckbox().click();
90+
await util.assertCompactLayout();
91+
});
13192

132-
// Assert that the layout selected is "IRC (Experimental)"
133-
await expect(buttons.locator(".mx_StyledRadioButton_enabled", { hasText: "Message bubbles" })).toBeVisible();
93+
test("should disable compact layout when the modern layout is not selected", async ({
94+
page,
95+
app,
96+
user,
97+
util,
98+
}) => {
99+
await expect(util.getCompactLayoutCheckbox()).not.toBeDisabled();
100+
101+
// Select the bubble layout, which should disable the compact layout checkbox
102+
await util.getBubbleLayout().click();
103+
await expect(util.getCompactLayoutCheckbox()).toBeDisabled();
104+
});
134105

135-
await checkDisabled();
136-
});
106+
test.skip("should support enabling compact group (modern) layout", async ({ page, app, user }) => {
107+
// Create and view a room first
108+
await app.client.createRoom({ name: "Test Room" });
109+
await app.viewRoomByName("Test Room");
137110

138-
test("should support enabling system font", async ({ page, app, user }) => {
139-
await app.settings.openUserSettings("Appearance");
140-
const tab = page.getByTestId("mx_AppearanceUserSettingsTab");
111+
await app.settings.openUserSettings("Appearance");
141112

142-
// Click "Show advanced" link button
143-
await tab.getByRole("button", { name: "Show advanced" }).click();
113+
// Click "Show advanced" link button
114+
const tab = page.getByTestId("mx_AppearanceUserSettingsTab");
115+
await tab.getByRole("button", { name: "Show advanced" }).click();
144116

145-
await tab.locator(".mx_Checkbox", { hasText: "Use bundled emoji font" }).click();
146-
await tab.locator(".mx_Checkbox", { hasText: "Use a system font" }).click();
117+
await tab.locator("label", { hasText: "Use a more compact 'Modern' layout" }).click();
147118

148-
// Assert that the font-family value was removed
149-
await expect(page.locator("body")).toHaveCSS("font-family", '""');
119+
// Assert that the room layout is set to compact group (modern) layout
120+
await expect(
121+
page.locator("#matrixchat .mx_MatrixChat_wrapper.mx_MatrixChat_useCompactLayout"),
122+
).toBeVisible();
123+
});
150124
});
151125

152126
test.describe("Theme Choice Panel", () => {

playwright/e2e/settings/appearance-user-settings-tab/index.ts

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { Page } from "@playwright/test";
1919
import { ElementAppPage } from "../../../pages/ElementAppPage";
2020
import { test as base, expect } from "../../../element-web-test";
2121
import { SettingLevel } from "../../../../src/settings/SettingLevel";
22+
import { Layout } from "../../../../src/settings/enums/Layout";
2223

2324
export { expect };
2425

@@ -136,4 +137,84 @@ class Helpers {
136137
removeCustomTheme() {
137138
return this.getThemePanel().getByRole("listitem", { name: this.CUSTOM_THEME.name }).getByRole("button").click();
138139
}
140+
141+
// Message layout Panel
142+
143+
/**
144+
* Create and display a room named Test Room
145+
*/
146+
async createAndDisplayRoom() {
147+
await this.app.client.createRoom({ name: "Test Room" });
148+
await this.app.viewRoomByName("Test Room");
149+
}
150+
151+
/**
152+
* Assert the room layout
153+
* @param layout
154+
* @private
155+
*/
156+
private assertRoomLayout(layout: Layout) {
157+
return expect(this.page.locator(`.mx_RoomView_body[data-layout=${layout}]`)).toBeVisible();
158+
}
159+
160+
/**
161+
* Assert the room layout is modern
162+
*/
163+
assertModernLayout() {
164+
return this.assertRoomLayout(Layout.Group);
165+
}
166+
167+
/**
168+
* Assert the room layout is bubble
169+
*/
170+
assertBubbleLayout() {
171+
return this.assertRoomLayout(Layout.Bubble);
172+
}
173+
174+
/**
175+
* Return the layout panel
176+
*/
177+
getMessageLayoutPanel() {
178+
return this.page.getByTestId("layoutPanel");
179+
}
180+
181+
/**
182+
* Return the layout radio button
183+
* @param layoutName
184+
* @private
185+
*/
186+
private getLayout(layoutName: string) {
187+
return this.getMessageLayoutPanel().getByRole("radio", { name: layoutName });
188+
}
189+
190+
/**
191+
* Return the message bubbles layout radio button
192+
*/
193+
getBubbleLayout() {
194+
return this.getLayout("Message bubbles");
195+
}
196+
197+
/**
198+
* Return the modern layout radio button
199+
*/
200+
getModernLayout() {
201+
return this.getLayout("Modern");
202+
}
203+
204+
/**
205+
* Return the IRC layout radio button
206+
*/
207+
getIRCLayout() {
208+
return this.getLayout("IRC (experimental)");
209+
}
210+
211+
getCompactLayoutCheckbox() {
212+
return this.getMessageLayoutPanel().getByRole("checkbox", { name: "Show compact text and messages" });
213+
}
214+
215+
assertCompactLayout() {
216+
return expect(
217+
this.page.locator("#matrixchat .mx_MatrixChat_wrapper.mx_MatrixChat_useCompactLayout"),
218+
).toBeVisible();
219+
}
139220
}

0 commit comments

Comments
 (0)