feat: 全局设置系统 — settings 表、CRUD 路由、主题偏好持久化

This commit is contained in:
2026-06-05 23:10:32 +08:00
parent e2eba6dc1f
commit 3f88e33bd1
23 changed files with 652 additions and 54 deletions

View File

@@ -0,0 +1,61 @@
import { screen, waitFor } from "@testing-library/react";
import { describe, expect, test } from "bun:test";
import { createElement } from "react";
import { SettingsPage } from "../../../../src/web/features/settings/index";
import { installFetchMock, jsonResponse, renderWithProviders } from "../../test-utils";
function mockSettingsResponse(theme = "system"): Response {
return jsonResponse({ theme });
}
describe("SettingsPage", () => {
test("渲染主题卡片", () => {
installFetchMock((call) => {
if (call.url.includes("/api/settings")) return mockSettingsResponse();
return jsonResponse({});
});
renderWithProviders(createElement(SettingsPage));
expect(screen.getByText("主题")).not.toBeNull();
});
test("渲染主题 Segmented 选项", () => {
installFetchMock((call) => {
if (call.url.includes("/api/settings")) return mockSettingsResponse();
return jsonResponse({});
});
renderWithProviders(createElement(SettingsPage));
expect(screen.getByText("系统")).not.toBeNull();
expect(screen.getByText("明亮")).not.toBeNull();
expect(screen.getByText("黑暗")).not.toBeNull();
});
test("API 加载中时不显示保存状态", () => {
installFetchMock((call) => {
if (call.url.includes("/api/settings")) return mockSettingsResponse();
return jsonResponse({});
});
renderWithProviders(createElement(SettingsPage));
expect(screen.queryByText("保存中...")).toBeNull();
});
test("GET /api/settings 获取已保存主题", async () => {
installFetchMock((call) => {
if (call.url.includes("/api/settings")) return mockSettingsResponse("dark");
return jsonResponse({});
});
renderWithProviders(createElement(SettingsPage));
await waitFor(() => {
const segmented = document.querySelector(".ant-segmented");
expect(segmented).not.toBeNull();
});
});
});