文件
hyb-oa/client/tests/e2e/invoice-ocr-flow.spec.ts
wangsli 1f8d5b658a 完善借款、编号、付款与预算并发及验收(09-06-release-gate-integrity)
汇总已落盘的借款本金与还款、兼容历史编号的周期化编号、付款责任与回单核验、报销进度和排序、PWA/采购事务、错误原因与日期校验及ERP退役。
统一共享预算池锁序和锁后判断,恢复差旅原预算选择,补原因码固定夹具及反向完整性检查。
纳入配套迁移、测试、受管QA、分层验收合同、规约及任务记录;原始证据留在ignored artifacts。

关联任务:09-17-company-loan-principal-repayment、09-17-erp-exclusive-retirement、09-18-reimbursement-periodic-numbering、09-08-reimbursement-payment-closeout、09-18-local-concurrency-product-fixes、09-19-budget-pool-concurrency、09-05-error-explainability-payment-readiness。
预算补审由Claude定向验证2文件928项通过,原4446/28及r6结果仍仅对应各自历史输入;本轮未重跑测试。
完整新候选门禁、R1真实入口接入与12项公网义务仍开放。生产编号未启用、差旅仍冻结;不推送、不部署,不宣称发布资格。
2026-09-19 13:11:04 +08:00

94 行
4.9 KiB
TypeScript

import { test, expect } from "./helpers/fixtures";
import { EMPLOYEE, FINANCE, login, logout } from "./helpers/auth";
import { openNavLink } from "./helpers/navigation";
async function createBlankReimbursement(page: import("@playwright/test").Page) {
const createResponsePromise = page.waitForResponse((response) => {
const url = new URL(response.url());
return response.request().method() === "POST" && url.pathname === "/api/reimbursements" && response.ok();
});
await (await openNavLink(page, "我的报销")).click();
await expect(page.getByTestId("reimbursements-create")).toBeVisible();
await page.getByTestId("reimbursements-create").click();
await page.getByRole("menuitem", { name: "空白报销" }).click();
const createPayload = (await (await createResponsePromise).json()) as { data?: { id?: string } };
const reimbursementId = createPayload.data?.id;
if (!reimbursementId) {
throw new Error(`创建报销单后未返回 id: ${JSON.stringify(createPayload)}`);
}
return reimbursementId;
}
test("E2E 轻交互 OCR:报销详情上传后自动添加并提交", async ({ page, reimbursementDetail }) => {
await login(page, EMPLOYEE);
const reimbursementId = await createBlankReimbursement(page);
await expect(page).toHaveURL(new RegExp(`/reimbursements/${reimbursementId}$`));
await reimbursementDetail.assertLoaded();
await reimbursementDetail.addItem();
// Historical title retained for result mapping; current UX explicitly confirms binding.
const marker = `MOCK_R73_SUCCESS_${Date.now()}`;
await reimbursementDetail.uploadInvoicePdf(
`r73-success-${Date.now()}.pdf`,
Buffer.from(`%PDF-1.4\n${marker}\n%%EOF\n`, "utf8"),
);
await reimbursementDetail.submitReimbursement();
await expect(page.getByText(/reviewing|审批中/).first()).toBeVisible({ timeout: 30_000 });
await logout(page, EMPLOYEE.name);
});
test("E2E 轻交互 OCR:票据缺关键字段后可在当前页修正并标记可用", async ({ page }) => {
test.skip(process.env.E2E_MODE === "live" || process.env.PLAYWRIGHT_OCR_MOCK !== "1", "需要本地受管 mock OCR 环境和 OCR 作业开启");
await login(page, FINANCE);
await (await openNavLink(page, "票据")).click();
await expect(page.getByTestId("invoice-pool-table")).toBeVisible();
const filename = `r73-missing-${Date.now()}.pdf`;
await page.getByRole("button", { name: "上传票据" }).click();
await page.getByTestId("invoice-upload-file").setInputFiles({
name: filename,
mimeType: "application/pdf",
buffer: Buffer.from("%PDF-1.4\nMOCK_OCR_MISSING:invoiceCode,sellerName\n%%EOF\n", "utf8"),
});
const uploaded = page.waitForResponse(response => new URL(response.url()).pathname === "/api/invoice-pool/upload" && response.request().method() === "POST");
await page.getByTestId("invoice-upload-submit").click();
const upload = await uploaded;
expect(upload.ok()).toBe(true);
const invoiceId = (await upload.json()).data.invoicePoolId as string;
await expect(page).toHaveURL(url => url.pathname === "/invoice-pool" && url.searchParams.get("id") === invoiceId);
await expect(page.getByTestId("invoice-detail-panel")).toContainText("状态:识别失败", { timeout: 90_000 });
await expect(page.getByTestId("invoice-ocr-status-banner")).toContainText("票据识别缺少关键字段:发票代码、销售方。");
await page.getByTestId("invoice-edit-open").click();
await page.getByTestId("invoice-edit-set-available").check();
await page.getByTestId("invoice-edit-save").click();
await expect(page.locator("main").getByText("票据仍缺少关键字段:发票代码、销售方,补齐后才能标记为可用。", { exact: true })).toBeVisible({ timeout: 15_000 });
await page.getByTestId("invoice-edit-code").fill("044003204111");
await page.getByTestId("invoice-edit-seller-name").fill("北京悦海堂餐饮管理有限公司");
await page.getByTestId("invoice-edit-save").click();
await expect(page.getByTestId("invoice-detail-panel")).toContainText("状态:可用", { timeout: 30_000 });
await expect(page.getByTestId("invoice-detail-panel")).toContainText("北京悦海堂餐饮管理有限公司");
await expect(page).toHaveURL(url => url.searchParams.get("id") === invoiceId);
await page.getByRole("button", { name: "返回列表", exact: true }).click();
await expect(page).toHaveURL(url => url.pathname === "/invoice-pool" && !url.searchParams.has("id"));
const row = page.getByRole("row").filter({ hasText: filename });
await row.getByRole("button", { name: "more_horiz", exact: true }).click();
await page.getByTestId("invoice-detail-button").click();
await expect(page).toHaveURL(url => url.searchParams.get("id") === invoiceId);
await expect(page.getByTestId("invoice-detail-panel")).toContainText("状态:可用");
await expect(page.getByTestId("invoice-detail-panel")).toContainText("北京悦海堂餐饮管理有限公司");
await logout(page, FINANCE.name);
});