优化PC核心工作流视觉 Wave2(05-27-pc-core-workflow-visual-wave2)
这个提交包含在:
@@ -0,0 +1,331 @@
|
||||
import { mkdirSync } from "node:fs";
|
||||
import path from "node:path";
|
||||
import type { Page, Route } from "@playwright/test";
|
||||
|
||||
import { test, expect } from "./helpers/fixtures";
|
||||
|
||||
test.use({ serviceWorkers: "block" });
|
||||
|
||||
const visualUser = {
|
||||
identifier: "[email protected]",
|
||||
password: "VisualPassword1234",
|
||||
name: "Visual Manager",
|
||||
};
|
||||
|
||||
const visualMe = {
|
||||
id: "employee-visual-wave2",
|
||||
employeeNo: "E-WAVE2",
|
||||
name: visualUser.name,
|
||||
email: visualUser.identifier,
|
||||
phone: null,
|
||||
roleCodes: ["manager"],
|
||||
permissions: [
|
||||
"expense.create",
|
||||
"expense.view_own",
|
||||
"expense.view_all",
|
||||
"expense.delete_own",
|
||||
"expense.approve",
|
||||
"leave.approve",
|
||||
"report.dashboard.view",
|
||||
],
|
||||
profileCompleteness: {
|
||||
hasEmergencyContact: true,
|
||||
hasBankAccount: true,
|
||||
hasAvatar: false,
|
||||
hasIdNumber: false,
|
||||
score: 80,
|
||||
},
|
||||
};
|
||||
|
||||
function envelope<T>(data: T) {
|
||||
return { requestId: "mock-pc-wave2", data };
|
||||
}
|
||||
|
||||
async function fulfillJson<T>(route: Route, data: T) {
|
||||
await route.fulfill({
|
||||
status: 200,
|
||||
contentType: "application/json",
|
||||
body: JSON.stringify(envelope(data)),
|
||||
});
|
||||
}
|
||||
|
||||
function navigationItem(key: string, href: string, label: string, icon: string, placement = "main") {
|
||||
return { key, href, label, icon, placement, permissionCodes: [], featureFlagKey: null };
|
||||
}
|
||||
|
||||
function reimbursementItem(id: string, status: string, formNumber: string, amount: string) {
|
||||
return {
|
||||
id,
|
||||
formNumber,
|
||||
status,
|
||||
reimbursementDate: "2026-05-27",
|
||||
totalAmount: amount,
|
||||
description: "Wave2 PC 视觉验证",
|
||||
payment: {
|
||||
paymentVoucherNo: null,
|
||||
paymentDate: null,
|
||||
paymentChannel: null,
|
||||
paidAt: null,
|
||||
paidBy: null,
|
||||
},
|
||||
owner: { id: visualMe.id, employeeNo: visualMe.employeeNo, name: visualMe.name },
|
||||
submitter: { id: visualMe.id, employeeNo: visualMe.employeeNo, name: visualMe.name },
|
||||
project: { id: "project-wave2", projectNo: "HYB-WAVE2", name: "OA 试运行" },
|
||||
pendingWorkflow: status === "reviewing"
|
||||
? {
|
||||
task: { id: `task-${id}`, stepName: "主管审批" },
|
||||
allowedActions: ["approve", "reject"],
|
||||
}
|
||||
: null,
|
||||
createdAt: "2026-05-27T09:00:00.000Z",
|
||||
updatedAt: "2026-05-27T09:30:00.000Z",
|
||||
};
|
||||
}
|
||||
|
||||
const pendingWorkflowTask = {
|
||||
id: "workflow-task-wave2",
|
||||
instanceId: "workflow-instance-wave2",
|
||||
stepId: "manager-review",
|
||||
stepName: "主管审批",
|
||||
assigneeId: visualMe.id,
|
||||
assigneeRole: "manager",
|
||||
status: "pending",
|
||||
outcome: null,
|
||||
createdAt: "2026-05-27T09:05:00.000Z",
|
||||
completedAt: null,
|
||||
workflowInstance: {
|
||||
entityType: "reimbursement",
|
||||
entityId: "reimbursement-wave2-reviewing",
|
||||
currentStatus: "reviewing",
|
||||
},
|
||||
businessSummary: {
|
||||
reference: "BX20260527001",
|
||||
title: "研发采购报销",
|
||||
applicantName: "王经理",
|
||||
amount: "¥1,260.00",
|
||||
duration: null,
|
||||
businessStatus: "reviewing",
|
||||
},
|
||||
allowedActions: ["approve", "reject", "return", "transfer"],
|
||||
};
|
||||
|
||||
async function mockWave2Apis(page: Page) {
|
||||
await page.route((url) => url.pathname.startsWith("/api/"), async (route) => {
|
||||
const request = route.request();
|
||||
const url = new URL(request.url());
|
||||
const pathName = url.pathname;
|
||||
|
||||
if (pathName === "/api/auth/capabilities") {
|
||||
await fulfillJson(route, {
|
||||
emailDelivery: { ready: true, statusReasons: [] },
|
||||
emailLoginCode: { enabled: true },
|
||||
passwordReset: { enabled: true },
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (pathName === "/api/auth/sso/providers") {
|
||||
await fulfillJson(route, []);
|
||||
return;
|
||||
}
|
||||
|
||||
if (pathName === "/api/auth/wecom/config") {
|
||||
await fulfillJson(route, {
|
||||
enabled: true,
|
||||
entryEnabled: true,
|
||||
oauthEnabled: true,
|
||||
corpId: "wx-wave2",
|
||||
agentId: "1000002",
|
||||
loginUrl: "/api/auth/wecom/login?returnTo=%2Fportal",
|
||||
bindEnabled: true,
|
||||
defaultReturnTo: "/portal",
|
||||
status: "ready",
|
||||
statusReasons: [],
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (pathName === "/api/auth/login" || pathName === "/api/auth/refresh") {
|
||||
await route.fulfill({
|
||||
status: 200,
|
||||
contentType: "application/json",
|
||||
headers: { "set-cookie": "has_session=1; Path=/; SameSite=Lax" },
|
||||
body: JSON.stringify(envelope({ accessToken: "mock-pc-wave2-token", expiresIn: 900, mustChangePassword: false })),
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (pathName === "/api/me") {
|
||||
await fulfillJson(route, visualMe);
|
||||
return;
|
||||
}
|
||||
|
||||
if (pathName === "/api/system/navigation") {
|
||||
await fulfillJson(route, {
|
||||
workspace: {
|
||||
id: "workspace-wave2",
|
||||
persisted: true,
|
||||
profile: "small_team_internal",
|
||||
orgMode: "single_company",
|
||||
primaryEntryMode: "password",
|
||||
notificationStrategy: "in_app",
|
||||
devicePriority: "desktop",
|
||||
moduleVisibility: {},
|
||||
createdAt: null,
|
||||
updatedAt: null,
|
||||
updatedBy: null,
|
||||
},
|
||||
sections: {
|
||||
main: [
|
||||
navigationItem("portal", "/portal", "工作台", "home_app_logo"),
|
||||
navigationItem("workflow", "/workflow/tasks", "审批待办", "fact_check"),
|
||||
navigationItem("expense", "/reimbursements", "报销", "request_quote"),
|
||||
],
|
||||
admin: [],
|
||||
backup: [],
|
||||
},
|
||||
recommendedRolePresets: [],
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (pathName === "/api/notifications") {
|
||||
await fulfillJson(route, {
|
||||
page: 1,
|
||||
pageSize: Number(url.searchParams.get("pageSize") ?? 5),
|
||||
total: 0,
|
||||
unreadOnly: url.searchParams.get("unreadOnly") === "1",
|
||||
unreadCount: 0,
|
||||
items: [],
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (pathName === "/api/portal/home") {
|
||||
await fulfillJson(route, {
|
||||
workspace: { id: "workspace-wave2", persisted: true, profile: "small_team_internal" },
|
||||
greeting: { name: visualMe.name },
|
||||
cards: [
|
||||
{ key: "pending_approvals", title: "审批待办", value: 3, href: "/workflow/tasks", severity: "warning" },
|
||||
{ key: "team_presence", title: "团队状态", value: "7/9 在岗", href: "/team", severity: "normal" },
|
||||
{ key: "weekly_missing", title: "周报缺口", value: 1, href: "/weekly-reports", severity: "warning" },
|
||||
{ key: "weekly_help", title: "需协助", value: 1, href: "/weekly-reports", severity: "normal" },
|
||||
{ key: "my_projects", title: "项目跟进", value: 4, href: "/projects", severity: "normal" },
|
||||
],
|
||||
pendingTasks: { count: 3, href: "/workflow/tasks" },
|
||||
myApplications: [
|
||||
{ domain: "reimbursement", count: 2, href: "/reimbursements" },
|
||||
{ domain: "leave", count: 1, href: "/leave-requests" },
|
||||
],
|
||||
riskSummary: null,
|
||||
announcements: [{ id: "ann-wave2", title: "试运行提醒", summary: "今日优先处理审批和报销。", href: null }],
|
||||
quickLinks: [{ key: "expense", title: "报销列表", href: "/reimbursements" }],
|
||||
todayPresence: { date: "2026-05-27", status: "office", label: "在岗", note: "已同步企微", href: "/team" },
|
||||
teamPresence: { date: "2026-05-27", office: 7, remote: 1, out: 0, travel: 0, leave: 1, unspecified: 0, total: 9, href: "/team" },
|
||||
weeklyReport: { weekStart: "2026-05-25", status: "draft", needsHelp: false, href: "/weekly-reports" },
|
||||
weeklySummary: { weekStart: "2026-05-25", submittedCount: 8, missingCount: 1, needsHelpCount: 1, href: "/weekly-reports" },
|
||||
todoSummary: { openCount: 2, highPriorityCount: 1, href: "/todos" },
|
||||
projectSummary: null,
|
||||
peopleLifecycle: null,
|
||||
financeSummary: null,
|
||||
adoptionSummary: null,
|
||||
roleCapabilities: {
|
||||
canSubmitApplications: true,
|
||||
canApproveTasks: true,
|
||||
canUseFinance: false,
|
||||
canManageSystem: false,
|
||||
canViewTeam: true,
|
||||
isAdminOnly: false,
|
||||
},
|
||||
recentActivities: [
|
||||
{ id: "activity-wave2-1", type: "reimbursement.submit", actorName: "王经理", summary: "王经理提交了研发采购报销", createdAt: "2026-05-27T08:50:00.000Z", href: "/reimbursements/reimbursement-wave2-reviewing" },
|
||||
],
|
||||
teamStatusBoard: [
|
||||
{ employeeId: "employee-wave2-1", name: "王经理", avatarUrl: null, presenceStatus: "office", attendanceClockIn: "2026-05-27T09:00:00.000Z", attendanceClockOut: null, onLeave: false, leaveType: null },
|
||||
{ employeeId: "employee-wave2-2", name: "李工", avatarUrl: null, presenceStatus: "remote", attendanceClockIn: null, attendanceClockOut: null, onLeave: false, leaveType: null },
|
||||
],
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (pathName === "/api/workflow/tasks/summary") {
|
||||
await fulfillJson(route, {
|
||||
scope: "mine",
|
||||
pendingTotal: 3,
|
||||
overdueTotal: 1,
|
||||
earliestPendingAt: "2026-05-27T09:05:00.000Z",
|
||||
averagePendingAgeHours: 2,
|
||||
byEntityType: [{ key: "reimbursement", pendingTotal: 3 }],
|
||||
byStep: [],
|
||||
byAssigneeRole: [],
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (pathName === "/api/workflow/tasks") {
|
||||
const status = url.searchParams.get("status") ?? "pending";
|
||||
await fulfillJson(route, {
|
||||
page: 1,
|
||||
pageSize: Number(url.searchParams.get("pageSize") ?? 20),
|
||||
total: status === "pending" ? 1 : 0,
|
||||
items: status === "pending" ? [pendingWorkflowTask] : [],
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (pathName === "/api/reimbursements" && request.method() === "GET") {
|
||||
const status = url.searchParams.get("status") ?? "draft";
|
||||
const items = [
|
||||
reimbursementItem("reimbursement-wave2-draft", "draft", "BX20260527000", "320.00"),
|
||||
reimbursementItem("reimbursement-wave2-reviewing", "reviewing", "BX20260527001", "1260.00"),
|
||||
].filter((item) => item.status === status);
|
||||
await fulfillJson(route, { page: 1, pageSize: 20, total: items.length, scope: url.searchParams.get("scope") ?? "own", items });
|
||||
return;
|
||||
}
|
||||
|
||||
if (pathName === "/api/reimbursement-templates") {
|
||||
await fulfillJson(route, { page: 1, pageSize: 20, total: 0, items: [] });
|
||||
return;
|
||||
}
|
||||
|
||||
if (pathName === "/api/reimbursements/linkable-travel-requests") {
|
||||
await fulfillJson(route, { ownerEmployeeId: visualMe.id, items: [] });
|
||||
return;
|
||||
}
|
||||
|
||||
await fulfillJson(route, {});
|
||||
});
|
||||
}
|
||||
|
||||
async function capture(page: Page, name: string) {
|
||||
const outputDir = path.resolve(process.cwd(), "../output/playwright/pc-core-workflow-visual-wave2");
|
||||
mkdirSync(outputDir, { recursive: true });
|
||||
await page.screenshot({ path: path.join(outputDir, `${name}.png`), fullPage: true });
|
||||
}
|
||||
|
||||
test("PC 核心工作流 Wave2 视觉截图", async ({ page }) => {
|
||||
await mockWave2Apis(page);
|
||||
await page.setViewportSize({ width: 1440, height: 960 });
|
||||
|
||||
await page.goto("/login");
|
||||
await expect(page.getByTestId("login-mode-switch")).toBeVisible();
|
||||
await expect(page.getByTestId("wecom-entry-browser-notice")).toBeVisible();
|
||||
await capture(page, "01-login");
|
||||
|
||||
await page.getByTestId("login-identifier").fill(visualUser.identifier);
|
||||
await page.getByTestId("login-password").fill(visualUser.password);
|
||||
await page.getByTestId("login-submit").click();
|
||||
await expect(page).toHaveURL(/\/portal/);
|
||||
await expect(page.locator('[aria-label="portal-card-pending_approvals"]')).toBeVisible();
|
||||
await capture(page, "02-portal");
|
||||
|
||||
await page.goto("/reimbursements?status=reviewing&scope=all");
|
||||
await expect(page.getByTestId("reimbursements-table")).toBeVisible();
|
||||
await expect(page.locator(".ops-command-bar").first()).toBeVisible();
|
||||
await capture(page, "03-reimbursements");
|
||||
|
||||
await page.goto("/workflow/tasks");
|
||||
await expect(page.getByTestId("workflow-tasks-table")).toBeVisible();
|
||||
await expect(page.locator(".ops-command-bar").first()).toBeVisible();
|
||||
await capture(page, "04-workflow-tasks");
|
||||
});
|
||||
在新工单中引用
屏蔽一个用户