From b0df4175e6e595a2fc7f2e286a007089077a3e8d Mon Sep 17 00:00:00 2001 From: RMidhunSuresh Date: Fri, 18 Aug 2023 23:13:55 +0530 Subject: [PATCH] Write tests for invite --- playwright/tests/invite.spec.ts | 86 +++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 playwright/tests/invite.spec.ts diff --git a/playwright/tests/invite.spec.ts b/playwright/tests/invite.spec.ts new file mode 100644 index 00000000..90648bf4 --- /dev/null +++ b/playwright/tests/invite.spec.ts @@ -0,0 +1,86 @@ +/* +Copyright 2023 The Matrix.org Foundation C.I.C. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ +import {test} from '@playwright/test'; +import {synapseStart, synapseStop, registerUser} from "../plugins/synapsedocker"; +import type {SynapseInstance} from "../plugins/synapsedocker"; + +test.describe("Login", () => { + let synapse: SynapseInstance; + + test.beforeEach(async () => { + synapse = await synapseStart("default"); + }); + + test.afterEach(async () => { + await synapseStop(synapse.synapseId); + }); + + test("Invite user using /invite command from composer", async ({ page }) => { + const user1 = ["foobaraccount", "password123"] as const; + const user2 = ["foobaraccount2", "password123"] as const; + await registerUser(synapse, ...user1); + const { userId } = await registerUser(synapse, ...user2); + await page.goto("/"); + await page.locator("#homeserver").fill(""); + await page.locator("#homeserver").type(synapse.baseUrl); + const [username, password] = user1; + await page.locator("#username").type(username); + await page.locator("#password").type(password); + await page.getByText("Log In", { exact: true }).click(); + await page.locator(".SessionView").waitFor(); + // Create the room + await page.getByLabel("Create room").click(); + await page.getByText("Create Room").click(); + await page.locator("#name").type("My Room"); + await page.locator(".CreateRoomView_detailsForm") + .getByRole("button", { name: "Create room" }) + .click(); + await page.locator(".RoomList") + .locator("li") + .first() + .click(); + await page.locator(".MessageComposer_input textarea").type(`/invite ${userId}`); + await page.keyboard.press("Enter"); + await page.locator(".AnnouncementView").last().getByText("was invited to the room").waitFor(); + }); + + test("Error is shown when using /invite command from composer", async ({ page }) => { + const user1 = ["foobaraccount", "password123"] as const; + await registerUser(synapse, ...user1); + await page.goto("/"); + await page.locator("#homeserver").fill(""); + await page.locator("#homeserver").type(synapse.baseUrl); + const [username, password] = user1; + await page.locator("#username").type(username); + await page.locator("#password").type(password); + await page.getByText("Log In", { exact: true }).click(); + await page.locator(".SessionView").waitFor(); + // Create the room + await page.getByLabel("Create room").click(); + await page.getByText("Create Room").click(); + await page.locator("#name").type("My Room"); + await page.locator(".CreateRoomView_detailsForm") + .getByRole("button", { name: "Create room" }) + .click(); + await page.locator(".RoomList") + .locator("li") + .first() + .click(); + await page.locator(".MessageComposer_input textarea").type("/invite foobar"); + await page.keyboard.press("Enter"); + await page.locator(".RoomView").locator(".ErrorView").waitFor(); + }); +});