Skip to content

Commit 8035703

Browse files
committed
Simplify
1 parent 361e5fb commit 8035703

13 files changed

Lines changed: 55 additions & 59 deletions

File tree

apps/web/playwright/e2e/audio-player/audio-player.spec.ts

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import { test, expect } from "../../element-web-test";
1212
import { SettingLevel } from "../../../src/settings/SettingLevel";
1313
import { Layout } from "../../../src/settings/enums/Layout";
1414
import { type ElementAppPage } from "../../pages/ElementAppPage";
15-
import { getSampleFilePath } from "../../sample-files";
1615

1716
// Find and click "Reply" button
1817
const clickButtonReply = async (tile: Locator) => {
@@ -29,11 +28,9 @@ test.describe("Audio player", { tag: ["@no-firefox", "@no-webkit"] }, () => {
2928
displayName: "Hanako",
3029
});
3130

32-
const uploadFile = async (page: Page, sampleFile: string) => {
31+
const uploadFile = async (page: Page, file: string) => {
3332
// Upload a file from the message composer
34-
await page
35-
.locator(".mx_MessageComposer_actions input[type='file']")
36-
.setInputFiles(getSampleFilePath(sampleFile));
33+
await page.locator(".mx_MessageComposer_actions input[type='file']").setInputFiles(file);
3734

3835
// Find and click primary "Upload" button
3936
await page.locator(".mx_Dialog").getByRole("button", { name: "Upload" }).click();
@@ -44,7 +41,12 @@ test.describe("Audio player", { tag: ["@no-firefox", "@no-webkit"] }, () => {
4441
"Your message was sent",
4542
);
4643
// wait for the tile to finish loading
47-
await expect(page.getByTestId("audio-player-name").last().filter({ hasText: sampleFile })).toBeVisible();
44+
await expect(
45+
page
46+
.getByTestId("audio-player-name")
47+
.last()
48+
.filter({ hasText: file.split("/").at(-1) }),
49+
).toBeVisible();
4850
};
4951

5052
const scrollToBottomOfTimeline = async (page: Page) => {
@@ -156,15 +158,15 @@ test.describe("Audio player", { tag: ["@no-firefox", "@no-webkit"] }, () => {
156158
});
157159

158160
test("should be correctly rendered - light theme", { tag: "@screenshot" }, async ({ page, app }) => {
159-
await uploadFile(page, "1sec-long-name-audio-file.ogg");
161+
await uploadFile(page, "playwright/sample-files/1sec-long-name-audio-file.ogg");
160162
await takeSnapshots(page, app, "Selected EventTile of audio player (light theme)");
161163
});
162164

163165
test(
164166
"should be correctly rendered - light theme with monospace font",
165167
{ tag: "@screenshot" },
166168
async ({ page, app }) => {
167-
await uploadFile(page, "1sec-long-name-audio-file.ogg");
169+
await uploadFile(page, "playwright/sample-files/1sec-long-name-audio-file.ogg");
168170

169171
await takeSnapshots(page, app, "Selected EventTile of audio player (light theme, monospace font)", true); // Enable monospace
170172
},
@@ -181,7 +183,7 @@ test.describe("Audio player", { tag: ["@no-firefox", "@no-webkit"] }, () => {
181183

182184
await app.closeDialog();
183185

184-
await uploadFile(page, "1sec-long-name-audio-file.ogg");
186+
await uploadFile(page, "playwright/sample-files/1sec-long-name-audio-file.ogg");
185187

186188
await takeSnapshots(page, app, "Selected EventTile of audio player (high contrast)");
187189
});
@@ -190,13 +192,13 @@ test.describe("Audio player", { tag: ["@no-firefox", "@no-webkit"] }, () => {
190192
// Enable dark theme
191193
await app.settings.setValue("theme", null, SettingLevel.ACCOUNT, "dark");
192194

193-
await uploadFile(page, "1sec-long-name-audio-file.ogg");
195+
await uploadFile(page, "playwright/sample-files/1sec-long-name-audio-file.ogg");
194196

195197
await takeSnapshots(page, app, "Selected EventTile of audio player (dark theme)");
196198
});
197199

198200
test("should play an audio file", async ({ page, app }) => {
199-
await uploadFile(page, "1sec.ogg");
201+
await uploadFile(page, "playwright/sample-files/1sec.ogg");
200202

201203
// Assert that the audio player is rendered
202204
const container = page.locator(".mx_EventTile_last").getByRole("region", { name: "Audio player" });
@@ -218,7 +220,7 @@ test.describe("Audio player", { tag: ["@no-firefox", "@no-webkit"] }, () => {
218220
});
219221

220222
test("should support downloading an audio file", async ({ page, app }) => {
221-
await uploadFile(page, "1sec.ogg");
223+
await uploadFile(page, "playwright/sample-files/1sec.ogg");
222224

223225
const downloadPromise = page.waitForEvent("download");
224226

@@ -236,7 +238,7 @@ test.describe("Audio player", { tag: ["@no-firefox", "@no-webkit"] }, () => {
236238
"should support replying to audio file with another audio file",
237239
{ tag: "@screenshot" },
238240
async ({ page, app }) => {
239-
await uploadFile(page, "1sec.ogg");
241+
await uploadFile(page, "playwright/sample-files/1sec.ogg");
240242

241243
// Assert the audio player is rendered
242244
await expect(page.getByRole("region", { name: "Audio player" })).toBeVisible();
@@ -246,7 +248,7 @@ test.describe("Audio player", { tag: ["@no-firefox", "@no-webkit"] }, () => {
246248
await clickButtonReply(tile);
247249

248250
// Reply to the player with another audio file
249-
await uploadFile(page, "1sec.ogg");
251+
await uploadFile(page, "playwright/sample-files/1sec.ogg");
250252

251253
// Assert that the audio player is rendered
252254
await expect(tile.getByRole("region", { name: "Audio player" })).toBeVisible();
@@ -271,7 +273,7 @@ test.describe("Audio player", { tag: ["@no-firefox", "@no-webkit"] }, () => {
271273

272274
const tile = page.locator(".mx_EventTile_last");
273275

274-
await uploadFile(page, "upload-first.ogg");
276+
await uploadFile(page, "playwright/sample-files/upload-first.ogg");
275277

276278
// Assert that the audio player is rendered
277279
await expect(
@@ -281,7 +283,7 @@ test.describe("Audio player", { tag: ["@no-firefox", "@no-webkit"] }, () => {
281283
await clickButtonReply(tile);
282284

283285
// Reply to the player with another audio file
284-
await uploadFile(page, "upload-second.ogg");
286+
await uploadFile(page, "playwright/sample-files/upload-second.ogg");
285287

286288
// Assert that the audio player is rendered
287289
await expect(
@@ -291,7 +293,7 @@ test.describe("Audio player", { tag: ["@no-firefox", "@no-webkit"] }, () => {
291293
await clickButtonReply(tile);
292294

293295
// Reply to the player with yet another audio file to create a reply chain
294-
await uploadFile(page, "upload-third.ogg");
296+
await uploadFile(page, "playwright/sample-files/upload-third.ogg");
295297

296298
// Assert that the audio player is rendered
297299
await expect(tile.getByRole("region", { name: "Audio player" })).toBeVisible();
@@ -323,7 +325,7 @@ test.describe("Audio player", { tag: ["@no-firefox", "@no-webkit"] }, () => {
323325
);
324326

325327
test("should be rendered, play, and support replying on a thread", async ({ page, app }) => {
326-
await uploadFile(page, "1sec-long-name-audio-file.ogg");
328+
await uploadFile(page, "playwright/sample-files/1sec-long-name-audio-file.ogg");
327329

328330
// On the main timeline
329331
const messageList = page.locator(".mx_RoomView_MessageList");

apps/web/playwright/e2e/file-upload/image-upload.spec.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ Please see LICENSE files in the repository root for full details.
77
*/
88

99
import { test, expect } from "../../element-web-test";
10-
import { getSampleFilePath } from "../../sample-files";
1110

1211
test.describe("Image Upload", () => {
1312
test.use({
@@ -29,7 +28,7 @@ test.describe("Image Upload", () => {
2928
test("should show image preview when uploading an image", { tag: "@screenshot" }, async ({ page, app }) => {
3029
await page
3130
.locator(".mx_MessageComposer_actions input[type='file']")
32-
.setInputFiles(getSampleFilePath("riot.png"));
31+
.setInputFiles("playwright/sample-files/riot.png");
3332

3433
await expect(page.getByRole("button", { name: "Upload" })).toBeEnabled();
3534
await expect(page.getByRole("button", { name: "Close dialog" })).toBeEnabled();

apps/web/playwright/e2e/messages/messages.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ Please see LICENSE files in the repository root for full details.
99
/* See readme.md for tips on writing these tests. */
1010

1111
import { type Locator, type Page } from "@playwright/test";
12+
import { readFileSync } from "node:fs";
1213

1314
import { test, expect } from "../../element-web-test";
14-
import { readSampleFileSync } from "../../sample-files";
1515

16-
const MEDIA_FILE = readSampleFileSync("riot.png", null);
16+
const MEDIA_FILE = readFileSync("playwright/sample-files/riot.png");
1717

1818
async function waitForMessageSentStatus(msgTile: Locator): Promise<void> {
1919
await expect(msgTile.getByRole("status")).toHaveAccessibleName("Your message was sent");

apps/web/playwright/e2e/modules/custom-component.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ Please see LICENSE files in the repository root for full details.
66
*/
77

88
import { type Page } from "@playwright/test";
9+
import fs from "node:fs";
910

1011
import { test, expect } from "../../element-web-test";
11-
import { getSampleFilePath, readSampleFileSync } from "../../sample-files";
1212

1313
const screenshotOptions = (page: Page) => ({
1414
// Hide the jump to bottom button in the timeline to avoid flakiness
@@ -26,7 +26,7 @@ const screenshotOptions = (page: Page) => ({
2626
`,
2727
});
2828

29-
const IMAGE_FILE = readSampleFileSync("element.png", null);
29+
const IMAGE_FILE = fs.readFileSync("playwright/sample-files/element.png");
3030

3131
test.describe("Custom Component API", () => {
3232
test.use({
@@ -36,7 +36,7 @@ test.describe("Custom Component API", () => {
3636
},
3737
page: async ({ page }, use) => {
3838
await page.route("/modules/custom-component-module.js", async (route) => {
39-
await route.fulfill({ path: getSampleFilePath("custom-component-module.js") });
39+
await route.fulfill({ path: "playwright/sample-files/custom-component-module.js" });
4040
});
4141
await use(page);
4242
},

apps/web/playwright/e2e/modules/loader.spec.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ Please see LICENSE files in the repository root for full details.
66
*/
77

88
import { test, expect } from "../../element-web-test";
9-
import { getSampleFilePath } from "../../sample-files";
109

1110
test.describe("Module loading", () => {
1211
test.use({
@@ -21,7 +20,7 @@ test.describe("Module loading", () => {
2120
},
2221
page: async ({ page }, use) => {
2322
await page.route("/modules/example-module.js", async (route) => {
24-
await route.fulfill({ path: getSampleFilePath("example-module.js") });
23+
await route.fulfill({ path: "playwright/sample-files/example-module.js" });
2524
});
2625
await use(page);
2726
},

apps/web/playwright/e2e/right-panel/file-panel.spec.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import { type Page } from "@playwright/test";
1111
import { test, expect } from "../../element-web-test";
1212
import { viewRoomSummaryByName } from "./utils";
1313
import { isDendrite } from "../../plugins/homeserver/dendrite";
14-
import { getSampleFilePath } from "../../sample-files";
1514

1615
const ROOM_NAME = "Test room";
1716
const NAME = "Alice";
@@ -54,9 +53,9 @@ test.describe("FilePanel", () => {
5453

5554
test("should list tiles on the panel", { tag: "@screenshot" }, async ({ page }) => {
5655
// Upload multiple files
57-
await uploadFile(page, getSampleFilePath("riot.png")); // Image
58-
await uploadFile(page, getSampleFilePath("1sec.ogg")); // Audio
59-
await uploadFile(page, getSampleFilePath("matrix-org-client-versions.json")); // JSON
56+
await uploadFile(page, "playwright/sample-files/riot.png"); // Image
57+
await uploadFile(page, "playwright/sample-files/1sec.ogg"); // Audio
58+
await uploadFile(page, "playwright/sample-files/matrix-org-client-versions.json"); // JSON
6059

6160
const roomViewBody = page.locator(".mx_RoomView_body");
6261
// Assert that all of the file were uploaded and rendered
@@ -138,7 +137,7 @@ test.describe("FilePanel", () => {
138137

139138
test("should render the audio player and play the audio file on the panel", async ({ page }) => {
140139
// Upload an image file
141-
await uploadFile(page, getSampleFilePath("1sec.ogg"));
140+
await uploadFile(page, "playwright/sample-files/1sec.ogg");
142141

143142
const audioBody = page.getByTestId("right-panel").getByRole("region", { name: "Audio player" });
144143

@@ -171,7 +170,7 @@ test.describe("FilePanel", () => {
171170
const size = "1.12 KB"; // actual file size in kibibytes (1024 bytes)
172171

173172
// Upload a file
174-
await uploadFile(page, getSampleFilePath("matrix-org-client-versions.json"));
173+
await uploadFile(page, "playwright/sample-files/matrix-org-client-versions.json");
175174

176175
const tile = page.locator(".mx_FilePanel .mx_EventTile");
177176
// Assert that the file size is displayed in kibibytes, not kilobytes (1000 bytes)
@@ -185,7 +184,7 @@ test.describe("FilePanel", () => {
185184

186185
test("should download an image via the link on the panel", async ({ page, context }) => {
187186
// Upload an image file
188-
await uploadFile(page, getSampleFilePath("riot.png"));
187+
await uploadFile(page, "playwright/sample-files/riot.png");
189188

190189
// Detect the image file on the panel
191190
const imageBody = page.locator(

apps/web/playwright/e2e/settings/account-user-settings-tab.spec.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ Please see LICENSE files in the repository root for full details.
77
*/
88

99
import { test, expect } from "../../element-web-test";
10-
import { getSampleFilePath } from "../../sample-files";
1110

1211
const USER_NAME = "Bob";
1312
const USER_NAME_NEW = "Alice";
@@ -86,7 +85,7 @@ test.describe("Account user settings tab", () => {
8685
test("should support adding and removing a profile picture", async ({ uut, page }) => {
8786
const profileSettings = uut.locator(".mx_UserProfileSettings");
8887
// Upload a picture
89-
await profileSettings.getByAltText("Upload").setInputFiles(getSampleFilePath("riot.png"));
88+
await profileSettings.getByAltText("Upload").setInputFiles("playwright/sample-files/riot.png");
9089

9190
// Image should be visible
9291
await expect(profileSettings.locator(".mx_AvatarSetting_avatar img")).toBeVisible();

apps/web/playwright/e2e/spaces/spaces.spec.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import type { Preset, ICreateRoomOpts } from "matrix-js-sdk/src/matrix";
1212
import { type ElementAppPage } from "../../pages/ElementAppPage";
1313
import { isDendrite } from "../../plugins/homeserver/dendrite";
1414
import { UIFeature } from "../../../src/settings/UIFeature";
15-
import { getSampleFilePath } from "../../sample-files";
1615

1716
async function openSpaceCreateMenu(page: Page): Promise<Locator> {
1817
await page.getByRole("button", { name: "Create a space" }).click();
@@ -75,7 +74,7 @@ test.describe("Spaces", () => {
7574

7675
await contextMenu
7776
.locator('.mx_SpaceBasicSettings_avatarContainer input[type="file"]')
78-
.setInputFiles(getSampleFilePath("riot.png"));
77+
.setInputFiles("playwright/sample-files/riot.png");
7978
await contextMenu.getByRole("textbox", { name: "Name" }).fill("Let's have a Riot");
8079
await expect(contextMenu.getByRole("textbox", { name: "Address" })).toHaveValue("lets-have-a-riot");
8180
await contextMenu
@@ -109,7 +108,7 @@ test.describe("Spaces", () => {
109108

110109
await menu
111110
.locator('.mx_SpaceBasicSettings_avatarContainer input[type="file"]')
112-
.setInputFiles(getSampleFilePath("riot.png"));
111+
.setInputFiles("playwright/sample-files/riot.png");
113112
await menu.getByRole("textbox", { name: "Name" }).fill("This is not a Riot");
114113
await expect(menu.getByRole("textbox", { name: "Address" })).not.toBeVisible();
115114
await menu.getByRole("textbox", { name: "Description" }).fill("This is a private space of mourning Riot.im...");
@@ -155,7 +154,7 @@ test.describe("Spaces", () => {
155154

156155
await menu
157156
.locator('.mx_SpaceBasicSettings_avatarContainer input[type="file"]')
158-
.setInputFiles(getSampleFilePath("riot.png"));
157+
.setInputFiles("playwright/sample-files/riot.png");
159158
await expect(menu.getByRole("textbox", { name: "Address" })).not.toBeVisible();
160159
await menu.getByRole("textbox", { name: "Description" }).fill("This is a personal space to mourn Riot.im...");
161160
await menu.getByRole("textbox", { name: "Name" }).fill("This is my Riot");
@@ -189,7 +188,7 @@ test.describe("Spaces", () => {
189188

190189
await menu
191190
.locator('.mx_SpaceBasicSettings_avatarContainer input[type="file"]')
192-
.setInputFiles(getSampleFilePath("riot.png"));
191+
.setInputFiles("playwright/sample-files/riot.png");
193192
await expect(menu.getByRole("textbox", { name: "Address" })).not.toBeVisible();
194193
await menu
195194
.getByRole("textbox", { name: "Description" })
@@ -407,7 +406,7 @@ test.describe("Spaces", () => {
407406
const menu = await openSpaceCreateMenu(page);
408407
await menu
409408
.locator('.mx_SpaceBasicSettings_avatarContainer input[type="file"]')
410-
.setInputFiles(getSampleFilePath("riot.png"));
409+
.setInputFiles("playwright/sample-files/riot.png");
411410
await menu.getByRole("textbox", { name: "Name" }).fill("This is a private space");
412411
await expect(menu.getByRole("textbox", { name: "Address" })).not.toBeVisible();
413412
await menu

apps/web/playwright/e2e/timeline/media-preview-settings.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Com
55
Please see LICENSE files in the repository root for full details.
66
*/
77

8+
import * as fs from "node:fs";
89
import { type EventType, type MsgType, type RoomJoinRulesEventContent } from "matrix-js-sdk/src/types";
910

1011
import { test, expect } from "../../element-web-test";
11-
import { readSampleFileSync } from "../../sample-files";
1212

13-
const MEDIA_FILE = readSampleFileSync("riot.png", null);
13+
const MEDIA_FILE = fs.readFileSync("playwright/sample-files/riot.png");
1414

1515
test.describe("Media preview settings", () => {
1616
test.use({

apps/web/playwright/e2e/timeline/timeline.spec.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Com
66
Please see LICENSE files in the repository root for full details.
77
*/
88

9+
import * as fs from "node:fs";
10+
911
import type { Locator, Page } from "@playwright/test";
1012
import type { ISendEventResponse, EventType, MsgType } from "matrix-js-sdk/src/matrix";
1113
import { test, expect } from "../../element-web-test";
@@ -14,20 +16,19 @@ import { Layout } from "../../../src/settings/enums/Layout";
1416
import { type Client } from "../../pages/client";
1517
import { type ElementAppPage } from "../../pages/ElementAppPage";
1618
import { Bot } from "../../pages/bot";
17-
import { getSampleFilePath, readSampleFileSync } from "../../sample-files";
1819

1920
// The avatar size used in the timeline
2021
const AVATAR_SIZE = 30;
2122
// The resize method used in the timeline
2223
const AVATAR_RESIZE_METHOD = "crop";
2324

2425
const ROOM_NAME = "Test room";
25-
const OLD_AVATAR = readSampleFileSync("riot.png", null);
26-
const NEW_AVATAR = readSampleFileSync("element.png", null);
26+
const OLD_AVATAR = fs.readFileSync("playwright/sample-files/riot.png");
27+
const NEW_AVATAR = fs.readFileSync("playwright/sample-files/element.png");
2728
const OLD_NAME = "Alan";
2829
const NEW_NAME = "Alan (away)";
2930

30-
const VIDEO_FILE = readSampleFileSync("5secvid.webm", null);
31+
const VIDEO_FILE = fs.readFileSync("playwright/sample-files/5secvid.webm");
3132

3233
const getEventTilesWithBodies = (page: Page): Locator => {
3334
return page.locator(".mx_EventTile").filter({ has: page.locator(".mx_EventTile_body") });
@@ -764,7 +765,7 @@ test.describe("Timeline", () => {
764765
// Upload a file from the message composer
765766
await page
766767
.locator(".mx_MessageComposer_actions input[type='file']")
767-
.setInputFiles(getSampleFilePath("matrix-org-client-versions.json"));
768+
.setInputFiles("playwright/sample-files/matrix-org-client-versions.json");
768769

769770
// Click "Upload" button
770771
await page.locator(".mx_Dialog").getByRole("button", { name: "Upload" }).click();

0 commit comments

Comments
 (0)