droboticflow/tests/frontend/annotation-five-rules.test.mjs

41 lines
2.3 KiB
JavaScript

import test from "node:test";
import assert from "node:assert/strict";
import fs from "node:fs";
import { sliceDictionaryNameIssue } from "../../src/lib/annotation-workbench.js";
const read = (path) => fs.readFileSync(new URL("../../" + path, import.meta.url), "utf8");
test("same dictionary name may be selected by multiple slices", () => {
const items = [{ id: "n", name: "拿取商品" }];
assert.equal(sliceDictionaryNameIssue([{ name: "拿取商品" }, { name: "拿取商品" }], items), "");
assert.ok(sliceDictionaryNameIssue([{ name: "自定义" }], items));
assert.ok(sliceDictionaryNameIssue([{ name: "拿取商品" }], []));
assert.ok(sliceDictionaryNameIssue([{ name: "拿取商品" }], items, true));
});
test("slice names are selection-only", () => {
const ui = read("src/components/CaptureAnnotationWorkbench.tsx"),
picker = read("src/components/SliceNameDictionaryPicker.tsx");
// The name is static text now; real-browser coverage verifies that clicking
// it retains workbench shortcuts without enabling free-form name editing.
assert.doesNotMatch(ui, /onSliceNameChange\?\.\(.*(?:event|e)\.target\.value/);
assert.doesNotMatch(picker, /填入后仍可修改|可直接输入名称/);
});
test("three roles hide release controls while counts remain anonymous", () => {
const page = read("src/pages/AnnotationOperations.tsx"),
final = read("src/components/FinalAcceptanceWorkspace.tsx");
assert.match(
page,
/const releaseLocked = role === "annotator" \|\| role === "quality_reviewer" \|\| role === "acceptance_reviewer"/,
);
assert.match(page, /onRelease=\{releaseLocked \? undefined/);
assert.match(final, /onRelease \?/);
assert.match(page, /claimableCount.count \?\? "—"/);
assert.match(page, /setHumanPools\(\{ available: \[\], mine, all: \[\] \}\)/);
});
test("discarded slices do not require names or a naming dictionary", () => {
const discarded = { name: "切片 001", deliveryDisposition: "discard" };
assert.equal(sliceDictionaryNameIssue([discarded], [], true, "unavailable"), "");
assert.equal(sliceDictionaryNameIssue([discarded, { name: "拿取商品" }], [{ name: "拿取商品" }]), "");
assert.ok(sliceDictionaryNameIssue([discarded, { name: "切片 002" }], [{ name: "拿取商品" }]));
assert.ok(sliceDictionaryNameIssue([{ ...discarded, deliveryDisposition: "keep" }], [{ name: "拿取商品" }]));
});