文件
hyb-oa/client/tests/e2e/helpers/navigation.ts
T

25 行
835 B
TypeScript

import { expect, type Locator, type Page } from "@playwright/test";
export async function openBackupModulesIfNeeded(page: Page) {
const summary = page.locator("summary").filter({ hasText: "备用模块" }).first();
if (await summary.count()) {
const details = summary.locator("xpath=ancestor::details[1]");
const isOpen = await details.evaluate((node) => (node as HTMLDetailsElement).open);
if (!isOpen) {
await summary.click();
await expect(details).toHaveAttribute("open", "");
}
}
}
export async function openNavLink(page: Page, name: string | RegExp): Promise<Locator> {
const link = page.getByRole("link", { name }).first();
if (await link.isVisible().catch(() => false)) {
return link;
}
await openBackupModulesIfNeeded(page);
await expect(link).toBeVisible();
return link;
}