element-web-Github/playwright/pages/toasts.ts
Michael Telatynski b0392b8fc3
Update toast styles to match Figma (#12833)
* Warn users on unsupported browsers before they lack features

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

* Update Learn more link

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

* Iterate

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

* Iterate

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

* Update toast styles to match Figma

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

* Remove test code

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

* update tests

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

* Update tests

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

* Update snapshots

---------

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
2024-07-30 12:57:15 +00:00

61 lines
2.1 KiB
TypeScript

/*
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 { Page, expect, Locator } from "@playwright/test";
export class Toasts {
public constructor(private readonly page: Page) {}
/**
* Assert that a toast with the given title exists, and return it
*
* @param expectedTitle - Expected title of the toast
* @returns the Locator for the matching toast
*/
public async getToast(expectedTitle: string): Promise<Locator> {
const toast = this.page.locator(".mx_Toast_toast", { hasText: expectedTitle }).first();
await expect(toast).toBeVisible();
return toast;
}
/**
* Assert that no toasts exist
*/
public async assertNoToasts(): Promise<void> {
await expect(this.page.locator(".mx_Toast_toast")).not.toBeVisible();
}
/**
* Accept a toast with the given title, only works for the first toast in the stack
*
* @param expectedTitle - Expected title of the toast
*/
public async acceptToast(expectedTitle: string): Promise<void> {
const toast = await this.getToast(expectedTitle);
await toast.locator('.mx_Toast_buttons button[data-kind="primary"]').click();
}
/**
* Reject a toast with the given title, only works for the first toast in the stack
*
* @param expectedTitle - Expected title of the toast
*/
public async rejectToast(expectedTitle: string): Promise<void> {
const toast = await this.getToast(expectedTitle);
await toast.locator('.mx_Toast_buttons button[data-kind="secondary"]').click();
}
}