feat(报销): 收敛只读内容与审批上下文 [09-02-reimbursement-readonly-content-consistency]

这个提交包含在:
2026-09-02 21:13:08 +08:00
父节点 dda625b15f
当前提交 e48514d542
共修改 20 个文件,包含 740 行新增和 47 行删除
@@ -87,9 +87,12 @@ test("B-2b 报销工作台双端共享内容合同且 task detail 只由路由
expect(shell).toContain("<ReimbursementItemEvidenceList");
expect(shell.indexOf("slots.beforeEvidence")).toBeLessThan(shell.indexOf("<ReimbursementItemEvidenceList"));
expect(shell.indexOf("<ReimbursementItemEvidenceList")).toBeLessThan(shell.indexOf("slots.afterEvidence"));
expect(shell.indexOf("slots.afterEvidence")).toBeLessThan(shell.indexOf("slots.timeline"));
}
expect(desktopShell).not.toContain("slots.timeline");
expect(desktopShell.indexOf("slots.actionPanel")).toBeLessThan(desktopShell.indexOf("slots.asideContext"));
expect(mobileShell.indexOf("slots.afterEvidence")).toBeLessThan(mobileShell.indexOf("slots.timeline"));
expect(desktopRoute.match(/fetchWorkflowTaskDetail\(/g)).toHaveLength(1);
expect(mobileRoute.match(/fetchWorkflowTaskDetail\(/g)).toHaveLength(1);
expect(approvalAdapter).not.toContain("fetchWorkflowTaskDetail");
@@ -415,6 +415,8 @@ test.describe("R102 reimbursement main flow", () => {
await page.goto(`/reimbursements/${reimbursementId}`);
await expect(page.getByTestId("reimbursement-desktop-workspace")).toContainText("¥168.30");
await expect(page.getByTestId("reimbursement-amount-summary")).toContainText("明细合计");
await expect(page.getByTestId("reimbursement-amount-summary")).toContainText("¥168.30");
await expect(page.getByTestId("reimbursement-expense-items-table").getByRole("columnheader")).toHaveText(["序号", "费用类型", "发生日期", "费用说明", "金额", "票据", "操作"]);
await expect(page.getByTestId("approval-item-evidence")).toContainText("未关联");
await expect(page.getByTestId("approval-item-evidence")).toContainText("这条明细尚无对应票据");
@@ -451,6 +453,8 @@ test.describe("R102 reimbursement main flow", () => {
await page.getByTestId("mobile-reimbursement-card").getByRole("link").click();
await expect(page.getByTestId("reimbursement-approval-evidence").getByTestId("approval-item-evidence")).toHaveCount(1);
await expect(page.getByTestId("reimbursement-mobile-workspace")).toContainText("¥168.30");
await expect(page.getByTestId("reimbursement-amount-summary")).toContainText("明细合计");
await expect(page.getByTestId("reimbursement-amount-summary")).toContainText("¥168.30");
});
test("管理员查看他人报销时保持只读并可在移动端切换全部报销", async ({ page }) => {
@@ -0,0 +1,149 @@
import { readFileSync } from "node:fs";
import path from "node:path";
import { expect, test } from "@playwright/test";
import { buildReimbursementApprovalEvidence } from "../../src/lib/reimbursementApprovalProjection";
import {
buildReimbursementAmountSummary,
parseMoneyToMinorUnits,
} from "../../src/lib/reimbursementWorkspace";
function source(relativePath: string) {
return readFileSync(path.resolve(process.cwd(), relativePath), "utf8");
}
test("报销金额使用整数分判断完整性且不产生展示用第二总额", () => {
expect(parseMoneyToMinorUnits("0")).toBe(0n);
expect(parseMoneyToMinorUnits("0.1")).toBe(10n);
expect(parseMoneyToMinorUnits("1234.56")).toBe(123456n);
expect(parseMoneyToMinorUnits("1,234.56")).toBeNull();
expect(parseMoneyToMinorUnits("0.001")).toBeNull();
expect(parseMoneyToMinorUnits("NaN")).toBeNull();
expect(parseMoneyToMinorUnits(null)).toBeNull();
expect(buildReimbursementAmountSummary("0.30", [{ amount: "0.1" }, { amount: "0.20" }])).toEqual({
authoritativeTotalAmount: "0.30",
integrity: "ready",
});
expect(buildReimbursementAmountSummary("1000.00", [{ amount: "400" }, { amount: "600.00" }])).toEqual({
authoritativeTotalAmount: "1000.00",
integrity: "ready",
});
expect(buildReimbursementAmountSummary("100.00", [{ amount: "99.99" }])).toEqual({
authoritativeTotalAmount: "100.00",
integrity: "mismatch",
});
expect(buildReimbursementAmountSummary("100.00", [{ amount: "invalid" }])).toEqual({
authoritativeTotalAmount: "100.00",
integrity: "unavailable",
});
expect(buildReimbursementAmountSummary("0.00", [])).toEqual({
authoritativeTotalAmount: "0.00",
integrity: "ready",
});
});
test("PC 与移动明细只展示共享模型中的服务端权威合计", () => {
const evidenceList = source("src/components/reimbursements/ReimbursementItemEvidenceList.tsx");
const desktopDetail = source("src/pages/ReimbursementDetailPage.tsx");
const mobileDetail = source("src/pages/MobileReimbursementDetailPage.tsx");
const approvalAdapter = source("src/pages/reimbursement-workspace/ReimbursementApprovalAdapter.tsx");
const desktopShell = source("src/components/reimbursements/ReimbursementDesktopWorkspaceShell.tsx");
const mobileShell = source("src/components/reimbursements/ReimbursementMobileWorkspaceShell.tsx");
expect(evidenceList).toContain("<tfoot");
expect(evidenceList).toContain("amountSummary.authoritativeTotalAmount");
expect(evidenceList).not.toContain("items.reduce(");
expect(desktopShell).toContain("model.amountSummary.authoritativeTotalAmount");
expect(mobileShell).toContain("model.amountSummary.authoritativeTotalAmount");
expect(desktopShell).not.toContain("model.header.totalAmount");
expect(mobileShell).not.toContain("model.header.totalAmount");
for (const consumer of [desktopDetail, mobileDetail, approvalAdapter]) {
expect(consumer).toContain("buildReimbursementWorkspaceModel(");
expect(consumer).not.toContain("buildReimbursementAmountSummary(");
}
});
test("PC 审批历史只进入右栏且移动历史保持正文末尾", () => {
const desktopShell = source("src/components/reimbursements/ReimbursementDesktopWorkspaceShell.tsx");
const mobileShell = source("src/components/reimbursements/ReimbursementMobileWorkspaceShell.tsx");
const approvalAdapter = source("src/pages/reimbursement-workspace/ReimbursementApprovalAdapter.tsx");
expect(desktopShell).not.toContain("slots.timeline");
expect(desktopShell.indexOf("slots.actionPanel")).toBeLessThan(desktopShell.indexOf("slots.asideContext"));
expect(mobileShell.indexOf("slots.afterEvidence")).toBeLessThan(mobileShell.indexOf("slots.timeline"));
expect(approvalAdapter).toContain("asideContext: timeline");
expect(approvalAdapter.match(/^\s+timeline,$/gm)).toHaveLength(1);
});
test("申请人进度与审批历史保持有意分工", () => {
const desktopDetail = source("src/pages/ReimbursementDetailPage.tsx");
const mobileDetail = source("src/pages/MobileReimbursementDetailPage.tsx");
const approvalAdapter = source("src/pages/reimbursement-workspace/ReimbursementApprovalAdapter.tsx");
expect(desktopDetail).toContain("<ProcessingProgress");
expect(mobileDetail).toContain("<ProcessingProgress");
expect(desktopDetail.match(/targetLinkLabel="查看所在付款批次"/g)).toHaveLength(1);
expect(mobileDetail.match(/targetLinkLabel="查看所在付款批次"/g)).toHaveLength(1);
expect(approvalAdapter).toContain('data-testid="reimbursement-workflow-history"');
expect(approvalAdapter).not.toContain("<ProcessingProgress");
});
test("票据申报事实与系统金额证据状态分属正文和处理上下文", () => {
const baseDetail = {
items: [{
id: "item-1",
expenseTypeId: "type-1",
expenseDate: "2026-09-01",
amount: "100.00",
description: "合成明细",
assetPriorApprovalBasis: null,
expenseType: { id: "type-1", code: "office_supplies", name: "办公用品", category: "office", enabled: true, requiresInvoice: true },
}],
attachments: [],
};
const buildDetail = (amountEvidenceStatus: "verified" | "manual_review") => ({
...baseDetail,
invoices: [{
id: "invoice-1",
status: "bound",
invoiceCode: "CODE-1",
invoiceNumber: "NUMBER-1",
invoiceDate: "2026-09-01",
sellerName: "合成供应商",
buyerName: null,
documentCategory: "invoice",
documentSubtype: "vat",
totalAmount: "100.00",
originalName: "invoice.pdf",
mimeType: "application/pdf",
fileSize: 100,
linkedItemId: "item-1",
amountEvidenceStatus,
}],
});
const snapshot = { standardViolations: [], budgetCheck: null, budgetCheckStatus: "not_applicable" as const, parseStatus: "ready" as const };
const verified = buildReimbursementApprovalEvidence(buildDetail("verified"), snapshot).items[0].invoices[0];
const manualReview = buildReimbursementApprovalEvidence(buildDetail("manual_review"), snapshot).items[0].invoices[0];
const declaredFact = ({ amountEvidenceStatus: _context, ...fact }: typeof verified) => fact;
expect(declaredFact(verified)).toEqual(declaredFact(manualReview));
expect(verified.amountEvidenceStatus).toBe("verified");
expect(manualReview.amountEvidenceStatus).toBe("manual_review");
});
test("打印页保持组合归档视图且归档元数据不进入交互工作台", () => {
const printPage = source("src/pages/ReimbursementPrintPage.tsx");
const desktopShell = source("src/components/reimbursements/ReimbursementDesktopWorkspaceShell.tsx");
const mobileShell = source("src/components/reimbursements/ReimbursementMobileWorkspaceShell.tsx");
expect(printPage).toContain("const totalAmount = detail.totalAmount");
expect(printPage).toContain("<QRCodeSVG");
expect(printPage).toContain("打印时间:");
expect(printPage).toContain("打印人:");
expect(printPage).toContain("审批记录");
for (const shell of [desktopShell, mobileShell]) {
expect(shell).not.toContain("QRCodeSVG");
expect(shell).not.toContain("打印时间:");
expect(shell).not.toContain("打印人:");
}
});
@@ -387,6 +387,14 @@ test.describe("R7E 审批动作二次确认", () => {
submitter: { id: "owner", employeeNo: "E001", name: "申请人" },
},
leaveRequest: null,
history: Array.from({ length: 6 }, (_, index) => ({
id: `history-${index + 1}`,
action: index === 0 ? "submit" : "approve",
actorName: index === 0 ? "申请人" : `审批人 ${index}`,
actorEmployeeNo: `E${index + 1}`,
comment: index === 5 ? "这是一条用于验证右栏长意见自然换行且不会把审批动作推到历史之后的合成长意见。".repeat(3) : `第 ${index + 1} 条处理意见`,
createdAt: pendingTaskCreatedAt,
})),
};
const reimbursementDetail = {
id: reimbursementId,
@@ -425,6 +433,22 @@ test.describe("R7E 审批动作二次确认", () => {
await expect(page.getByRole("heading", { name: "报销单 BX-APPROVAL-001" })).toHaveCount(1);
await expect(page.getByText("客户拜访交通费", { exact: true })).toHaveCount(1);
await expect(page.getByTestId("reimbursement-approval-evidence")).toContainText("客户拜访打车");
await expect(page.getByTestId("reimbursement-amount-summary")).toContainText("明细合计");
await expect(page.getByTestId("reimbursement-amount-summary")).toContainText("¥180.00");
await expect(page.getByText("报销总额与明细汇总不一致,请联系管理员")).toHaveCount(0);
await expect(page.getByText("明细金额无法完整核对,请联系管理员")).toHaveCount(0);
await expect(page.getByTestId("workflow-task-approve")).toBeEnabled();
await expect(page.getByTestId("workflow-task-return-toggle")).toBeEnabled();
await expect(page.getByTestId("workflow-task-reject-toggle")).toBeEnabled();
await expect(page.getByTestId("workflow-task-transfer-menu-item")).toBeEnabled();
await expect(page.getByTestId("reimbursement-workflow-history").locator(".detail-timeline-item")).toHaveCount(6);
await expect(page.getByRole("heading", { name: "处理历史" })).toHaveCount(1);
const actionBox = await page.getByTestId("workflow-task-action-panel").boundingBox();
const historyBox = await page.getByTestId("reimbursement-workflow-history").boundingBox();
expect(actionBox).not.toBeNull();
expect(historyBox).not.toBeNull();
expect(actionBox!.y + actionBox!.height).toBeLessThanOrEqual(historyBox!.y);
expect(await page.evaluate(() => document.documentElement.scrollWidth <= document.documentElement.clientWidth + 2)).toBe(true);
await expect(page.getByTestId("approval-unlinked-invoices")).toContainText("FP-002");
await expect(page.locator("#reimbursement-workspace-snapshot")).toContainText("该次提交未留存预算快照");
await expect(page.getByText("当前申报金额高于已读取的票面金额合计")).toBeVisible();
@@ -469,4 +493,146 @@ test.describe("R7E 审批动作二次确认", () => {
await expect(page.getByTestId("workflow-task-reject-toggle")).toBeDisabled();
await expect(page.getByTestId("workflow-task-transfer-menu-item")).toBeDisabled();
});
test("移动报销审批保留正文末尾历史且底部动作不遮挡", async ({ page }) => {
const reimbursementId = "reimbursement-mobile-history";
const taskDetail = {
...pendingTaskDetail,
workflowInstance: {
...pendingTaskDetail.workflowInstance,
entityType: "reimbursement",
contextData: { standardViolations: [], budgetCheck: null, budgetCheckStatus: "not_applicable", parseStatus: "ready" },
},
reimbursement: {
id: reimbursementId,
formNumber: "BX-MOBILE-HISTORY",
status: "reviewing",
reimbursementDate: "2026-09-01",
totalAmount: "100.00",
description: "移动端历史布局",
owner: { id: "owner", employeeNo: "E001", name: "申请人" },
submitter: { id: "owner", employeeNo: "E001", name: "申请人" },
},
leaveRequest: null,
history: Array.from({ length: 6 }, (_, index) => ({
id: `mobile-history-${index + 1}`,
action: index === 0 ? "submit" : "approve",
actorName: index === 0 ? "申请人" : `审批人 ${index}`,
actorEmployeeNo: `M${index + 1}`,
comment: index === 5 ? "用于验证移动端长意见换行与底部安全区的合成长意见。".repeat(4) : `移动端第 ${index + 1} 条意见`,
createdAt: pendingTaskCreatedAt,
})),
};
const reimbursementDetail = {
id: reimbursementId,
formNumber: "BX-MOBILE-HISTORY",
status: "reviewing",
reimbursementDate: "2026-09-01",
totalAmount: "100.00",
description: "移动端历史布局",
owner: { id: "owner", employeeNo: "E001", name: "申请人" },
items: [{
id: "mobile-item",
expenseTypeId: "mobile-type",
expenseDate: "2026-09-01",
amount: "100.00",
description: "移动端合成明细",
assetPriorApprovalBasis: null,
expenseType: { id: "mobile-type", code: "travel_meal", name: "伙食补助费", category: "travel", enabled: true, requiresInvoice: false },
}],
invoices: [],
attachments: [],
};
await mockWorkflowConfirmApis(page, { taskDetail, reimbursementDetail });
await page.setViewportSize({ width: 375, height: 667 });
await login(page, MANAGER);
await page.goto(`/mobile/approvals/${pendingTask.id}`);
await expect(page.getByTestId("reimbursement-amount-summary")).toContainText("¥100.00");
await expect(page.getByTestId("reimbursement-workflow-history").locator(".detail-timeline-item")).toHaveCount(6);
const assertMobileGeometry = async () => {
expect(await page.evaluate(() => document.documentElement.scrollWidth <= document.documentElement.clientWidth + 2)).toBe(true);
const lastHistory = page.getByTestId("reimbursement-workflow-history").locator(".detail-timeline-item").last();
await page.evaluate(() => {
const scroller = document.querySelector<HTMLElement>(".hyb-mobile-shell .overflow-y-auto");
scroller?.scrollTo(0, scroller.scrollHeight);
});
const historyBox = await lastHistory.boundingBox();
const stickyBox = await page.getByTestId("mobile-approvals-sticky-actions").boundingBox();
expect(historyBox).not.toBeNull();
expect(stickyBox).not.toBeNull();
expect(historyBox!.y + historyBox!.height).toBeLessThanOrEqual(stickyBox!.y);
};
await assertMobileGeometry();
await page.setViewportSize({ width: 667, height: 375 });
await assertMobileGeometry();
});
for (const scenario of [
{
name: "权威总额与明细汇总不一致",
itemAmount: "99.99",
expectedMessage: "报销总额与明细汇总不一致,请联系管理员",
},
{
name: "明细金额无法解析",
itemAmount: "invalid",
expectedMessage: "明细金额无法完整核对,请联系管理员",
},
]) {
test(`PC 报销${scenario.name}时四类审批入口 fail closed`, async ({ page }) => {
const reimbursementId = `reimbursement-integrity-${scenario.itemAmount === "invalid" ? "unavailable" : "mismatch"}`;
const taskDetail = {
...pendingTaskDetail,
workflowInstance: {
...pendingTaskDetail.workflowInstance,
entityType: "reimbursement",
contextData: { standardViolations: [], budgetCheck: null, budgetCheckStatus: "not_applicable", parseStatus: "ready" },
},
reimbursement: {
id: reimbursementId,
formNumber: "BX-INTEGRITY-001",
status: "reviewing",
reimbursementDate: "2026-09-01",
totalAmount: "100.00",
description: "合成完整性场景",
owner: { id: "owner", employeeNo: "E001", name: "申请人" },
submitter: { id: "owner", employeeNo: "E001", name: "申请人" },
},
leaveRequest: null,
};
const reimbursementDetail = {
id: reimbursementId,
formNumber: "BX-INTEGRITY-001",
status: "reviewing",
reimbursementDate: "2026-09-01",
totalAmount: "100.00",
description: "合成完整性场景",
owner: { id: "owner", employeeNo: "E001", name: "申请人" },
items: [{
id: "item-integrity",
expenseTypeId: "type-integrity",
expenseDate: "2026-09-01",
amount: scenario.itemAmount,
description: "完整性核对明细",
assetPriorApprovalBasis: null,
expenseType: { id: "type-integrity", code: "office_supplies", name: "办公用品", category: "office", enabled: true, requiresInvoice: false },
}],
invoices: [],
attachments: [],
};
await mockWorkflowConfirmApis(page, { taskDetail, reimbursementDetail });
await login(page, MANAGER);
await page.goto(`/workflow/tasks/${pendingTask.id}`);
await expect(page.getByTestId("reimbursement-amount-summary")).toContainText("¥100.00");
await expect(page.getByRole("alert").filter({ hasText: scenario.expectedMessage })).toBeVisible();
await expect(page.getByText("差额", { exact: true })).toHaveCount(0);
await expect(page.getByTestId("workflow-task-approve")).toBeDisabled();
await expect(page.getByTestId("workflow-task-return-toggle")).toBeDisabled();
await expect(page.getByTestId("workflow-task-reject-toggle")).toBeDisabled();
await expect(page.getByTestId("workflow-task-transfer-menu-item")).toBeDisabled();
});
}
});