|
| 1 | +/* |
| 2 | +Copyright 2024 The Matrix.org Foundation C.I.C. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +/* See readme.md for tips on writing these tests. */ |
| 18 | + |
| 19 | +import { Locator, Page } from "playwright-core"; |
| 20 | + |
| 21 | +import { test, expect } from "../../element-web-test"; |
| 22 | + |
| 23 | +async function sendMessage(page: Page, message: string): Promise<Locator> { |
| 24 | + await page.getByRole("textbox", { name: "Send a messageโฆ" }).fill(message); |
| 25 | + await page.getByRole("button", { name: "Send message" }).click(); |
| 26 | + |
| 27 | + const msgTile = await page.locator(".mx_EventTile_last"); |
| 28 | + await msgTile.locator(".mx_EventTile_receiptSent").waitFor(); |
| 29 | + return msgTile; |
| 30 | +} |
| 31 | + |
| 32 | +async function editMessage(page: Page, message: Locator, newMsg: string): Promise<void> { |
| 33 | + const line = message.locator(".mx_EventTile_line"); |
| 34 | + await line.hover(); |
| 35 | + await line.getByRole("button", { name: "Edit" }).click(); |
| 36 | + const editComposer = page.getByRole("textbox", { name: "Edit message" }); |
| 37 | + await page.getByLabel("User menu").hover(); // Just to un-hover the message line |
| 38 | + await editComposer.fill(newMsg); |
| 39 | + await editComposer.press("Enter"); |
| 40 | +} |
| 41 | + |
| 42 | +test.describe("Message rendering", () => { |
| 43 | + [ |
| 44 | + { direction: "ltr", displayName: "Quentin" }, |
| 45 | + { direction: "rtl", displayName: "ููููุชูู" }, |
| 46 | + ].forEach(({ direction, displayName }) => { |
| 47 | + test.describe(`with ${direction} display name`, () => { |
| 48 | + test.use({ |
| 49 | + displayName, |
| 50 | + room: async ({ user, app }, use) => { |
| 51 | + const roomId = await app.client.createRoom({ name: "Test room" }); |
| 52 | + await use({ roomId }); |
| 53 | + }, |
| 54 | + }); |
| 55 | + |
| 56 | + test("should render a basic LTR text message", async ({ page, user, app, room }) => { |
| 57 | + await page.goto(`#/room/${room.roomId}`); |
| 58 | + |
| 59 | + const msgTile = await sendMessage(page, "Hello, world!"); |
| 60 | + await expect(msgTile).toMatchScreenshot(`basic-message-ltr-${direction}displayname.png`, { |
| 61 | + mask: [page.locator(".mx_MessageTimestamp")], |
| 62 | + }); |
| 63 | + }); |
| 64 | + |
| 65 | + test("should render an LTR emote", async ({ page, user, app, room }) => { |
| 66 | + await page.goto(`#/room/${room.roomId}`); |
| 67 | + |
| 68 | + const msgTile = await sendMessage(page, "/me lays an egg"); |
| 69 | + await expect(msgTile).toMatchScreenshot(`emote-ltr-${direction}displayname.png`); |
| 70 | + }); |
| 71 | + |
| 72 | + test("should render an edited LTR message", async ({ page, user, app, room }) => { |
| 73 | + await page.goto(`#/room/${room.roomId}`); |
| 74 | + |
| 75 | + const msgTile = await sendMessage(page, "Hello, world!"); |
| 76 | + |
| 77 | + await editMessage(page, msgTile, "Hello, universe!"); |
| 78 | + |
| 79 | + await expect(msgTile).toMatchScreenshot(`edited-message-ltr-${direction}displayname.png`, { |
| 80 | + mask: [page.locator(".mx_MessageTimestamp")], |
| 81 | + }); |
| 82 | + }); |
| 83 | + |
| 84 | + test("should render a basic RTL text message", async ({ page, user, app, room }) => { |
| 85 | + await page.goto(`#/room/${room.roomId}`); |
| 86 | + |
| 87 | + const msgTile = await sendMessage(page, "ู
ุฑุญุจุง ุจุงูุนุงูู
!"); |
| 88 | + await expect(msgTile).toMatchScreenshot(`basic-message-rtl-${direction}displayname.png`, { |
| 89 | + mask: [page.locator(".mx_MessageTimestamp")], |
| 90 | + }); |
| 91 | + }); |
| 92 | + |
| 93 | + test("should render an RTL emote", async ({ page, user, app, room }) => { |
| 94 | + await page.goto(`#/room/${room.roomId}`); |
| 95 | + |
| 96 | + const msgTile = await sendMessage(page, "/me ูุถุน ุจูุถุฉ"); |
| 97 | + await expect(msgTile).toMatchScreenshot(`emote-rtl-${direction}displayname.png`); |
| 98 | + }); |
| 99 | + |
| 100 | + test("should render an edited RTL message", async ({ page, user, app, room }) => { |
| 101 | + await page.goto(`#/room/${room.roomId}`); |
| 102 | + |
| 103 | + const msgTile = await sendMessage(page, "ู
ุฑุญุจุง ุจุงูุนุงูู
!"); |
| 104 | + |
| 105 | + await editMessage(page, msgTile, "ู
ุฑุญุจุง ุจุงูููู!"); |
| 106 | + |
| 107 | + await expect(msgTile).toMatchScreenshot(`edited-message-rtl-${direction}displayname.png`, { |
| 108 | + mask: [page.locator(".mx_MessageTimestamp")], |
| 109 | + }); |
| 110 | + }); |
| 111 | + }); |
| 112 | + }); |
| 113 | +}); |
0 commit comments