34 行
1.4 KiB
TypeScript
34 行
1.4 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { assignPaneOcr, type PaneOcrLine } from "./pane-ocr-service";
|
|
|
|
describe("pane OCR assignment", () => {
|
|
it("assigns OCR lines to the boxes containing their center", () => {
|
|
const lines: PaneOcrLine[] = [
|
|
{ text: "登录", confidence: 0.9, x: 12, y: 10, width: 24, height: 12 }
|
|
];
|
|
const boxes = [
|
|
{ candidateId: "button", x: 8, y: 6, width: 48, height: 24 },
|
|
{ candidateId: "container", x: 0, y: 0, width: 120, height: 80 }
|
|
];
|
|
expect(assignPaneOcr(lines, boxes)).toEqual({
|
|
button: { ocrText: "登录", ocrState: "done", ocrConfidence: 0.9 },
|
|
container: { ocrText: "登录", ocrState: "done", ocrConfidence: 0.9 }
|
|
});
|
|
});
|
|
|
|
it("uses a strongly overlapping line even when its center falls outside", () => {
|
|
const lines: PaneOcrLine[] = [
|
|
{ text: "保存", confidence: 0.8, x: 0, y: 10, width: 30, height: 12 }
|
|
];
|
|
const boxes = [{ candidateId: "button", x: 8, y: 8, width: 30, height: 16 }];
|
|
const result = assignPaneOcr(lines, boxes);
|
|
expect(result.button.ocrText).toBe("保存");
|
|
expect(result.button.ocrState).toBe("done");
|
|
});
|
|
|
|
it("marks boxes without text as empty", () => {
|
|
const result = assignPaneOcr([], [{ candidateId: "image", x: 0, y: 0, width: 20, height: 20 }]);
|
|
expect(result.image).toEqual({ ocrText: "", ocrState: "empty" });
|
|
});
|
|
});
|