forked from longtao.wu/droboticflow
82 lines
2.6 KiB
JavaScript
82 lines
2.6 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import test from "node:test";
|
|
|
|
import {
|
|
getPluginNavigationContributions,
|
|
getPluginPrimaryNavigationContributions,
|
|
matchesPluginNavigationPath,
|
|
resolvePluginNavigationRole,
|
|
} from "../../src/lib/plugin-navigation.js";
|
|
|
|
const annotationStatus = {
|
|
enabled: true,
|
|
manifest: {
|
|
id: "annotation-qa",
|
|
navigation: [
|
|
{
|
|
id: "quality",
|
|
label: "审核",
|
|
path: "/quality",
|
|
order: 20,
|
|
groupId: "annotation-center",
|
|
groupLabel: "标注中心",
|
|
requiredRoles: ["admin", "quality_reviewer"],
|
|
},
|
|
{
|
|
id: "annotate",
|
|
label: "标注",
|
|
path: "/annotate",
|
|
order: 10,
|
|
groupId: "annotation-center",
|
|
groupLabel: "标注中心",
|
|
requiredRoles: ["admin", "annotator"],
|
|
},
|
|
],
|
|
},
|
|
};
|
|
|
|
test("plugin navigation appears only after installation and respects roles", () => {
|
|
assert.deepEqual(getPluginNavigationContributions([{ ...annotationStatus, enabled: false }], "admin"), []);
|
|
assert.deepEqual(
|
|
getPluginNavigationContributions([annotationStatus], "annotator").map((item) => item.id),
|
|
["annotate"],
|
|
);
|
|
assert.deepEqual(
|
|
getPluginNavigationContributions([annotationStatus], "admin").map((item) => item.id),
|
|
["annotate", "quality"],
|
|
);
|
|
});
|
|
|
|
test("plugin workbench stages collapse to one role-aware primary entry", () => {
|
|
const adminItems = getPluginPrimaryNavigationContributions([annotationStatus], "admin");
|
|
assert.deepEqual(
|
|
adminItems.map((item) => [item.label, item.path]),
|
|
[["标注中心", "/annotate"]],
|
|
);
|
|
assert.deepEqual(adminItems[0].matchPaths, ["/annotate", "/quality"]);
|
|
assert.deepEqual(
|
|
getPluginPrimaryNavigationContributions([annotationStatus], "quality_reviewer").map((item) => [
|
|
item.label,
|
|
item.path,
|
|
]),
|
|
[["标注中心", "/quality"]],
|
|
);
|
|
});
|
|
|
|
test("grouped plugin primary entry stays active on every contributed stage route", () => {
|
|
assert.equal(
|
|
matchesPluginNavigationPath(
|
|
"/plugins/annotation-qa/workflows/workflow-1/quality",
|
|
"/plugins/annotation-qa/workflows/all/quality",
|
|
),
|
|
true,
|
|
);
|
|
assert.equal(matchesPluginNavigationPath("/plugins/another-plugin/workflows/workflow-1/quality", "/quality"), false);
|
|
});
|
|
|
|
test("plugin navigation preserves legacy role compatibility", () => {
|
|
assert.equal(resolvePluginNavigationRole("data_operator"), "annotator");
|
|
assert.equal(resolvePluginNavigationRole("qa_reviewer"), "quality_reviewer");
|
|
assert.equal(resolvePluginNavigationRole("pipeline_engineer"), "admin");
|
|
});
|