73 行
2.3 KiB
TypeScript
73 行
2.3 KiB
TypeScript
import { expect, type Page } from "@playwright/test";
|
|
|
|
export type WecomEntryConfig = {
|
|
enabled: boolean;
|
|
entryEnabled: boolean;
|
|
oauthEnabled: boolean;
|
|
corpId: string;
|
|
agentId: string;
|
|
loginUrl: string | null;
|
|
bindEnabled: boolean;
|
|
defaultReturnTo: string;
|
|
status: string;
|
|
statusReasons: string[];
|
|
};
|
|
|
|
type Envelope<T> = {
|
|
data: T;
|
|
error?: {
|
|
code?: string;
|
|
message?: string;
|
|
};
|
|
};
|
|
|
|
export async function assertPortalLoaded(page: Page) {
|
|
await expect(page).toHaveURL(/\/portal/);
|
|
await expect(page.getByRole("link", { name: "Portal" }).first()).toBeVisible();
|
|
await expect(page.locator('[aria-label^="portal-card-"]').first()).toBeVisible();
|
|
}
|
|
|
|
export async function assertForbiddenPage(page: Page) {
|
|
await expect(page).toHaveURL(/\/403/);
|
|
await expect(page.getByRole("heading", { name: "无权限访问", exact: true })).toBeVisible();
|
|
}
|
|
|
|
export async function assertMainNavVisible(page: Page) {
|
|
await expect(page.getByRole("link", { name: "Portal" }).first()).toBeVisible();
|
|
await expect(page.getByRole("link", { name: "团队" }).first()).toBeVisible();
|
|
await expect(page.getByRole("link", { name: "项目" }).first()).toBeVisible();
|
|
}
|
|
|
|
export async function assertBackupModulesCollapsed(page: Page) {
|
|
const summary = page.locator("summary").filter({ hasText: "备用模块" }).first();
|
|
await expect(summary).toBeVisible();
|
|
const details = summary.locator("xpath=ancestor::details[1]");
|
|
const isOpen = await details.evaluate((node) => (node as HTMLDetailsElement).open);
|
|
expect(isOpen).toBe(false);
|
|
await expect(page.getByRole("link", { name: "采购申请" })).not.toBeVisible();
|
|
}
|
|
|
|
export async function assertWecomBindingCardVisible(page: Page) {
|
|
await expect(page.getByRole("heading", { name: "企业微信绑定" })).toBeVisible();
|
|
await expect(page.getByText("接入状态", { exact: true })).toBeVisible();
|
|
}
|
|
|
|
export async function fetchWecomConfig(page: Page) {
|
|
const response = await page.request.get("/api/auth/wecom/config");
|
|
const text = await response.text();
|
|
let parsed: Envelope<WecomEntryConfig> | null = null;
|
|
|
|
try {
|
|
parsed = text ? JSON.parse(text) as Envelope<WecomEntryConfig> : null;
|
|
} catch {
|
|
parsed = null;
|
|
}
|
|
|
|
return {
|
|
status: response.status(),
|
|
ok: response.ok(),
|
|
body: text,
|
|
data: parsed?.data ?? null,
|
|
};
|
|
}
|