|
| 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 * as fs from "node:fs"; |
| 9 | +import { type EventType, type MsgType, type RoomJoinRulesEventContent } from "matrix-js-sdk/src/types"; |
| 10 | + |
| 11 | +import { test, expect } from "../../element-web-test"; |
| 12 | + |
| 13 | +const MEDIA_FILE = fs.readFileSync("playwright/sample-files/riot.png"); |
| 14 | + |
| 15 | +test.describe("Media preview settings", () => { |
| 16 | + test.use({ |
| 17 | + displayName: "Alan", |
| 18 | + room: async ({ app, page, homeserver, bot, user }, use) => { |
| 19 | + const mxc = (await bot.uploadContent(MEDIA_FILE, { name: "image.png", type: "image/png" })).content_uri; |
| 20 | + const roomId = await bot.createRoom({ |
| 21 | + name: "Test room", |
| 22 | + invite: [user.userId], |
| 23 | + initial_state: [{ type: "m.room.avatar", content: { url: mxc }, state_key: "" }], |
| 24 | + }); |
| 25 | + await bot.sendEvent(roomId, null, "m.room.message" as EventType, { |
| 26 | + msgtype: "m.image" as MsgType, |
| 27 | + body: "image.png", |
| 28 | + url: mxc, |
| 29 | + }); |
| 30 | + |
| 31 | + await use({ roomId }); |
| 32 | + }, |
| 33 | + }); |
| 34 | + |
| 35 | + test("should be able to hide avatars of inviters", { tag: "@screenshot" }, async ({ page, app, room, user }) => { |
| 36 | + let settings = await app.settings.openUserSettings("Preferences"); |
| 37 | + await settings.getByLabel("Hide avatars of room and inviter").click(); |
| 38 | + await app.closeDialog(); |
| 39 | + await app.viewRoomById(room.roomId); |
| 40 | + await expect( |
| 41 | + page.getByRole("complementary").filter({ hasText: "Do you want to join Test room" }), |
| 42 | + ).toMatchScreenshot("invite-no-avatar.png"); |
| 43 | + await expect( |
| 44 | + page.getByRole("tree", { name: "Rooms" }).getByRole("treeitem", { name: "Test room" }), |
| 45 | + ).toMatchScreenshot("invite-room-tree-no-avatar.png"); |
| 46 | + |
| 47 | + // And then go back to being visible |
| 48 | + settings = await app.settings.openUserSettings("Preferences"); |
| 49 | + await settings.getByLabel("Hide avatars of room and inviter").click(); |
| 50 | + await app.closeDialog(); |
| 51 | + await page.goto("#/home"); |
| 52 | + await app.viewRoomById(room.roomId); |
| 53 | + await expect( |
| 54 | + page.getByRole("complementary").filter({ hasText: "Do you want to join Test room" }), |
| 55 | + ).toMatchScreenshot("invite-with-avatar.png"); |
| 56 | + await expect( |
| 57 | + page.getByRole("tree", { name: "Rooms" }).getByRole("treeitem", { name: "Test room" }), |
| 58 | + ).toMatchScreenshot("invite-room-tree-with-avatar.png"); |
| 59 | + }); |
| 60 | + |
| 61 | + test("should be able to hide media in rooms globally", async ({ page, app, room, user }) => { |
| 62 | + const settings = await app.settings.openUserSettings("Preferences"); |
| 63 | + await settings.getByLabel("Show media in timeline").getByRole("radio", { name: "Always hide" }).click(); |
| 64 | + await app.closeDialog(); |
| 65 | + await app.viewRoomById(room.roomId); |
| 66 | + await page.getByRole("button", { name: "Accept" }).click(); |
| 67 | + await expect(page.getByText("Show image")).toBeVisible(); |
| 68 | + }); |
| 69 | + test("should be able to hide media in non-private rooms globally", async ({ page, app, room, user, bot }) => { |
| 70 | + await bot.sendStateEvent(room.roomId, "m.room.join_rules", { |
| 71 | + join_rule: "public", |
| 72 | + }); |
| 73 | + const settings = await app.settings.openUserSettings("Preferences"); |
| 74 | + await settings.getByLabel("Show media in timeline").getByLabel("In private rooms").click(); |
| 75 | + await app.closeDialog(); |
| 76 | + await app.viewRoomById(room.roomId); |
| 77 | + await page.getByRole("button", { name: "Accept" }).click(); |
| 78 | + await expect(page.getByText("Show image")).toBeVisible(); |
| 79 | + for (const joinRule of ["invite", "knock", "restricted"] as RoomJoinRulesEventContent["join_rule"][]) { |
| 80 | + await bot.sendStateEvent(room.roomId, "m.room.join_rules", { |
| 81 | + join_rule: joinRule, |
| 82 | + } satisfies RoomJoinRulesEventContent); |
| 83 | + await expect(page.getByText("Show image")).not.toBeVisible(); |
| 84 | + } |
| 85 | + }); |
| 86 | + test("should be able to show media in rooms globally", async ({ page, app, room, user }) => { |
| 87 | + const settings = await app.settings.openUserSettings("Preferences"); |
| 88 | + await settings.getByLabel("Show media in timeline").getByRole("radio", { name: "Always show" }).click(); |
| 89 | + await app.closeDialog(); |
| 90 | + await app.viewRoomById(room.roomId); |
| 91 | + await page.getByRole("button", { name: "Accept" }).click(); |
| 92 | + await expect(page.getByText("Show image")).not.toBeVisible(); |
| 93 | + }); |
| 94 | + test("should be able to hide media in an individual room", async ({ page, app, room, user }) => { |
| 95 | + const settings = await app.settings.openUserSettings("Preferences"); |
| 96 | + await settings.getByLabel("Show media in timeline").getByRole("radio", { name: "Always show" }).click(); |
| 97 | + await app.closeDialog(); |
| 98 | + |
| 99 | + await app.viewRoomById(room.roomId); |
| 100 | + await page.getByRole("button", { name: "Accept" }).click(); |
| 101 | + |
| 102 | + const roomSettings = await app.settings.openRoomSettings("General"); |
| 103 | + await roomSettings.getByLabel("Show media in timeline").getByRole("radio", { name: "Always hide" }).click(); |
| 104 | + await app.closeDialog(); |
| 105 | + |
| 106 | + await expect(page.getByText("Show image")).toBeVisible(); |
| 107 | + }); |
| 108 | + test("should be able to show media in an individual room", async ({ page, app, room, user }) => { |
| 109 | + const settings = await app.settings.openUserSettings("Preferences"); |
| 110 | + await settings.getByLabel("Show media in timeline").getByRole("radio", { name: "Always hide" }).click(); |
| 111 | + await app.closeDialog(); |
| 112 | + |
| 113 | + await app.viewRoomById(room.roomId); |
| 114 | + await page.getByRole("button", { name: "Accept" }).click(); |
| 115 | + |
| 116 | + const roomSettings = await app.settings.openRoomSettings("General"); |
| 117 | + await roomSettings.getByLabel("Show media in timeline").getByRole("radio", { name: "Always show" }).click(); |
| 118 | + await app.closeDialog(); |
| 119 | + |
| 120 | + await expect(page.getByText("Show image")).not.toBeVisible(); |
| 121 | + }); |
| 122 | +}); |
0 commit comments