45 lines
1.2 KiB
JavaScript
45 lines
1.2 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import { readFileSync } from "node:fs";
|
|
import { dirname, resolve } from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
import ts from "typescript";
|
|
|
|
const testDir = dirname(fileURLToPath(import.meta.url));
|
|
const sourcePath = resolve(testDir, "../src/widgets/role-navigation/model.ts");
|
|
const source = readFileSync(sourcePath, "utf8");
|
|
const transpiled = ts.transpileModule(source, {
|
|
compilerOptions: {
|
|
module: ts.ModuleKind.CommonJS,
|
|
target: ts.ScriptTarget.ES2022,
|
|
},
|
|
});
|
|
|
|
const exports = {};
|
|
new Function("exports", transpiled.outputText)(exports);
|
|
|
|
const editorItems = exports.getRoleNavigationItems("EDITOR");
|
|
const adminItems = exports.getRoleNavigationItems("ADMIN");
|
|
|
|
assert.deepEqual(
|
|
editorItems.map((item) => item.id),
|
|
["dashboard", "new-article", "review"],
|
|
);
|
|
assert.equal(
|
|
editorItems.some((item) => item.id === "site-config" || item.id === "script-versions"),
|
|
false,
|
|
);
|
|
assert.equal(
|
|
adminItems.some((item) => item.id === "site-config"),
|
|
true,
|
|
);
|
|
assert.equal(
|
|
adminItems.some((item) => item.id === "script-versions"),
|
|
true,
|
|
);
|
|
assert.equal(
|
|
adminItems.some((item) => item.id === "agent-jobs"),
|
|
true,
|
|
);
|
|
|
|
console.log("role navigation hides Admin-only items for Editors");
|