37 lines
1.9 KiB
JavaScript
37 lines
1.9 KiB
JavaScript
import { readFileSync } from "node:fs";
|
|
import assert from "node:assert/strict";
|
|
import test from "node:test";
|
|
|
|
test("dictionary panel wires export, bulk import and batch remove for admins", () => {
|
|
const panel = readFileSync("src/components/AnnotationLabelsPanel.tsx", "utf8");
|
|
// Bulk import posts to the dedicated endpoint with the panel's dictionary kind.
|
|
assert.ok(panel.includes("/dictionary-labels/import"));
|
|
assert.ok(panel.includes("names: parsedImport.names"));
|
|
// Export serializes through the shared CSV helper with a BOM for Excel.
|
|
assert.ok(panel.includes("serializeDictionaryCSV"));
|
|
assert.ok(panel.includes("导出 CSV"));
|
|
// Batch remove reuses the authoritative project selection PUT, never org-wide deletes.
|
|
assert.ok(panel.includes("删除所选"));
|
|
assert.ok(panel.includes("labelIds: nextEnabled"));
|
|
// Import preview classifies names before submit and disables the button when empty.
|
|
assert.ok(panel.includes("importPlan.toImport.length"));
|
|
assert.ok(panel.includes("planDictionaryImport"));
|
|
});
|
|
|
|
test("dictionary batch routes stay admin-gated on the server", () => {
|
|
const routes = readFileSync("internal/api/routes_annotation.go", "utf8");
|
|
const sharedRoutes = readFileSync("internal/api/routes.go", "utf8");
|
|
const handler = readFileSync("internal/api/annotation_labels_import.go", "utf8");
|
|
assert.ok(
|
|
routes.includes(
|
|
'admin.Post("/api/projects/{id}/dictionary-labels/import", server.handleProjectDictionaryLabelsImport)',
|
|
),
|
|
);
|
|
// The route uses the admin-only router AND the handler re-checks the role.
|
|
assert.match(routes, /admin := server\.withRoles\(router, rolesAdmin\.\.\.\)/);
|
|
assert.match(sharedRoutes, /rolesAdmin = \[\]domain\.UserRole\{domain\.UserRoleAdmin\}/);
|
|
assert.match(sharedRoutes, /return router\.With\(server\.requireBusinessRole\(roles\.\.\.\)\)/);
|
|
assert.ok(handler.includes("if !annotationManager(principal)"));
|
|
assert.ok(handler.includes("dictionaryImportMaxNames"));
|
|
});
|