|
| 1 | +/* |
| 2 | +Copyright 2025 New Vector Ltd. |
| 3 | +
|
| 4 | +SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial |
| 5 | +Please see LICENSE in the repository root for full details. |
| 6 | +*/ |
| 7 | + |
| 8 | +import { type Page, test, expect, type JSHandle } from "@playwright/test"; |
| 9 | + |
| 10 | +import type { MatrixClient } from "matrix-js-sdk/src"; |
| 11 | + |
| 12 | +export type UserBaseFixture = { |
| 13 | + mxId: string; |
| 14 | + page: Page; |
| 15 | + clientHandle: JSHandle<MatrixClient>; |
| 16 | +}; |
| 17 | + |
| 18 | +export type BaseWidgetSetup = { |
| 19 | + brooks: UserBaseFixture; |
| 20 | + whistler: UserBaseFixture; |
| 21 | +}; |
| 22 | + |
| 23 | +export interface MyFixtures { |
| 24 | + asWidget: BaseWidgetSetup; |
| 25 | +} |
| 26 | + |
| 27 | +const PASSWORD = "foobarbaz1!"; |
| 28 | + |
| 29 | +// Minimal config.json for the local element-web instance |
| 30 | +const CONFIG_JSON = { |
| 31 | + default_server_config: { |
| 32 | + "m.homeserver": { |
| 33 | + base_url: "http://synapse.localhost:8008", |
| 34 | + server_name: "synapse.localhost", |
| 35 | + }, |
| 36 | + }, |
| 37 | + |
| 38 | + element_call: { |
| 39 | + url: "https://localhost:3000", |
| 40 | + participant_limit: 8, |
| 41 | + brand: "Element Call", |
| 42 | + }, |
| 43 | + |
| 44 | + // The default language is set here for test consistency |
| 45 | + setting_defaults: { |
| 46 | + language: "en-GB", |
| 47 | + feature_group_calls: true, |
| 48 | + }, |
| 49 | + |
| 50 | + // the location tests want a map style url. |
| 51 | + map_style_url: |
| 52 | + "https://api.maptiler.com/maps/streets/style.json?key=fU3vlMsMn4Jb6dnEIFsx", |
| 53 | + |
| 54 | + features: { |
| 55 | + // We don't want to go through the feature announcement during the e2e test |
| 56 | + feature_release_announcement: false, |
| 57 | + feature_element_call_video_rooms: true, |
| 58 | + feature_video_rooms: true, |
| 59 | + feature_group_calls: true, |
| 60 | + }, |
| 61 | +}; |
| 62 | + |
| 63 | +export const widgetTest = test.extend<MyFixtures>({ |
| 64 | + asWidget: async ({ browser, context }, pUse) => { |
| 65 | + await context.route(`http://localhost:8081/config.json*`, async (route) => { |
| 66 | + await route.fulfill({ json: CONFIG_JSON }); |
| 67 | + }); |
| 68 | + |
| 69 | + const userA = `brooks_${Date.now()}`; |
| 70 | + const userB = `whistler_${Date.now()}`; |
| 71 | + |
| 72 | + const user1Context = await browser.newContext({ |
| 73 | + reducedMotion: "reduce", |
| 74 | + }); |
| 75 | + const ewPage1 = await user1Context.newPage(); |
| 76 | + // Register the first user |
| 77 | + await ewPage1.goto("http://localhost:8081/#/welcome"); |
| 78 | + await ewPage1.getByRole("link", { name: "Create Account" }).click(); |
| 79 | + await ewPage1.getByRole("textbox", { name: "Username" }).fill(userA); |
| 80 | + await ewPage1 |
| 81 | + .getByRole("textbox", { name: "Password", exact: true }) |
| 82 | + .fill(PASSWORD); |
| 83 | + await ewPage1.getByRole("textbox", { name: "Confirm password" }).click(); |
| 84 | + await ewPage1 |
| 85 | + .getByRole("textbox", { name: "Confirm password" }) |
| 86 | + .fill(PASSWORD); |
| 87 | + await ewPage1.getByRole("button", { name: "Register" }).click(); |
| 88 | + await expect( |
| 89 | + ewPage1.getByRole("heading", { name: `Welcome ${userA}` }), |
| 90 | + ).toBeVisible(); |
| 91 | + |
| 92 | + const brooksClientHandle = await ewPage1.evaluateHandle(() => |
| 93 | + window.mxMatrixClientPeg.get(), |
| 94 | + ); |
| 95 | + const brooksMxId = (await brooksClientHandle.evaluate((cli) => { |
| 96 | + return cli.getUserId(); |
| 97 | + }, brooksClientHandle))!; |
| 98 | + |
| 99 | + const user2Context = await browser.newContext({ |
| 100 | + reducedMotion: "reduce", |
| 101 | + }); |
| 102 | + const ewPage2 = await user2Context.newPage(); |
| 103 | + // Register the second user |
| 104 | + await ewPage2.goto("http://localhost:8081/#/welcome"); |
| 105 | + await ewPage2.getByRole("link", { name: "Create Account" }).click(); |
| 106 | + await ewPage2.getByRole("textbox", { name: "Username" }).fill(userB); |
| 107 | + await ewPage2 |
| 108 | + .getByRole("textbox", { name: "Password", exact: true }) |
| 109 | + .fill(PASSWORD); |
| 110 | + await ewPage2.getByRole("textbox", { name: "Confirm password" }).click(); |
| 111 | + await ewPage2 |
| 112 | + .getByRole("textbox", { name: "Confirm password" }) |
| 113 | + .fill(PASSWORD); |
| 114 | + await ewPage2.getByRole("button", { name: "Register" }).click(); |
| 115 | + await expect( |
| 116 | + ewPage2.getByRole("heading", { name: `Welcome ${userB}` }), |
| 117 | + ).toBeVisible(); |
| 118 | + |
| 119 | + const whistlerClientHandle = await ewPage2.evaluateHandle(() => |
| 120 | + window.mxMatrixClientPeg.get(), |
| 121 | + ); |
| 122 | + const whistlerMxId = (await whistlerClientHandle.evaluate((cli) => { |
| 123 | + return cli.getUserId(); |
| 124 | + }, whistlerClientHandle))!; |
| 125 | + |
| 126 | + // Invite the second user |
| 127 | + await ewPage1.getByRole("button", { name: "Add room" }).click(); |
| 128 | + await ewPage1.getByText("New room").click(); |
| 129 | + await ewPage1.getByRole("textbox", { name: "Name" }).fill("Welcome Room"); |
| 130 | + await ewPage1.getByRole("button", { name: "Create room" }).click(); |
| 131 | + await expect(ewPage1.getByText("You created this room.")).toBeVisible(); |
| 132 | + await expect(ewPage1.getByText("Encryption enabled")).toBeVisible(); |
| 133 | + |
| 134 | + await ewPage1 |
| 135 | + .getByRole("button", { name: "Invite to this room", exact: true }) |
| 136 | + .click(); |
| 137 | + await expect( |
| 138 | + ewPage1.getByRole("heading", { name: "Invite to Welcome Room" }), |
| 139 | + ).toBeVisible(); |
| 140 | + |
| 141 | + await ewPage1.getByRole("textbox").fill(whistlerMxId); |
| 142 | + await ewPage1.getByRole("textbox").click(); |
| 143 | + await ewPage1.getByRole("button", { name: "Invite" }).click(); |
| 144 | + |
| 145 | + // Accept the invite |
| 146 | + await expect( |
| 147 | + ewPage2.getByRole("treeitem", { name: "Welcome Room" }), |
| 148 | + ).toBeVisible(); |
| 149 | + await ewPage2.getByRole("treeitem", { name: "Welcome Room" }).click(); |
| 150 | + await ewPage2.getByRole("button", { name: "Accept" }).click(); |
| 151 | + await expect( |
| 152 | + ewPage2.getByRole("main").getByRole("heading", { name: "Welcome Room" }), |
| 153 | + ).toBeVisible(); |
| 154 | + |
| 155 | + // Renamed use to pUse, as a workaround for eslint error that was thinking this use was a react use. |
| 156 | + await pUse({ |
| 157 | + brooks: { |
| 158 | + mxId: brooksMxId, |
| 159 | + page: ewPage1, |
| 160 | + clientHandle: brooksClientHandle, |
| 161 | + }, |
| 162 | + whistler: { |
| 163 | + mxId: whistlerMxId, |
| 164 | + page: ewPage2, |
| 165 | + clientHandle: whistlerClientHandle, |
| 166 | + }, |
| 167 | + }); |
| 168 | + }, |
| 169 | +}); |
0 commit comments