refactor: 统一管理页面布局 — FilterToolbar + usePageSearchParams + parseListParams

This commit is contained in:
2026-06-04 17:25:36 +08:00
parent 61b479e2be
commit 6f547560d1
40 changed files with 1805 additions and 628 deletions

View File

@@ -131,6 +131,55 @@ describe("供应商 API 路由", () => {
});
});
test("GET /api/providers sortBy + sortOrder", async () => {
await withRouteDb(async (db) => {
createTestProvider(db, "Beta");
createTestProvider(db, "Alpha");
const req = new Request("http://localhost/api/providers?page=1&pageSize=20&sortBy=name&sortOrder=asc");
const res = await listProvidersViaHandler(req, db);
expect(res.status).toBe(200);
const body = (await res.json()) as { items: Provider[] };
expect(body.items[0]!.name).toBe("Alpha");
expect(body.items[1]!.name).toBe("Beta");
});
});
test("GET /api/providers filter by type", async () => {
await withRouteDb(async (db) => {
createTestProvider(db, "OpenAI Provider");
const compatResult = createProvider(
db,
{ apiKey: "sk-test", baseUrl: "https://compat.test.com", name: "Compat", type: "openai-compatible" },
LOG,
);
if ("error" in compatResult) throw new Error(compatResult.error);
const req = new Request("http://localhost/api/providers?page=1&pageSize=20&type=openai");
const res = await listProvidersViaHandler(req, db);
expect(res.status).toBe(200);
const body = (await res.json()) as { items: Provider[]; total: number };
expect(body.total).toBe(1);
expect(body.items[0]!.name).toBe("OpenAI Provider");
});
});
test("GET /api/providers rejects invalid sortBy", async () => {
await withRouteDb(async (db) => {
const req = new Request("http://localhost/api/providers?page=1&pageSize=20&sortBy=evil");
const res = await listProvidersViaHandler(req, db);
expect(res.status).toBe(400);
});
});
test("GET /api/providers rejects invalid sortOrder", async () => {
await withRouteDb(async (db) => {
const req = new Request("http://localhost/api/providers?page=1&pageSize=20&sortBy=name&sortOrder=invalid");
const res = await listProvidersViaHandler(req, db);
expect(res.status).toBe(400);
});
});
test("GET /api/providers/options 返回最小字段", async () => {
await withRouteDb(async (db) => {
createTestProvider(db, "选项供应商");