Complete platform management workflows

This commit is contained in:
npc0-hue
2026-07-14 16:39:37 +08:00
parent 7e05d0a4e7
commit 4f33f761a3
106 changed files with 11313 additions and 460 deletions
+101
View File
@@ -0,0 +1,101 @@
import { renderToStaticMarkup } from "react-dom/server";
import { describe, expect, it } from "vitest";
import { UsersPage } from "./UsersPage";
import type { UserResponse } from "../api/types";
import type { PageComponentProps } from "../contracts/page";
import { capabilitiesForRoles, type CurrentUserView } from "../contracts/workspace";
import type { OperationTracker } from "../stores/operations";
const adminUser: CurrentUserView = {
id: "user-admin",
displayName: "Operator",
status: "active",
roles: ["platformAdmin"],
capabilities: capabilitiesForRoles(["platformAdmin"]),
profile: {},
source: "local"
};
const serverUser: CurrentUserView = {
...adminUser,
id: "user-server",
roles: ["serverAdmin"],
capabilities: capabilitiesForRoles(["serverAdmin"])
};
const managedUser: UserResponse = {
id: "user-reviewer",
displayName: "Plugin Reviewer",
email: "reviewer@example.test",
status: "pending",
roles: ["server-admin"],
profile: { phone: "13800000000", qq: "10001", contactNote: "needs approval" },
createdAt: "2026-07-03T00:00:00Z",
updatedAt: "2026-07-03T00:00:00Z"
};
const noopOperations: OperationTracker = {
operations: [],
begin: () => "op-test",
update: () => undefined,
succeed: () => undefined,
fail: () => undefined,
isPending: () => false
};
function pageProps(session = adminUser): PageComponentProps {
return {
session,
params: {},
operations: noopOperations,
onNavigate: () => undefined,
onLogout: async () => undefined,
onProfileSave: async () => session,
onThemePreferenceSave: async () => ({ userId: session.id, paletteId: "mecha-black", backgroundPresetId: "mecha-grid", persistence: "api", updatedAt: "2026-07-03T00:00:00Z" })
};
}
describe("UsersPage", () => {
it("renders an empty API-backed state without local users", () => {
const html = renderToStaticMarkup(<UsersPage {...pageProps()} initialState={{ users: [], loading: false, source: "api" }} />);
expect(html).toContain("暂无用户");
expect(html).toContain("page-summary-chip");
expect(html).not.toContain("metric-card");
expect(html).not.toContain("Plugin Reviewer");
});
it("renders explicit local-development fixture state with a single status flow", () => {
const html = renderToStaticMarkup(<UsersPage {...pageProps()} initialState={{ users: [managedUser], loading: false, source: "local-development" }} />);
expect(html).toContain("Plugin Reviewer");
expect(html).toContain("本地开发样例 / 禁止假成功");
expect(html).toContain("编辑");
expect(html).toContain("状态");
expect(html).toContain("应用状态");
expect(html).toContain("停用");
expect(html).toContain("邀请用户");
expect(html).toContain("审核申请");
expect(html).toContain("绑定服务器范围");
expect(html).toContain("角色影响");
expect(html).toContain("needs approval");
});
it("does not render create or edit forms inline on the list page", () => {
const html = renderToStaticMarkup(<UsersPage {...pageProps()} initialState={{ users: [managedUser], loading: false, source: "api" }} />);
expect(html).toContain("访问列表");
expect(html).toContain("邀请用户");
expect(html).not.toContain('role="dialog"');
expect(html).not.toContain('aria-label="编辑用户"');
});
it("does not render account maintenance controls for non-admins", () => {
const html = renderToStaticMarkup(<UsersPage {...pageProps(serverUser)} initialState={{ users: [managedUser], loading: false, source: "api" }} />);
expect(html).toContain("当前账号不能管理用户");
expect(html).not.toContain("邀请用户");
expect(html).not.toContain("停用");
});
});