import assert from "node:assert/strict"; import "./DeploymentResult.test.js"; import "./DashboardLogout.test.js"; import "./DomainModal.test.js"; import "./DomainForm.test.js"; import test from "node:test"; import { nextTick, ref } from "vue"; import { useDashboard } from "./Dashboard.js"; import { useDashboardNavigation } from "./DashboardNavigation.js"; import { summarizeRuntime, runtimeTime, useRuntimeOverview } from "./RuntimeOverview.js"; import { aliyunProvider, deferred, mountComposable, verifiedResponse } from "../../test-support/mount.js"; test("管理页面使用拆分后的域名表单与同项目服务器候选", async (t) => { const requests = []; const item = { id: "domain-form", name: "example.test", project_id: "default" }; const server = { id: "server-form", name: "共享服务器", project_id: "default" }; const { state } = await mountComposable(t, useDashboard, async (path, options = {}) => { if (options.method) { requests.push({ path, ...options }); return Response.json(path.endsWith("/servers") ? { items: [server] } : item); } if (path === "/api/v1/servers") return Response.json({ items: [server, { id: "other", project_id: "other" }] }); return Response.json({ items: [] }); }); state.openCreate(); assert.deepEqual(state.domainServerOptions.value, [server]); state.form.value.name = item.name; state.form.value.server_ids = [server.id]; await state.saveDomain(); assert.deepEqual(requests.map(({ method }) => method), ["POST", "PUT"]); assert.equal(requests[1].path, `/api/v1/domains/${item.id}/servers`); assert.deepEqual(JSON.parse(requests[1].body), { server_ids: [server.id] }); assert.equal(state.showForm.value, false); }); test("板块导航默认只选中基本信息,超级管理员可切换全部板块", () => { const navigation = useDashboardNavigation(ref({ role: "super_admin" })); assert.equal(navigation.activeSection.value, "overview"); assert.equal(navigation.sections.value.length, 7); for (const section of navigation.sections.value) { navigation.selectSection(section.id); assert.equal(navigation.activeSection.value, section.id); assert.equal(navigation.activeLabel.value, section.label); } navigation.selectSection("invalid"); assert.equal(navigation.activeSection.value, "users"); }); test("用户管理导航按权限显示,权限变化后回到基本信息", () => { const user = ref(null); const navigation = useDashboardNavigation(user); assert.equal(navigation.sections.value.some((section) => section.id === "users"), false); navigation.selectSection("users"); assert.equal(navigation.activeSection.value, "overview"); user.value = { role: "super_admin" }; navigation.selectSection("users"); assert.equal(navigation.activeSection.value, "users"); user.value = { role: "admin" }; assert.equal(navigation.activeSection.value, "users"); assert.equal(navigation.sections.value.length, 7); user.value = null; assert.equal(navigation.activeSection.value, "overview"); assert.equal(navigation.sections.value.length, 5); }); test("单板块布局使用互斥条件,切换重置滚动且保留弹窗入口", async () => { const { readFile } = await import("node:fs/promises"); const template = await readFile(new URL("./Dashboard.vue", import.meta.url), "utf8"); const stylesheet = await readFile(new URL("./DashboardLayout.css", import.meta.url), "utf8"); for (const id of ["overview", "activity", "projects", "domains", "servers", "dns-accounts", "users"]) { assert.ok(template.includes(`v-if="activeSection === '${id}'"`)); } assert.match(template, /:key="activeSection"/); assert.match(template, /role="region"\s+:aria-label="activeLabel"\s+tabindex="0"/); for (const modal of ["SettingsModal", "DomainModal", "ServerModal"]) { assert.ok(template.includes(`<${modal} v-if=`)); } assert.match(stylesheet, /height: 100dvh/); assert.match(stylesheet, /\.dashboard-content\s*\{[^}]*overflow: auto/); }); test("侧栏支持键盘焦点、当前项标记和悬浮说明", async () => { const { readFile } = await import("node:fs/promises"); const template = await readFile(new URL("./DashboardNavigation.vue", import.meta.url), "utf8"); const stylesheet = await readFile(new URL("./DashboardNavigation.css", import.meta.url), "utf8"); assert.match(template, /