95 lines
4.2 KiB
JavaScript
95 lines
4.2 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import { readFile } from "node:fs/promises";
|
|
import test from "node:test";
|
|
|
|
import { poolTabCounts } from "../../src/lib/annotation-workbench.js";
|
|
|
|
const operationsURL = new URL("../../src/pages/AnnotationOperations.tsx", import.meta.url);
|
|
|
|
// Fixtures mirror the customer scenario: the 可领取/我的任务 pools hold items
|
|
// whose derived status is NOT pending_acceptance, so the 「待验收」category
|
|
// matches none of them while the pools themselves are populated.
|
|
function reviewPoolsFixture() {
|
|
return {
|
|
available: [
|
|
{ id: "a1", currentStageId: "quality_review", status: "ready" },
|
|
{ id: "a2", currentStageId: "semantic_review", status: "ready" },
|
|
{ id: "a3", currentStageId: "quality_review", status: "submitted" },
|
|
],
|
|
mine: [
|
|
{ id: "m1", currentStageId: "quality_review", status: "claimed" },
|
|
{ id: "m2", currentStageId: "semantic_review", status: "in_progress" },
|
|
],
|
|
all: [
|
|
{ id: "a1", currentStageId: "quality_review", status: "ready" },
|
|
{ id: "a2", currentStageId: "semantic_review", status: "ready" },
|
|
{ id: "m1", currentStageId: "quality_review", status: "claimed" },
|
|
{ id: "x1", currentStageId: "split_annotation", status: "pending" },
|
|
],
|
|
reviewed: [{ id: "r1", currentStageId: "completed", status: "approved" }],
|
|
};
|
|
}
|
|
|
|
// Scope stage: mode visibility per pool, like humanItemVisibleInMode.
|
|
function reviewScope(item, pool) {
|
|
if (pool === "reviewed") return true;
|
|
return item.currentStageId === "quality_review" || item.currentStageId === "semantic_review";
|
|
}
|
|
|
|
// List stage: the 「待验收」category select under the claim-random area.
|
|
function pendingAcceptanceListFilter(item) {
|
|
return item.status === "pending_acceptance";
|
|
}
|
|
|
|
test("pool tab counts stay at pool totals while the 待验收 category empties its own list", () => {
|
|
const pools = reviewPoolsFixture();
|
|
const counts = poolTabCounts(pools, reviewScope);
|
|
|
|
// The category scopes only the task list below the tabs: it matches none of
|
|
// the pool items here, yet every upper pool count keeps its full value.
|
|
const listAfterCategory = pools.available.filter(
|
|
(item) => reviewScope(item, "available") && pendingAcceptanceListFilter(item),
|
|
);
|
|
assert.equal(listAfterCategory.length, 0);
|
|
assert.deepEqual(counts, { available: 3, mine: 2, all: 3, reviewed: 1 });
|
|
});
|
|
|
|
test("pool tab counts follow the scope stage, not the list filters", () => {
|
|
const pools = reviewPoolsFixture();
|
|
const narrowedScope = (item, pool) => item.id !== "a2" && reviewScope(item, pool);
|
|
|
|
// Dropping one in-scope item lowers exactly that pool's count; the list
|
|
// filters have no say in the tab totals.
|
|
assert.deepEqual(poolTabCounts(pools, narrowedScope), { available: 2, mine: 2, all: 2, reviewed: 1 });
|
|
// Missing pools count as 0 instead of crashing on sparse pool maps.
|
|
assert.deepEqual(poolTabCounts({ available: pools.available }, reviewScope), {
|
|
available: 3,
|
|
mine: 0,
|
|
all: 0,
|
|
reviewed: 0,
|
|
});
|
|
});
|
|
|
|
test("pool tab wiring keeps the category out of the counts and inside the task list", async () => {
|
|
const source = await readFile(operationsURL, "utf8");
|
|
|
|
// Counts derive from the scope stage only, through the shared helper.
|
|
assert.match(source, /poolTabCounts\(humanPools, matchesPoolScope\)/);
|
|
const countsStart = source.indexOf("const poolCounts");
|
|
const countsBlock = source.slice(countsStart, source.indexOf(");", countsStart) + 2);
|
|
assert.doesNotMatch(countsBlock, /taskStatusFilter|taskSearch/);
|
|
|
|
// The list keeps both stages: scope + panel filters (search + category).
|
|
assert.match(source, /const matchesPoolListFilters/);
|
|
assert.match(source, /matchesPoolScope\(item, pool\) && matchesPoolListFilters\(item\)/);
|
|
assert.match(source, /taskStatusFilter === "all" \|\| status === taskStatusFilter/);
|
|
|
|
// All three roles share the counted pool tabs (annotator / reviewer /
|
|
// acceptor render the same tabs, including the role-specific reviewed tab).
|
|
assert.match(source, /poolCounts\.available/);
|
|
assert.match(source, /poolCounts\.mine/);
|
|
assert.match(source, /poolCounts\.reviewed/);
|
|
assert.match(source, /poolCounts\.all/);
|
|
assert.match(source, /workspaceMode === "acceptance" \? "我已验收" : "我已审核"/);
|
|
});
|