R28-1 R28-4: 收口网页门禁与公网 smoke

这个提交包含在:
2026-03-23 09:59:54 +08:00
父节点 7e183c0cdc
当前提交 c17a72830c
共修改 10 个文件,包含 456 行新增和 63 行删除
+72
查看文件
@@ -0,0 +1,72 @@
import { expect, type Page } from "@playwright/test";
import { logout } from "./auth";
export type LiveSmokeRole = "admin" | "employee";
export type LiveSmokeUser = {
role: LiveSmokeRole;
identifier: string;
password: string;
name: string;
};
function requireEnv(key: string) {
const value = process.env[key]?.trim();
if (!value) {
throw new Error(`缺少 live smoke 环境变量:${key}`);
}
return value;
}
export function getExpectedWecomStatus() {
return process.env.LIVE_EXPECT_WECOM_STATUS?.trim() || "disabled";
}
export function getLiveSmokeUser(role: LiveSmokeRole) {
if (role === "admin") {
return {
role,
identifier: requireEnv("LIVE_SMOKE_ADMIN_IDENTIFIER"),
password: requireEnv("LIVE_SMOKE_ADMIN_PASSWORD"),
};
}
return {
role,
identifier: requireEnv("LIVE_SMOKE_EMPLOYEE_IDENTIFIER"),
password: requireEnv("LIVE_SMOKE_EMPLOYEE_PASSWORD"),
};
}
async function readCurrentUserName(page: Page): Promise<string> {
const profileTrigger = page.getByTestId("topbar-profile-trigger").first();
await expect(profileTrigger).toBeVisible();
const name = (await profileTrigger.textContent())?.trim();
if (!name) {
throw new Error("无法从顶栏读取当前登录用户名称");
}
return name;
}
export async function loginLiveUser(page: Page, role: LiveSmokeRole): Promise<LiveSmokeUser> {
const credentials = getLiveSmokeUser(role);
await page.goto("/login");
await expect(page.getByTestId("login-identifier")).toBeVisible();
await page.getByTestId("login-identifier").fill(credentials.identifier);
await page.getByTestId("login-password").fill(credentials.password);
await page.getByTestId("login-submit").click();
await expect(page).toHaveURL(/\/portal/);
const name = await readCurrentUserName(page);
return {
...credentials,
name,
};
}
export async function logoutLiveUser(page: Page, user?: Pick<LiveSmokeUser, "name">) {
await logout(page, user?.name);
}
@@ -0,0 +1,67 @@
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("heading", { name: "Portal" })).toBeVisible();
await expect(page.getByRole("link", { name: "Portal" }).first()).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,
};
}