Files
boss/tests/admin-refine-page.test.ts

69 lines
2.7 KiB
TypeScript

import test from "node:test";
import assert from "node:assert/strict";
import { readFile } from "node:fs/promises";
const adminPagePath = new URL("../src/app/admin/page.tsx", import.meta.url);
const adminAppPath = new URL("../src/components/admin/boss-admin-app.tsx", import.meta.url);
const dataProviderPath = new URL("../src/components/admin/boss-admin-data-provider.ts", import.meta.url);
async function readSource(path: URL) {
return readFile(path, "utf8");
}
test("/admin page gates the refine shell behind highest_admin", async () => {
const source = await readSource(adminPagePath);
assert.match(source, /requirePageSession/);
assert.match(source, /BossAdminApp/);
assert.match(source, /session\.role\s*!==\s*["']highest_admin["']/);
assert.match(source, /仅最高管理员可用/);
});
test("BossAdminApp wires refine resources and enterprise overview sections", async () => {
const source = await readSource(adminAppPath);
assert.match(source, /['"]use client['"]/);
assert.doesNotMatch(source, /@refinedev\/antd/);
assert.match(source, /Refine/);
assert.match(source, /@refinedev\/core/);
assert.match(source, /ConfigProvider/);
assert.match(source, /Table/);
assert.match(source, /Alert/);
for (const resource of ["companies", "accounts", "devices", "risks", "auditLogs"]) {
assert.match(source, new RegExp(`name:\\s*["']${resource}["']`));
}
for (const title of ["平台运营驾驶舱", "客户与账号", "授权工作台", "风险与治理"]) {
assert.match(source, new RegExp(title));
}
for (const title of ["今日待处理", "客户健康排行", "关键风险队列", "节点健康", "最近事件"]) {
assert.match(source, new RegExp(title));
}
for (const riskAction of ["assign_owner", "set_sla", "负责人", "SLA"]) {
assert.match(source, new RegExp(riskAction));
}
assert.doesNotMatch(source, /window\.prompt/);
});
test("BossAdminApp uses the approved PC To B admin shell", async () => {
const source = await readSource(adminAppPath);
assert.match(source, /adminShell/);
assert.match(source, /adminSidebar/);
assert.match(source, /adminHeader/);
assert.match(source, /currentSubtitle/);
assert.match(source, /bg-\[#F3F5F2\]/);
assert.match(source, /highest_admin/);
assert.match(source, /开放风险/);
assert.match(source, /风险通知/);
});
test("admin data provider reads the overview endpoint and supports initialOverview", async () => {
const appSource = await readSource(adminAppPath);
const providerSource = await readSource(dataProviderPath);
assert.match(appSource, /initialOverview/);
assert.doesNotMatch(providerSource, /@refinedev\/antd/);
assert.match(providerSource, /\/api\/v1\/admin\/overview/);
assert.match(providerSource, /initialOverview/);
});