文件
hyb-oa/client/tests/e2e/workflow-action-confirm-ui.spec.ts
T
wangsli 96488d8052 R7E-16D 审批动作二次确认
Refs: R7E-16D BIZ8-12B QAOPS8-17
2026-05-15 21:20:49 +08:00

321 行
9.6 KiB
TypeScript

import type { Page, Route } from "@playwright/test";
import { test, expect } from "./helpers/fixtures";
import { login, MANAGER } from "./helpers/auth";
import { TEST_IDS } from "./helpers/testIds";
test.use({ serviceWorkers: "block" });
function envelope<T>(data: T) {
return { requestId: "mock-workflow-confirm", data };
}
async function fulfillJson<T>(route: Route, data: T) {
await route.fulfill({
status: 200,
contentType: "application/json",
body: JSON.stringify(envelope(data)),
});
}
const mockMe = {
id: "employee-confirm-manager",
employeeNo: "M-confirm",
name: "Manager",
email: "[email protected]",
phone: null,
roleCodes: ["manager"],
profileCompleteness: {
hasEmergencyContact: true,
hasBankAccount: true,
hasAvatar: false,
hasIdNumber: false,
score: 70,
},
};
const pendingTask = {
id: "task-confirm-1",
instanceId: "instance-confirm-1",
stepId: "manager-review",
stepName: "主管审批",
assigneeId: mockMe.id,
assigneeRole: "manager",
status: "pending",
outcome: null,
createdAt: "2026-05-15T09:00:00.000Z",
completedAt: null,
workflowInstance: {
entityType: "leave",
entityId: "leave-confirm-1",
currentStatus: "reviewing",
},
businessSummary: {
reference: "QJ-CONFIRM-001",
title: "R7E 审批确认测试",
applicantName: "Employee",
amount: null,
duration: "1 天",
businessStatus: "reviewing",
},
allowedActions: ["approve", "reject", "return"],
};
const pendingTaskDetail = {
task: {
id: pendingTask.id,
instanceId: pendingTask.instanceId,
stepId: pendingTask.stepId,
stepName: pendingTask.stepName,
assigneeId: pendingTask.assigneeId,
assigneeRole: pendingTask.assigneeRole,
status: pendingTask.status,
outcome: null,
comment: null,
createdAt: pendingTask.createdAt,
completedAt: null,
},
workflowInstance: {
id: pendingTask.instanceId,
entityType: "leave",
currentStatus: "reviewing",
currentStepId: "manager-review",
contextData: { standardViolations: [] },
startedAt: "2026-05-15T09:00:00.000Z",
completedAt: null,
},
reimbursement: null,
leaveRequest: {
id: "leave-confirm-1",
status: "reviewing",
startDate: "2026-06-01",
endDate: "2026-06-01",
startSession: "am",
endSession: "pm",
requestedDays: 1,
reason: "R7E 审批动作确认",
attachment: null,
leaveType: { id: "annual", code: "annual", name: "年假" },
owner: { id: "employee-confirm-applicant", employeeNo: "E-confirm", name: "Employee" },
},
purchaseRequest: null,
travelRequest: null,
allowedActions: pendingTask.allowedActions,
history: [],
};
function navigationItem(key: string, href: string, label: string, icon: string, placement = "main") {
return { key, href, label, icon, placement, permissionCodes: [], featureFlagKey: null };
}
async function mockWorkflowConfirmApis(page: Page) {
const actionCalls = {
approve: 0,
reject: 0,
return: 0,
};
await page.route((url) => url.pathname.startsWith("/api/"), async (route) => {
const request = route.request();
const url = new URL(request.url());
const path = url.pathname;
if (path === "/api/auth/sso/providers") {
await fulfillJson(route, []);
return;
}
if (path === "/api/auth/wecom/config") {
await fulfillJson(route, {
enabled: true,
entryEnabled: true,
oauthEnabled: true,
corpId: "wx-test-corp",
agentId: "1000002",
loginUrl: "/api/auth/wecom/login?returnTo=%2Fportal",
bindEnabled: true,
defaultReturnTo: "/portal",
status: "ready",
statusReasons: [],
});
return;
}
if (path === "/api/auth/login" || path === "/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-workflow-confirm-token",
expiresIn: 900,
mustChangePassword: false,
})),
});
return;
}
if (path === "/api/auth/logout") {
await route.fulfill({
status: 200,
contentType: "application/json",
headers: { "set-cookie": "has_session=; Path=/; Max-Age=0" },
body: JSON.stringify(envelope({})),
});
return;
}
if (path === "/api/me") {
await fulfillJson(route, mockMe);
return;
}
if (path === "/api/system/navigation") {
await fulfillJson(route, {
workspace: {
id: "workspace-confirm",
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", "Portal", "home_app_logo"),
navigationItem("workflow", "/workflow/tasks", "审批待办", "fact_check"),
],
admin: [],
backup: [],
},
recommendedRolePresets: [],
});
return;
}
if (path === "/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 (path === "/api/portal/home") {
await fulfillJson(route, {
hero: { title: "工作台", subtitle: "审批动作确认测试" },
metrics: [],
todos: [],
notifications: [],
});
return;
}
if (path === "/api/workflow/tasks/summary") {
await fulfillJson(route, {
scope: "mine",
pendingTotal: actionCalls.approve > 0 ? 0 : 1,
overdueTotal: 0,
earliestPendingAt: pendingTask.createdAt,
averagePendingAgeHours: 1,
byEntityType: [],
byStep: [],
byAssigneeRole: [],
});
return;
}
if (path === "/api/workflow/tasks") {
const status = url.searchParams.get("status") ?? "pending";
const items = status === "pending" && actionCalls.approve === 0 ? [pendingTask] : [];
await fulfillJson(route, {
page: 1,
pageSize: Number(url.searchParams.get("pageSize") ?? 20),
total: items.length,
items,
});
return;
}
const actionMatch = path.match(/^\/api\/workflow\/tasks\/[^/]+\/(approve|reject|return)$/);
if (actionMatch) {
const action = actionMatch[1] as keyof typeof actionCalls;
actionCalls[action] += 1;
await fulfillJson(route, { ok: true });
return;
}
if (/^\/api\/workflow\/tasks\/[^/]+$/.test(path)) {
await fulfillJson(route, pendingTaskDetail);
return;
}
if (path === "/api/workflow/approvers") {
await fulfillJson(route, { page: 1, pageSize: 100, total: 0, items: [] });
return;
}
await fulfillJson(route, {});
});
return actionCalls;
}
test.describe("R7E 审批动作二次确认", () => {
test("PC 列表快捷通过必须二次确认后才提交", async ({ page }) => {
const actionCalls = await mockWorkflowConfirmApis(page);
await login(page, MANAGER);
await page.goto("/workflow/tasks");
await expect(page.getByTestId(TEST_IDS.workflow.tasksTable)).toBeVisible();
const taskRow = page.getByTestId(TEST_IDS.workflow.taskRow).filter({ hasText: "QJ-CONFIRM-001" });
await expect(taskRow).toHaveCount(1);
await taskRow.getByTestId(TEST_IDS.workflow.quickApprove).click();
await expect(page.getByTestId("workflow-action-confirm-dialog")).toContainText("确认后将进入下一审批节点");
expect(actionCalls.approve).toBe(0);
await page.getByTestId("workflow-action-confirm-cancel").click();
expect(actionCalls.approve).toBe(0);
await taskRow.getByTestId(TEST_IDS.workflow.quickApprove).click();
await page.getByTestId("workflow-action-confirm-submit").click();
await expect.poll(() => actionCalls.approve).toBe(1);
});
test("PC 审批详情通过、驳回、退回都先解释动作后果", async ({ page }) => {
const actionCalls = await mockWorkflowConfirmApis(page);
await login(page, MANAGER);
await page.goto(`/workflow/tasks/${pendingTask.id}`);
await expect(page.getByTestId("workflow-task-overview")).toBeVisible();
await page.getByTestId("workflow-task-approve").click();
await expect(page.getByTestId("workflow-action-confirm-dialog")).toContainText("确认后将进入下一审批节点");
await page.getByTestId("workflow-action-confirm-cancel").click();
expect(actionCalls.approve).toBe(0);
await page.getByTestId("workflow-task-reject-comment").fill("资料不符合要求,请重新发起。");
await page.getByTestId("workflow-task-reject").click();
await expect(page.getByTestId("workflow-action-confirm-dialog")).toContainText("流程将终止");
await page.getByTestId("workflow-action-confirm-cancel").click();
expect(actionCalls.reject).toBe(0);
await page.getByTestId("workflow-task-return-comment").fill("请补充附件后重新提交。");
await page.getByTestId("workflow-task-return").click();
await expect(page.getByTestId("workflow-action-confirm-dialog")).toContainText("回到申请人修改态");
await page.getByTestId("workflow-action-confirm-submit").click();
await expect.poll(() => actionCalls.return).toBe(1);
});
});