droboticflow/tests/frontend/plugin-page-subnav.test.mjs
2026-09-29 04:58:53 -07:00

121 lines
5.8 KiB
JavaScript

import assert from "node:assert/strict";
import { readFile } from "node:fs/promises";
import test from "node:test";
const source = async (path) => readFile(new URL(`../../${path}`, import.meta.url), "utf8");
test("plugin management is a dedicated admin page", async () => {
const [app, sidebar, settings, plugins] = await Promise.all([
source("src/App.tsx"),
source("src/components/Sidebar.tsx"),
source("src/pages/Settings.tsx"),
source("src/pages/Plugins.tsx"),
]);
assert.match(app, /path="\/plugins" element={<Plugins \/>}/);
assert.match(sidebar, /label: "插件管理", path: "\/plugins"/);
assert.match(sidebar, /end=\{item\.path === "\/plugins"\}/);
assert.doesNotMatch(settings, /PluginSettingsPanel/);
assert.match(plugins, /<PluginSettingsPanel \/>/);
assert.match(plugins, /primaryNavigationCount/);
assert.match(plugins, /一级入口/);
assert.match(plugins, /status\.manifest\.operatorIds\?\.length/);
});
test("only pages with real internal views render secondary navigation", async () => {
const tabbedPaths = [
"src/pages/Projects.tsx",
"src/pages/ProjectDetail.tsx",
"src/pages/DataAssets.tsx",
"src/pages/ObjectStorageBrowser.tsx",
"src/pages/DataOperations.tsx",
"src/pages/ObjectSync.tsx",
"src/pages/Monitoring.tsx",
"src/pages/Runs.tsx",
"src/pages/Settings.tsx",
"src/pages/Plugins.tsx",
"src/pages/AnnotationOperations.tsx",
"src/pages/Audit.tsx",
];
const tabbedPages = await Promise.all(tabbedPaths.map(source));
for (const [index, page] of tabbedPages.entries()) {
assert.match(page, /<PageSubnav[\s/>]/, `${tabbedPaths[index]} should render internal secondary navigation`);
}
const untabbedPaths = [
"src/pages/Dashboard.tsx",
"src/pages/Templates.tsx",
"src/pages/Operators.tsx",
"src/pages/DatabaseBrowser.tsx",
"src/pages/Users.tsx",
"src/pages/Sampling.tsx",
];
const untabbedPages = await Promise.all(untabbedPaths.map(source));
for (const [index, page] of untabbedPages.entries()) {
assert.doesNotMatch(page, /<PageSubnav[\s/>]/, `${untabbedPaths[index]} must not render a fake one-item tab`);
}
});
test("annotation stages are secondary navigation under one primary center", async () => {
const annotation = await source("src/pages/AnnotationOperations.tsx");
const sidebar = await source("src/components/Sidebar.tsx");
assert.match(annotation, /getPluginNavigationContributions\(pluginStatuses, role\)/);
assert.match(annotation, /items={annotationStageTabs}/);
assert.match(annotation, /aria-label="当前工作台视图"/);
assert.match(annotation, /<option value="queue">{queueTabLabel}<\/option>/);
assert.match(annotation, /<option value="workload">工作记录<\/option>/);
assert.match(sidebar, /getPluginPrimaryNavigationContributions\(pluginStatuses, role\)/);
assert.doesNotMatch(annotation, /Annotation Operations|标注中心(人工标注)工作台/);
assert.doesNotMatch(annotation, /data-testid="role-workbenches"/);
});
test("secondary navigation exposes an active page state", async () => {
const component = await source("src/components/PageSubnav.tsx");
const groups = await source("src/lib/page-subnav.ts");
assert.match(component, /aria-current={active \? "page" : undefined}/);
assert.match(component, /dark:border-blue-500 dark:text-blue-300/);
assert.match(component, /if \(item\.onSelect\)/);
assert.match(component, /compact \? "mt-2 min-h-8"/);
assert.match(groups, /label: "插件目录", to: "\/plugins#catalog"/);
assert.match(groups, /label: "AI 与算子", to: "\/settings#ai"/);
assert.doesNotMatch(groups, /label: "项目", to: "\/projects"/);
assert.doesNotMatch(groups, /label: "工作流", to: "\/templates"/);
});
test("layout removes the redundant product header and keeps only a compact health control", async () => {
const layout = await source("src/components/Layout.tsx");
assert.doesNotMatch(layout, /Drobodata Platform|<Logo|from "\.\/Logo"/);
assert.doesNotMatch(layout, /<header className=/);
assert.match(layout, /group absolute right-3 top-3 z-40/);
assert.match(layout, /flex h-8 w-8 cursor-pointer/);
assert.match(layout, /flex-1 overflow-auto p-4 md:p-6/);
});
test("project page tabs filter project views instead of repeating primary navigation", async () => {
const projects = await source("src/pages/Projects.tsx");
assert.match(projects, /label: "全部项目"[\s\S]*setStatusFilter\("all"\)/);
assert.match(projects, /label: "进行中"[\s\S]*setStatusFilter\("active"\)/);
assert.match(projects, /label: "已归档"[\s\S]*setStatusFilter\("archived"\)/);
assert.doesNotMatch(projects, /items={workflowSubnav}/);
});
test("project detail separates released and debug workflows and opens released run history", async () => {
const detail = await source("src/pages/ProjectDetail.tsx");
assert.match(detail, /workflow\.definitionState === "released"/);
assert.match(detail, /label: `正式工作流 \(\$\{productionWorkflows\.length\}\)`/);
assert.match(detail, /label: `调试工作流 \(\$\{debugWorkflows\.length\}\)`/);
assert.match(detail, /label: runTotal > 0 \? `全部执行记录/);
assert.match(detail, /if \(workflow\.definitionState === "released"\) \{\s*void openRunHistoryModal\(workflow\)/);
assert.match(detail, /onClick=\{\(\) => openWorkflowCard\(wf\)\}/);
assert.match(detail, /wf\.definitionState === "released" \? "执行记录" : "编辑调试"/);
assert.match(detail, /void openRunModal\(wf\)/);
assert.match(detail, /wf\.definitionState === "released" \? "正式运行" : "调试运行"/);
assert.match(
detail,
/buildWorkflowEditorPath\(historyWorkflow\.id, \{\s*projectId: project\.id,\s*runId: run\.id,\s*readOnly: true,/,
);
assert.doesNotMatch(detail, /buildWorkflowEditorPath\(\{\s*workflowId:/);
assert.match(detail, /发起正式运行/);
});