import assert from "node:assert/strict"; import "./DeploymentResult.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("板块导航默认只选中基本信息,超级管理员可切换全部板块", () => { const navigation = useDashboardNavigation(ref({ role: "super_admin" })); assert.equal(navigation.activeSection.value, "overview"); assert.equal(navigation.sections.value.length, 6); 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, 6); 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", "domains", "servers", "keys", "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", "SSHKeyModal"]) { 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, /