89 lines
3.8 KiB
TypeScript
89 lines
3.8 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { getHandler } from "../engine/registry";
|
|
import type { CatalogComponent, FlowNode } from "../../shared/types";
|
|
import type { RunContext } from "../engine/types";
|
|
import "./ocr-caps";
|
|
import "./remaining-core";
|
|
|
|
const ctx = {
|
|
signal: new AbortController().signal,
|
|
log: () => {},
|
|
vars: {},
|
|
evidenceDir: "D:/office-test2/ocr-test"
|
|
} as unknown as RunContext;
|
|
|
|
const node = { id: "smoke", componentId: "smoke", position: { x: 0, y: 0 }, values: {}, options: {} };
|
|
|
|
async function runOcr(id: string, args: Record<string, unknown>) {
|
|
const handler = getHandler(id);
|
|
expect(handler, `${id} 应已注册`).toBeTruthy();
|
|
return handler!(ctx, node, args, {} as CatalogComponent);
|
|
}
|
|
|
|
describe("OCR 组件冒烟(本地离线识别,真实模型推理)", () => {
|
|
it("OCR_GeneralTextV2 通用文本", async () => {
|
|
const out = await runOcr("OCR_GeneralTextV2", { path: "D:/office-test2/ocr-test/general.png" });
|
|
console.log("[GeneralTextV2]", JSON.stringify(out));
|
|
expect(String(out)).toContain("张三");
|
|
}, 300000);
|
|
|
|
it("OCR_KeyValueIdentification 键值对", async () => {
|
|
const out = await runOcr("OCR_KeyValueIdentification", { image_path: "D:/office-test2/ocr-test/general.png" });
|
|
console.log("[KeyValue]", JSON.stringify(out));
|
|
expect(String(out).length).toBeGreaterThan(0);
|
|
}, 300000);
|
|
|
|
it("OCR_AmountIdentification 金额", async () => {
|
|
const out = await runOcr("OCR_AmountIdentification", { path: "D:/office-test2/ocr-test/general.png" });
|
|
console.log("[Amount]", JSON.stringify(out));
|
|
expect(String(out).length).toBeGreaterThan(0);
|
|
}, 300000);
|
|
|
|
it("OCR_CalculationCode 算术验证码", async () => {
|
|
const out = await runOcr("OCR_CalculationCode", { path: "D:/office-test2/ocr-test/code.png" });
|
|
console.log("[CalcCode]", JSON.stringify(out));
|
|
expect(String(out).length).toBeGreaterThan(0);
|
|
}, 300000);
|
|
|
|
it("OCR_CommonEnglishNumbersCode 普通验证码", async () => {
|
|
const out = await runOcr("OCR_CommonEnglishNumbersCode", { path: "D:/office-test2/ocr-test/code.png" });
|
|
console.log("[CommonCode]", JSON.stringify(out));
|
|
expect(String(out).length).toBeGreaterThan(0);
|
|
}, 300000);
|
|
|
|
it("OCR_IdCardV2 卡证族代表", async () => {
|
|
const out = await runOcr("OCR_IdCardV2", { path: "D:/office-test2/ocr-test/general.png" });
|
|
console.log("[IdCardV2]", JSON.stringify(out));
|
|
expect(String(out).length).toBeGreaterThan(0);
|
|
}, 300000);
|
|
|
|
it("OCR_VatInvoiceV2 票据族代表", async () => {
|
|
const out = await runOcr("OCR_VatInvoiceV2", { path: "D:/office-test2/ocr-test/table.png" });
|
|
console.log("[VatInvoiceV2]", JSON.stringify(out));
|
|
expect(String(out).length).toBeGreaterThan(0);
|
|
}, 300000);
|
|
|
|
it("OcrOffline_GetOcrTextNew 离线文本", async () => {
|
|
const out = await runOcr("OcrOffline_GetOcrTextNew", { uiSelector: "D:/office-test2/ocr-test/general.png" });
|
|
console.log("[OcrTextNew]", JSON.stringify(out));
|
|
expect(String(out)).toContain("订单号");
|
|
}, 300000);
|
|
|
|
it("OcrOffline_GetOcrTextPosition 离线定位", async () => {
|
|
const out = await runOcr("OcrOffline_GetOcrTextPosition", { image_path: "D:/office-test2/ocr-test/general.png" });
|
|
const words = out as Array<{ text: string; x: number; y: number }>;
|
|
console.log("[OcrPosition]", JSON.stringify(words?.slice(0, 3)));
|
|
expect(Array.isArray(words)).toBe(true);
|
|
expect(words.length).toBeGreaterThan(0);
|
|
expect(words[0]).toHaveProperty("x");
|
|
}, 300000);
|
|
|
|
it("OcrOffline_GetOcrTable 离线表格", async () => {
|
|
const out = await runOcr("OcrOffline_GetOcrTable", { image_path: "D:/office-test2/ocr-test/table.png", showTable: "1", isExcel: "0" });
|
|
const rows = out as string[][];
|
|
console.log("[OcrTable]", JSON.stringify(rows));
|
|
expect(Array.isArray(rows)).toBe(true);
|
|
expect(rows.length).toBeGreaterThan(0);
|
|
}, 300000);
|
|
});
|