From c920e199d0330d072318b743847e3063f6bde621 Mon Sep 17 00:00:00 2001 From: shunli Date: Wed, 6 May 2026 00:05:00 +0800 Subject: [PATCH] =?UTF-8?q?R93=20=E4=BF=AE=E5=A4=8D=E7=9C=9F=E5=AE=9E=20OC?= =?UTF-8?q?R=20=E8=BE=85=E5=8A=A9=E7=AD=89=E5=BE=85=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/tests/e2e/helpers/liveInvoiceOcr.ts | 24 +++++++++++++++---- .../tests/e2e/manual/live-invoice-ocr.spec.ts | 5 ++-- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/client/tests/e2e/helpers/liveInvoiceOcr.ts b/client/tests/e2e/helpers/liveInvoiceOcr.ts index 015aa1fd..048be9c5 100644 --- a/client/tests/e2e/helpers/liveInvoiceOcr.ts +++ b/client/tests/e2e/helpers/liveInvoiceOcr.ts @@ -35,14 +35,30 @@ export async function uploadLiveInvoiceAndWait(page: Page, invoiceFilePath: stri const detailPanel = page.getByTestId("invoice-detail-panel"); await expect(detailPanel).toBeVisible({ timeout: 30_000 }); - await expect - .poll(async () => { + try { + await expect + .poll(async () => { const text = await detailPanel.innerText().catch(() => ""); if (text.includes("状态:available")) return "available"; if (text.includes("状态:ocr_failed")) return "ocr_failed"; return "pending_ocr"; - }, { timeout }) - .not.toBe("pending_ocr"); + }, { timeout }) + .toMatch(/^(available|ocr_failed)$/); + } catch (error) { + const detailText = await detailPanel.innerText().catch(() => ""); + const bannerText = await page.getByTestId("invoice-ocr-status-banner").innerText().catch(() => ""); + const invoiceId = extractField(detailText, "票据ID:"); + throw new Error( + [ + "live 腾讯 OCR 等待终态超时", + `invoiceId=${invoiceId ?? "unknown"}`, + `timeoutMs=${timeout}`, + `detail=${detailText || ""}`, + `banner=${bannerText || ""}`, + `cause=${error instanceof Error ? error.message : String(error)}`, + ].join("\n"), + ); + } const detailText = await detailPanel.innerText(); const bannerText = await page.getByTestId("invoice-ocr-status-banner").innerText().catch(() => ""); diff --git a/client/tests/e2e/manual/live-invoice-ocr.spec.ts b/client/tests/e2e/manual/live-invoice-ocr.spec.ts index 3c452a9b..d704ca12 100644 --- a/client/tests/e2e/manual/live-invoice-ocr.spec.ts +++ b/client/tests/e2e/manual/live-invoice-ocr.spec.ts @@ -19,8 +19,9 @@ test("手工 live 腾讯 OCR 辅助复核:真实 VAT 发票上传后进入可 throw new Error(`live 腾讯 OCR 失败:${result.bannerText || result.detailText}`); } - await expect(page.getByTestId("invoice-detail-panel")).not.toContainText("发票号:---"); - await expect(page.getByTestId("invoice-detail-panel")).not.toContainText("总金额:-"); + expect(result.invoiceCode ?? result.invoiceNumber, JSON.stringify(result)).toBeTruthy(); + expect(result.totalAmount, JSON.stringify(result)).toBeTruthy(); + expect(result.totalAmount, JSON.stringify(result)).not.toBe("-"); await logout(page, EMPLOYEE.name); });