|
| 1 | +/* |
| 2 | +Copyright 2022 - 2023 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 | +import { test, expect } from "../../element-web-test"; |
| 18 | +import { SettingLevel } from "../../../src/settings/SettingLevel"; |
| 19 | + |
| 20 | +const CtrlOrMeta = process.platform === "darwin" ? "Meta" : "Control"; |
| 21 | + |
| 22 | +test.describe("Composer", () => { |
| 23 | + test.use({ |
| 24 | + displayName: "Janet", |
| 25 | + }); |
| 26 | + |
| 27 | + test.use({ |
| 28 | + room: async ({ app, user }, use) => { |
| 29 | + const roomId = await app.client.createRoom({ name: "Composing Room" }); |
| 30 | + await app.viewRoomByName("Composing Room"); |
| 31 | + await use({ roomId }); |
| 32 | + }, |
| 33 | + }); |
| 34 | + |
| 35 | + test.beforeEach(async ({ room }) => {}); // trigger room fixture |
| 36 | + |
| 37 | + test.describe("CIDER", () => { |
| 38 | + test("sends a message when you click send or press Enter", async ({ page }) => { |
| 39 | + const composer = page.getByRole("textbox", { name: "Send a message…" }); |
| 40 | + |
| 41 | + // Type a message |
| 42 | + await composer.pressSequentially("my message 0"); |
| 43 | + // It has not been sent yet |
| 44 | + await expect(page.locator(".mx_EventTile_body", { hasText: "my message 0" })).not.toBeVisible(); |
| 45 | + |
| 46 | + // Click send |
| 47 | + await page.getByRole("button", { name: "Send message" }).click(); |
| 48 | + // It has been sent |
| 49 | + await expect( |
| 50 | + page.locator(".mx_EventTile_last .mx_EventTile_body", { hasText: "my message 0" }), |
| 51 | + ).toBeVisible(); |
| 52 | + |
| 53 | + // Type another and press Enter afterward |
| 54 | + await composer.pressSequentially("my message 1"); |
| 55 | + await composer.press("Enter"); |
| 56 | + // It was sent |
| 57 | + await expect( |
| 58 | + page.locator(".mx_EventTile_last .mx_EventTile_body", { hasText: "my message 1" }), |
| 59 | + ).toBeVisible(); |
| 60 | + }); |
| 61 | + |
| 62 | + test("can write formatted text", async ({ page }) => { |
| 63 | + const composer = page.getByRole("textbox", { name: "Send a message…" }); |
| 64 | + |
| 65 | + await composer.pressSequentially("my bold"); |
| 66 | + await composer.press(`${CtrlOrMeta}+KeyB`); |
| 67 | + await composer.pressSequentially(" message"); |
| 68 | + await page.getByRole("button", { name: "Send message" }).click(); |
| 69 | + // Note: both "bold" and "message" are bold, which is probably surprising |
| 70 | + await expect(page.locator(".mx_EventTile_body strong", { hasText: "bold message" })).toBeVisible(); |
| 71 | + }); |
| 72 | + |
| 73 | + test("should allow user to input emoji via graphical picker", async ({ page, app }) => { |
| 74 | + await app.getComposer(false).getByRole("button", { name: "Emoji" }).click(); |
| 75 | + |
| 76 | + await page.getByTestId("mx_EmojiPicker").locator(".mx_EmojiPicker_item", { hasText: "😇" }).click(); |
| 77 | + |
| 78 | + await page.locator(".mx_ContextualMenu_background").click(); // Close emoji picker |
| 79 | + await page.getByRole("textbox", { name: "Send a message…" }).press("Enter"); // Send message |
| 80 | + |
| 81 | + await expect(page.locator(".mx_EventTile_body", { hasText: "😇" })).toBeVisible(); |
| 82 | + }); |
| 83 | + |
| 84 | + test.describe("when Control+Enter is required to send", () => { |
| 85 | + test.beforeEach(async ({ app }) => { |
| 86 | + await app.settings.setValue("MessageComposerInput.ctrlEnterToSend", null, SettingLevel.ACCOUNT, true); |
| 87 | + }); |
| 88 | + |
| 89 | + test("only sends when you press Control+Enter", async ({ page }) => { |
| 90 | + const composer = page.getByRole("textbox", { name: "Send a message…" }); |
| 91 | + // Type a message and press Enter |
| 92 | + await composer.pressSequentially("my message 3"); |
| 93 | + await composer.press("Enter"); |
| 94 | + // It has not been sent yet |
| 95 | + await expect(page.locator(".mx_EventTile_body", { hasText: "my message 3" })).not.toBeVisible(); |
| 96 | + |
| 97 | + // Press Control+Enter |
| 98 | + await composer.press(`${CtrlOrMeta}+Enter`); |
| 99 | + // It was sent |
| 100 | + await expect( |
| 101 | + page.locator(".mx_EventTile_last .mx_EventTile_body", { hasText: "my message 3" }), |
| 102 | + ).toBeVisible(); |
| 103 | + }); |
| 104 | + }); |
| 105 | + }); |
| 106 | +}); |
0 commit comments