2024-05-31 13:28:42 +03:00
|
|
|
import { expect, type Page } from '@playwright/test';
|
2023-09-02 06:31:07 +03:00
|
|
|
|
2024-08-12 06:56:56 +03:00
|
|
|
export function locateModeSwitchButton(
|
|
|
|
page: Page,
|
|
|
|
mode: 'page' | 'edgeless',
|
|
|
|
active?: boolean
|
|
|
|
) {
|
|
|
|
// switch is implemented as RadioGroup button,
|
|
|
|
// so we can use aria-checked to determine the active state
|
|
|
|
const checkedSelector = active ? '[aria-checked="true"]' : '';
|
|
|
|
|
|
|
|
return page.locator(
|
|
|
|
`[data-testid="switch-${mode}-mode-button"]${checkedSelector}`
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-09-02 06:31:07 +03:00
|
|
|
export async function clickEdgelessModeButton(page: Page) {
|
2024-08-12 06:56:56 +03:00
|
|
|
await locateModeSwitchButton(page, 'edgeless').click({ delay: 50 });
|
|
|
|
await ensureInEdgelessMode(page);
|
2023-09-02 06:31:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function clickPageModeButton(page: Page) {
|
2024-08-12 06:56:56 +03:00
|
|
|
await locateModeSwitchButton(page, 'page').click({ delay: 50 });
|
|
|
|
await ensureInPageMode(page);
|
2023-09-02 06:31:07 +03:00
|
|
|
}
|
2024-07-25 15:21:21 +03:00
|
|
|
|
|
|
|
export async function ensureInPageMode(page: Page) {
|
2024-08-12 06:56:56 +03:00
|
|
|
await expect(locateModeSwitchButton(page, 'page', true)).toBeVisible();
|
2024-07-25 15:21:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function ensureInEdgelessMode(page: Page) {
|
2024-08-12 06:56:56 +03:00
|
|
|
await expect(locateModeSwitchButton(page, 'edgeless', true)).toBeVisible();
|
2024-07-25 15:21:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function getPageMode(page: Page): Promise<'page' | 'edgeless'> {
|
2024-08-12 06:56:56 +03:00
|
|
|
if (await locateModeSwitchButton(page, 'page', true).isVisible()) {
|
2024-07-25 15:21:21 +03:00
|
|
|
return 'page';
|
|
|
|
}
|
2024-08-12 06:56:56 +03:00
|
|
|
if (await locateModeSwitchButton(page, 'edgeless', true).isVisible()) {
|
2024-07-25 15:21:21 +03:00
|
|
|
return 'edgeless';
|
|
|
|
}
|
|
|
|
throw new Error('Unknown mode');
|
|
|
|
}
|