R73-A5 固化 OCR Playwright 回归与试运行清单
这个提交包含在:
@@ -0,0 +1,90 @@
|
||||
import { test, expect } from "./helpers/fixtures";
|
||||
import { EMPLOYEE, login, logout } from "./helpers/auth";
|
||||
import { TEST_IDS } from "./helpers/testIds";
|
||||
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 page.goto(`/reimbursements/${reimbursementId}`);
|
||||
await reimbursementDetail.assertLoaded();
|
||||
|
||||
await page.getByTestId(TEST_IDS.reimbursement.invoiceAdd).click();
|
||||
await expect(page.getByRole("dialog", { name: "添加发票" })).toBeVisible();
|
||||
|
||||
const marker = `MOCK_R73_SUCCESS_${Date.now()}`;
|
||||
await page.getByTestId(TEST_IDS.reimbursement.invoiceUploadFile).setInputFiles({
|
||||
name: `r73-success-${Date.now()}.png`,
|
||||
mimeType: "image/png",
|
||||
buffer: Buffer.from(marker, "utf8"),
|
||||
});
|
||||
await page.getByTestId(TEST_IDS.reimbursement.invoiceUploadSubmit).scrollIntoViewIfNeeded();
|
||||
await page.getByTestId(TEST_IDS.reimbursement.invoiceUploadSubmit).click();
|
||||
|
||||
await expect.poll(async () => {
|
||||
const text = await page.getByText(/已选 \d+ 张发票/).first().textContent().catch(() => "");
|
||||
return text ?? "";
|
||||
}, { timeout: 90_000 }).toContain("已选 1 张发票");
|
||||
|
||||
await page.getByRole("button", { name: "绑定选中发票" }).click();
|
||||
await expect(page.getByTestId(TEST_IDS.reimbursement.invoices)).not.toContainText("暂无关联票据", { timeout: 30_000 });
|
||||
|
||||
await reimbursementDetail.submitReimbursement();
|
||||
await expect(page.getByText(/状态:(reviewing|审批中)/)).toBeVisible({ timeout: 30_000 });
|
||||
|
||||
await logout(page, EMPLOYEE.name);
|
||||
});
|
||||
|
||||
test("E2E 轻交互 OCR:票据中心缺关键字段后可在当前页修正并标记可用", async ({ page }) => {
|
||||
test.skip(process.env.PLAYWRIGHT_OCR_MOCK !== "1", "需要 mock OCR 环境和 OCR 作业开启");
|
||||
|
||||
await login(page, EMPLOYEE);
|
||||
|
||||
await (await openNavLink(page, "票据中心")).click();
|
||||
await expect(page.getByTestId("invoice-pool-table")).toBeVisible();
|
||||
|
||||
await page.getByTestId("invoice-upload-file").setInputFiles({
|
||||
name: `r73-missing-${Date.now()}.png`,
|
||||
mimeType: "image/png",
|
||||
buffer: Buffer.from("MOCK_OCR_MISSING:invoiceCode,sellerName", "utf8"),
|
||||
});
|
||||
await page.getByTestId("invoice-upload-submit").click();
|
||||
|
||||
await expect(page.getByTestId("invoice-detail-panel")).toContainText("状态:ocr_failed", { timeout: 90_000 });
|
||||
await expect(page.getByTestId("invoice-ocr-status-banner")).toContainText("OCR 缺少关键字段:发票代码、销售方。");
|
||||
|
||||
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(/票据仍缺少关键字段/)).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("状态:available", { timeout: 30_000 });
|
||||
await expect(page.getByTestId("invoice-detail-panel")).toContainText("北京悦海堂餐饮管理有限公司");
|
||||
|
||||
await logout(page, EMPLOYEE.name);
|
||||
});
|
||||
@@ -0,0 +1,38 @@
|
||||
import { existsSync } from "node:fs";
|
||||
|
||||
import { test, expect } from "../helpers/fixtures";
|
||||
import { EMPLOYEE, login, logout } from "../helpers/auth";
|
||||
import { openNavLink } from "../helpers/navigation";
|
||||
|
||||
test("手工 live 腾讯 OCR 辅助复核:真实 VAT 发票上传后进入可处理状态", async ({ page }) => {
|
||||
test.skip(process.env.PLAYWRIGHT_MANUAL !== "1", "仅在显式手工 Playwright 模式下执行");
|
||||
test.skip(process.env.PLAYWRIGHT_OCR_LIVE !== "1", "仅在显式 live OCR 辅助复核模式下执行");
|
||||
|
||||
const invoiceFilePath = process.env.PLAYWRIGHT_OCR_LIVE_FILE?.trim() ?? "";
|
||||
test.skip(!invoiceFilePath || !existsSync(invoiceFilePath), "需要提供存在的 PLAYWRIGHT_OCR_LIVE_FILE");
|
||||
|
||||
await login(page, EMPLOYEE);
|
||||
await (await openNavLink(page, "票据中心")).click();
|
||||
await expect(page.getByTestId("invoice-pool-table")).toBeVisible();
|
||||
|
||||
await page.getByTestId("invoice-upload-file").setInputFiles(invoiceFilePath);
|
||||
await page.getByTestId("invoice-upload-submit").click();
|
||||
|
||||
await expect.poll(async () => {
|
||||
const text = await page.getByTestId("invoice-detail-panel").innerText().catch(() => "");
|
||||
if (text.includes("状态:available")) return "available";
|
||||
if (text.includes("状态:ocr_failed")) return "ocr_failed";
|
||||
return "pending_ocr";
|
||||
}, { timeout: 180_000 }).not.toBe("pending_ocr");
|
||||
|
||||
const detailText = await page.getByTestId("invoice-detail-panel").innerText();
|
||||
if (detailText.includes("状态:ocr_failed")) {
|
||||
const bannerText = await page.getByTestId("invoice-ocr-status-banner").innerText().catch(() => "OCR 失败");
|
||||
throw new Error(`live 腾讯 OCR 失败:${bannerText}`);
|
||||
}
|
||||
|
||||
await expect(page.getByTestId("invoice-detail-panel")).not.toContainText("发票号:---");
|
||||
await expect(page.getByTestId("invoice-detail-panel")).not.toContainText("总金额:-");
|
||||
|
||||
await logout(page, EMPLOYEE.name);
|
||||
});
|
||||
在新工单中引用
屏蔽一个用户