playwright: Add togglePreview helper function

This adds a helper function that switches into preview.

Heavily inspired by and all credit due to `content-sources-playwright`.
This commit is contained in:
regexowl 2025-03-13 17:15:55 +01:00 committed by Klara Simickova
parent 01efb93ff6
commit cd5daade6b

View file

@ -1,4 +1,4 @@
import { type Page, type FrameLocator } from '@playwright/test';
import { type Page, type FrameLocator, expect } from '@playwright/test';
export const ibFrame = (page: Page): FrameLocator | Page => {
if (isHosted()) {
@ -9,6 +9,21 @@ export const ibFrame = (page: Page): FrameLocator | Page => {
.contentFrame();
};
export const togglePreview = async (page: Page) => {
const toggleSwitch = page.locator('#preview-toggle');
if (!(await toggleSwitch.isChecked())) {
await toggleSwitch.click();
}
const turnOnButton = page.getByRole('button', { name: 'Turn on' });
if (await turnOnButton.isVisible()) {
await turnOnButton.click();
}
await expect(toggleSwitch).toBeChecked();
};
export const login = async (page: Page) => {
if (!process.env.USER || !process.env.PASSWORD) {
throw new Error('user or password not set in environment');
@ -49,7 +64,7 @@ const loginConsole = async (page: Page, user: string, password: string) => {
await page.getByRole('textbox', { name: 'Password' }).fill(password);
await page.getByRole('button', { name: 'Log in' }).click();
await closePopupsIfExist(page);
await page.locator('#preview-toggle').check();
await togglePreview(page);
await page.getByRole('heading', { name: 'All images' });
};