Migrate knock/* from Cypress to Playwright (#12030)

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
Michael Telatynski 2023-12-12 14:08:36 +00:00 committed by GitHub
parent a806d71d45
commit e92ca4fcd2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 721 additions and 601 deletions

View file

@ -19,6 +19,7 @@ import { type Locator, type Page, expect } from "@playwright/test";
import { Settings } from "./settings";
import { Client } from "./client";
import { Labs } from "./labs";
import { Spotlight } from "./Spotlight";
export class ElementAppPage {
public constructor(public readonly page: Page) {}
@ -148,4 +149,10 @@ export class ElementAppPage {
public async getClipboardText(): Promise<string> {
return this.page.evaluate("navigator.clipboard.readText()");
}
public async openSpotlight(): Promise<Spotlight> {
const spotlight = new Spotlight(this.page);
await spotlight.open();
return spotlight;
}
}

View file

@ -0,0 +1,58 @@
/*
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 type { Locator, Page } from "@playwright/test";
import { CommandOrControl } from "../e2e/utils";
export enum Filter {
People = "people",
PublicRooms = "public_rooms",
}
export class Spotlight {
private root: Locator;
constructor(private page: Page) {}
public async open() {
await this.page.keyboard.press(`${CommandOrControl}+KeyK`);
this.root = this.page.locator('[role=dialog][aria-label="Search Dialog"]');
}
public async filter(filter: Filter) {
let selector: string;
switch (filter) {
case Filter.People:
selector = "#mx_SpotlightDialog_button_startChat";
break;
case Filter.PublicRooms:
selector = "#mx_SpotlightDialog_button_explorePublicRooms";
break;
default:
selector = ".mx_SpotlightDialog_filter";
break;
}
await this.root.locator(selector).click();
}
public async search(query: string) {
await this.root.locator(".mx_SpotlightDialog_searchBox").getByRole("textbox", { name: "Search" }).fill(query);
}
public get results() {
return this.root.locator(".mx_SpotlightDialog_section.mx_SpotlightDialog_results .mx_SpotlightDialog_option");
}
}

View file

@ -26,6 +26,8 @@ import type {
MatrixEvent,
ReceiptType,
IRoomDirectoryOptions,
KnockRoomOpts,
Visibility,
} from "matrix-js-sdk/src/matrix";
import { Credentials } from "../plugins/homeserver";
@ -215,6 +217,56 @@ export class Client {
});
}
/**
* Knocks the given room.
* @param roomId the id of the room to knock
* @param opts the options to use when knocking
*/
public async knockRoom(roomId: string, opts?: KnockRoomOpts): Promise<void> {
const client = await this.prepareClient();
await client.evaluate((client, { roomId, opts }) => client.knockRoom(roomId, opts), { roomId, opts });
}
/**
* Kicks the given user from the given room.
* @param roomId the id of the room to kick from
* @param userId the id of the user to kick
* @param reason the reason for the kick
*/
public async kick(roomId: string, userId: string, reason?: string): Promise<void> {
const client = await this.prepareClient();
await client.evaluate((client, { roomId, userId, reason }) => client.kick(roomId, userId, reason), {
roomId,
userId,
reason,
});
}
/**
* Bans the given user from the given room.
* @param roomId the id of the room to ban from
* @param userId the id of the user to ban
* @param reason the reason for the ban
*/
public async ban(roomId: string, userId: string, reason?: string): Promise<void> {
const client = await this.prepareClient();
await client.evaluate((client, { roomId, userId, reason }) => client.ban(roomId, userId, reason), {
roomId,
userId,
reason,
});
}
/**
* Unban the given user from the given room.
* @param roomId the id of the room to unban from
* @param userId the id of the user to unban
*/
public async unban(roomId: string, userId: string): Promise<void> {
const client = await this.prepareClient();
await client.evaluate((client, { roomId, userId }) => client.unban(roomId, userId), { roomId, userId });
}
/**
* @param {MatrixEvent} event
* @param {ReceiptType} receiptType
@ -261,4 +313,19 @@ export class Client {
});
}, credentials);
}
/**
* Sets the directory visibility for a room.
* @param roomId ID of the room to set the directory visibility for
* @param visibility The new visibility for the room
*/
public async setRoomDirectoryVisibility(roomId: string, visibility: Visibility): Promise<void> {
const client = await this.prepareClient();
return client.evaluate(
async (client, { roomId, visibility }) => {
await client.setRoomDirectoryVisibility(roomId, visibility);
},
{ roomId, visibility },
);
}
}