2023-11-27 15:11:00 +03:00
|
|
|
/*
|
2024-09-09 16:57:16 +03:00
|
|
|
Copyright 2024 New Vector Ltd.
|
2023-11-27 15:11:00 +03:00
|
|
|
Copyright 2023 The Matrix.org Foundation C.I.C.
|
|
|
|
|
2024-09-09 16:57:16 +03:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only
|
|
|
|
Please see LICENSE files in the repository root for full details.
|
2023-11-27 15:11:00 +03:00
|
|
|
*/
|
|
|
|
|
2023-12-01 15:24:49 +03:00
|
|
|
import { type Locator, type Page, expect } from "@playwright/test";
|
2023-11-28 16:52:09 +03:00
|
|
|
|
2023-11-29 16:50:13 +03:00
|
|
|
import { Settings } from "./settings";
|
2023-11-30 13:18:18 +03:00
|
|
|
import { Client } from "./client";
|
2023-12-19 11:36:54 +03:00
|
|
|
import { Timeline } from "./timeline";
|
2023-12-12 17:08:36 +03:00
|
|
|
import { Spotlight } from "./Spotlight";
|
2023-11-27 15:11:00 +03:00
|
|
|
|
2024-04-03 13:02:41 +03:00
|
|
|
/**
|
|
|
|
* A set of utility methods for interacting with the Element-Web UI.
|
|
|
|
*/
|
2023-11-27 15:11:00 +03:00
|
|
|
export class ElementAppPage {
|
2023-12-12 11:55:29 +03:00
|
|
|
public constructor(public readonly page: Page) {}
|
2023-11-27 15:11:00 +03:00
|
|
|
|
2024-02-19 20:26:32 +03:00
|
|
|
// We create these lazily on first access to avoid calling setup code which might cause conflicts,
|
|
|
|
// e.g. the network routing code in the client subfixture.
|
|
|
|
private _settings?: Settings;
|
|
|
|
public get settings(): Settings {
|
|
|
|
if (!this._settings) this._settings = new Settings(this.page);
|
|
|
|
return this._settings;
|
|
|
|
}
|
|
|
|
private _client?: Client;
|
|
|
|
public get client(): Client {
|
|
|
|
if (!this._client) this._client = new Client(this.page);
|
|
|
|
return this._client;
|
|
|
|
}
|
|
|
|
private _timeline?: Timeline;
|
|
|
|
public get timeline(): Timeline {
|
|
|
|
if (!this._timeline) this._timeline = new Timeline(this.page);
|
|
|
|
return this._timeline;
|
|
|
|
}
|
2023-11-28 16:52:09 +03:00
|
|
|
|
2023-11-27 15:11:00 +03:00
|
|
|
/**
|
|
|
|
* Open the top left user menu, returning a Locator to the resulting context menu.
|
|
|
|
*/
|
|
|
|
public async openUserMenu(): Promise<Locator> {
|
2023-11-29 16:50:13 +03:00
|
|
|
return this.settings.openUserMenu();
|
2023-11-27 15:11:00 +03:00
|
|
|
}
|
|
|
|
|
2023-11-27 19:24:02 +03:00
|
|
|
/**
|
|
|
|
* Open room creation dialog.
|
|
|
|
*/
|
|
|
|
public async openCreateRoomDialog(): Promise<Locator> {
|
|
|
|
await this.page.getByRole("button", { name: "Add room", exact: true }).click();
|
|
|
|
await this.page.getByRole("menuitem", { name: "New room", exact: true }).click();
|
|
|
|
return this.page.locator(".mx_CreateRoomDialog");
|
|
|
|
}
|
|
|
|
|
2023-11-28 03:37:20 +03:00
|
|
|
/**
|
|
|
|
* Close dialog currently open dialog
|
|
|
|
*/
|
|
|
|
public async closeDialog(): Promise<void> {
|
2023-11-29 16:50:13 +03:00
|
|
|
return this.settings.closeDialog();
|
2023-11-28 03:37:20 +03:00
|
|
|
}
|
|
|
|
|
2024-01-10 13:34:03 +03:00
|
|
|
public async getClipboard(): Promise<string> {
|
|
|
|
return await this.page.evaluate(() => navigator.clipboard.readText());
|
|
|
|
}
|
|
|
|
|
2023-11-29 16:50:13 +03:00
|
|
|
/**
|
|
|
|
* Opens the given room by name. The room must be visible in the
|
|
|
|
* room list, but the room list may be folded horizontally, and the
|
|
|
|
* room may contain unread messages.
|
|
|
|
*
|
|
|
|
* @param name The exact room name to find and click on/open.
|
|
|
|
*/
|
|
|
|
public async viewRoomByName(name: string): Promise<void> {
|
|
|
|
// We look for the room inside the room list, which is a tree called Rooms.
|
|
|
|
//
|
|
|
|
// There are 3 cases:
|
|
|
|
// - the room list is folded:
|
|
|
|
// then the aria-label on the room tile is the name (with nothing extra)
|
|
|
|
// - the room list is unfolder and the room has messages:
|
|
|
|
// then the aria-label contains the unread count, but the title of the
|
|
|
|
// div inside the titleContainer equals the room name
|
|
|
|
// - the room list is unfolded and the room has no messages:
|
|
|
|
// then the aria-label is the name and so is the title of a div
|
|
|
|
//
|
|
|
|
// So by matching EITHER title=name OR aria-label=name we find this exact
|
|
|
|
// room in all three cases.
|
|
|
|
return this.page
|
|
|
|
.getByRole("tree", { name: "Rooms" })
|
|
|
|
.locator(`[title="${name}"],[aria-label="${name}"]`)
|
|
|
|
.first()
|
|
|
|
.click();
|
|
|
|
}
|
|
|
|
|
2023-12-12 11:55:29 +03:00
|
|
|
public async viewRoomById(roomId: string): Promise<void> {
|
|
|
|
await this.page.goto(`/#/room/${roomId}`);
|
|
|
|
}
|
|
|
|
|
2023-11-28 03:37:20 +03:00
|
|
|
/**
|
|
|
|
* Get the composer element
|
|
|
|
* @param isRightPanel whether to select the right panel composer, otherwise the main timeline composer
|
|
|
|
*/
|
2023-12-04 15:01:06 +03:00
|
|
|
public getComposer(isRightPanel?: boolean): Locator {
|
2023-11-28 03:37:20 +03:00
|
|
|
const panelClass = isRightPanel ? ".mx_RightPanel" : ".mx_RoomView_body";
|
|
|
|
return this.page.locator(`${panelClass} .mx_MessageComposer`);
|
|
|
|
}
|
|
|
|
|
2023-12-13 17:59:08 +03:00
|
|
|
/**
|
|
|
|
* Get the composer input field
|
|
|
|
* @param isRightPanel whether to select the right panel composer, otherwise the main timeline composer
|
|
|
|
*/
|
|
|
|
public getComposerField(isRightPanel?: boolean): Locator {
|
|
|
|
return this.getComposer(isRightPanel).locator("[contenteditable]");
|
|
|
|
}
|
|
|
|
|
2023-11-28 03:37:20 +03:00
|
|
|
/**
|
|
|
|
* Open the message composer kebab menu
|
|
|
|
* @param isRightPanel whether to select the right panel composer, otherwise the main timeline composer
|
|
|
|
*/
|
|
|
|
public async openMessageComposerOptions(isRightPanel?: boolean): Promise<Locator> {
|
2023-12-04 15:01:06 +03:00
|
|
|
const composer = this.getComposer(isRightPanel);
|
2023-11-28 03:37:20 +03:00
|
|
|
await composer.getByRole("button", { name: "More options", exact: true }).click();
|
|
|
|
return this.page.getByRole("menu");
|
|
|
|
}
|
2023-12-01 15:24:49 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the space panel space button based on a name. The space
|
|
|
|
* must be visible in the space panel
|
|
|
|
* @param name The space name to find
|
|
|
|
*/
|
|
|
|
public async getSpacePanelButton(name: string): Promise<Locator> {
|
|
|
|
const button = this.page.getByRole("button", { name: name });
|
|
|
|
await expect(button).toHaveClass(/mx_SpaceButton/);
|
|
|
|
return button;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Opens the given space home by name. The space must be visible in
|
|
|
|
* the space list.
|
|
|
|
* @param name The space name to find and click on/open.
|
|
|
|
*/
|
|
|
|
public async viewSpaceHomeByName(name: string): Promise<void> {
|
|
|
|
const button = await this.getSpacePanelButton(name);
|
|
|
|
return button.dblclick();
|
|
|
|
}
|
2023-12-04 14:56:48 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Opens the given space by name. The space must be visible in the
|
|
|
|
* space list.
|
|
|
|
* @param name The space name to find and click on/open.
|
|
|
|
*/
|
|
|
|
public async viewSpaceByName(name: string): Promise<void> {
|
|
|
|
const button = await this.getSpacePanelButton(name);
|
|
|
|
return button.click();
|
|
|
|
}
|
|
|
|
|
|
|
|
public async getClipboardText(): Promise<string> {
|
|
|
|
return this.page.evaluate("navigator.clipboard.readText()");
|
|
|
|
}
|
2023-12-12 17:08:36 +03:00
|
|
|
|
|
|
|
public async openSpotlight(): Promise<Spotlight> {
|
|
|
|
const spotlight = new Spotlight(this.page);
|
|
|
|
await spotlight.open();
|
|
|
|
return spotlight;
|
|
|
|
}
|
2024-07-23 13:56:25 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Opens/closes the room info panel
|
|
|
|
* @returns locator to the right panel
|
|
|
|
*/
|
|
|
|
public async toggleRoomInfoPanel(): Promise<Locator> {
|
|
|
|
await this.page.getByRole("button", { name: "Room info" }).first().click();
|
|
|
|
return this.page.locator(".mx_RightPanel");
|
|
|
|
}
|
2024-10-14 19:11:58 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a locator for the tooltip associated with an element
|
|
|
|
* @param e The element with the tooltip
|
|
|
|
* @returns Locator to the tooltip
|
|
|
|
*/
|
|
|
|
public async getTooltipForElement(e: Locator): Promise<Locator> {
|
|
|
|
const [labelledById, describedById] = await Promise.all([
|
|
|
|
e.getAttribute("aria-labelledby"),
|
|
|
|
e.getAttribute("aria-describedby"),
|
|
|
|
]);
|
|
|
|
if (!labelledById && !describedById) {
|
|
|
|
throw new Error(
|
|
|
|
"Element has no aria-labelledby or aria-describedy attributes! The tooltip should have added either one of these.",
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return this.page.locator(`#${labelledById ?? describedById}`);
|
|
|
|
}
|
2023-11-27 15:11:00 +03:00
|
|
|
}
|