2024-02-29 14:32:37 +01:00
|
|
|
import { test, Page, expect } from '@playwright/test';
|
2024-02-06 12:26:06 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Execute a test suite only if the condition is true
|
|
|
|
*/
|
|
|
|
export const describeOnCondition = (shouldDescribe: boolean) =>
|
|
|
|
shouldDescribe ? test.describe : test.describe.skip;
|
2024-02-29 14:32:37 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Navigate to a page and confirm the header, awaiting each step
|
|
|
|
*/
|
|
|
|
export const navToHeader = async (page: Page, navItems: string[], headerText: string) => {
|
|
|
|
for (const navItem of navItems) {
|
|
|
|
// This does not use getByRole because sometimes "Settings" is "Settings 1" if there's a badge notification
|
|
|
|
// BUT if we don't match exact it conflicts with "Advanceed Settings"
|
|
|
|
// As a workaround, we implement our own startsWith with page.locator
|
|
|
|
const item = page.locator(`role=link[name^="${navItem}"]`);
|
|
|
|
await expect(item).toBeVisible();
|
|
|
|
await item.click();
|
|
|
|
}
|
|
|
|
|
|
|
|
const header = page.getByRole('heading', { name: headerText, exact: true });
|
|
|
|
await expect(header).toBeVisible();
|
|
|
|
return header;
|
|
|
|
};
|