fix: 修复测试套件质量审查问题——act环境、正则匹配、mock排序、超时设置
This commit is contained in:
@@ -46,34 +46,38 @@ function clickLatestConfirmButton() {
|
||||
}
|
||||
|
||||
describe("ModelFormModal", () => {
|
||||
test("编辑模型表单只提交变更字段", async () => {
|
||||
const updateCalls: unknown[] = [];
|
||||
test(
|
||||
"编辑模型表单只提交变更字段",
|
||||
async () => {
|
||||
const updateCalls: unknown[] = [];
|
||||
|
||||
renderWithProviders(
|
||||
createElement(ModelFormModal, {
|
||||
editingModel: ENABLED_MODEL,
|
||||
onCancel: () => undefined,
|
||||
onCreate: () => Promise.resolve(),
|
||||
onOpenChange: () => undefined,
|
||||
onUpdate: (args: unknown) => {
|
||||
updateCalls.push(args);
|
||||
return Promise.resolve();
|
||||
},
|
||||
open: true,
|
||||
providers: [ENABLED_PROVIDER, DISABLED_PROVIDER],
|
||||
providersError: null,
|
||||
providersLoading: false,
|
||||
submitting: false,
|
||||
}),
|
||||
);
|
||||
renderWithProviders(
|
||||
createElement(ModelFormModal, {
|
||||
editingModel: ENABLED_MODEL,
|
||||
onCancel: () => undefined,
|
||||
onCreate: () => Promise.resolve(),
|
||||
onOpenChange: () => undefined,
|
||||
onUpdate: (args: unknown) => {
|
||||
updateCalls.push(args);
|
||||
return Promise.resolve();
|
||||
},
|
||||
open: true,
|
||||
providers: [ENABLED_PROVIDER, DISABLED_PROVIDER],
|
||||
providersError: null,
|
||||
providersLoading: false,
|
||||
submitting: false,
|
||||
}),
|
||||
);
|
||||
|
||||
await screen.findByPlaceholderText("请输入模型名称");
|
||||
fireEvent.change(screen.getByPlaceholderText("请输入模型名称"), { target: { value: "GPT-4o Mini" } });
|
||||
clickLatestConfirmButton();
|
||||
await screen.findByPlaceholderText("请输入模型名称");
|
||||
fireEvent.change(screen.getByPlaceholderText("请输入模型名称"), { target: { value: "GPT-4o Mini" } });
|
||||
clickLatestConfirmButton();
|
||||
|
||||
await waitFor(() => expect(updateCalls.length).toBe(1));
|
||||
expect(updateCalls[0]).toEqual({ data: { name: "GPT-4o Mini" }, id: "m1" });
|
||||
});
|
||||
await waitFor(() => expect(updateCalls.length).toBe(1));
|
||||
expect(updateCalls[0]).toEqual({ data: { name: "GPT-4o Mini" }, id: "m1" });
|
||||
},
|
||||
{ timeout: 15000 },
|
||||
);
|
||||
|
||||
test("模型表单校验失败不会提交", async () => {
|
||||
const onCreate = mock(() => Promise.resolve());
|
||||
@@ -121,80 +125,92 @@ describe("ModelFormModal", () => {
|
||||
expect((reasoningCheckbox as { checked?: boolean }).checked).toBe(true);
|
||||
});
|
||||
|
||||
test("新建模型展示供应商 options 列表", async () => {
|
||||
renderWithProviders(
|
||||
createElement(ModelFormModal, {
|
||||
editingModel: null,
|
||||
onCancel: () => undefined,
|
||||
onCreate: () => Promise.resolve(),
|
||||
onOpenChange: () => undefined,
|
||||
onUpdate: () => Promise.resolve(),
|
||||
open: true,
|
||||
providers: [ENABLED_PROVIDER, DISABLED_PROVIDER],
|
||||
providersError: null,
|
||||
providersLoading: false,
|
||||
submitting: false,
|
||||
}),
|
||||
);
|
||||
test(
|
||||
"新建模型展示供应商 options 列表",
|
||||
async () => {
|
||||
renderWithProviders(
|
||||
createElement(ModelFormModal, {
|
||||
editingModel: null,
|
||||
onCancel: () => undefined,
|
||||
onCreate: () => Promise.resolve(),
|
||||
onOpenChange: () => undefined,
|
||||
onUpdate: () => Promise.resolve(),
|
||||
open: true,
|
||||
providers: [ENABLED_PROVIDER, DISABLED_PROVIDER],
|
||||
providersError: null,
|
||||
providersLoading: false,
|
||||
submitting: false,
|
||||
}),
|
||||
);
|
||||
|
||||
await screen.findByPlaceholderText("请输入模型名称");
|
||||
fireEvent.mouseDown(screen.getByRole("combobox"));
|
||||
await screen.findByPlaceholderText("请输入模型名称");
|
||||
fireEvent.mouseDown(screen.getByRole("combobox"));
|
||||
|
||||
expect(await screen.findByText("OpenAI")).not.toBeNull();
|
||||
expect(await screen.findByText("DeepSeek")).not.toBeNull();
|
||||
});
|
||||
expect(await screen.findByText("OpenAI")).not.toBeNull();
|
||||
expect(await screen.findByText("DeepSeek")).not.toBeNull();
|
||||
},
|
||||
{ timeout: 15000 },
|
||||
);
|
||||
|
||||
test("供应商下拉展示加载错误提示", async () => {
|
||||
renderWithProviders(
|
||||
createElement(ModelFormModal, {
|
||||
editingModel: null,
|
||||
onCancel: () => undefined,
|
||||
onCreate: () => Promise.resolve(),
|
||||
onOpenChange: () => undefined,
|
||||
onUpdate: () => Promise.resolve(),
|
||||
open: true,
|
||||
providers: [],
|
||||
providersError: new Error("options failed"),
|
||||
providersLoading: false,
|
||||
submitting: false,
|
||||
}),
|
||||
);
|
||||
test(
|
||||
"供应商下拉展示加载错误提示",
|
||||
async () => {
|
||||
renderWithProviders(
|
||||
createElement(ModelFormModal, {
|
||||
editingModel: null,
|
||||
onCancel: () => undefined,
|
||||
onCreate: () => Promise.resolve(),
|
||||
onOpenChange: () => undefined,
|
||||
onUpdate: () => Promise.resolve(),
|
||||
open: true,
|
||||
providers: [],
|
||||
providersError: new Error("options failed"),
|
||||
providersLoading: false,
|
||||
submitting: false,
|
||||
}),
|
||||
);
|
||||
|
||||
await screen.findByPlaceholderText("请输入模型名称");
|
||||
fireEvent.mouseDown(screen.getByRole("combobox"));
|
||||
await screen.findByPlaceholderText("请输入模型名称");
|
||||
fireEvent.mouseDown(screen.getByRole("combobox"));
|
||||
|
||||
expect(await screen.findByText("供应商加载失败:options failed")).not.toBeNull();
|
||||
});
|
||||
expect(await screen.findByText("供应商加载失败:options failed")).not.toBeNull();
|
||||
},
|
||||
{ timeout: 15000 },
|
||||
);
|
||||
|
||||
test("编辑模型时可测试模型连接", async () => {
|
||||
const testModelConnection = mock(() => Promise.resolve({ message: "模型连接成功", ok: true }));
|
||||
test(
|
||||
"编辑模型时可测试模型连接",
|
||||
async () => {
|
||||
const testModelConnection = mock(() => Promise.resolve({ message: "模型连接成功", ok: true }));
|
||||
|
||||
renderWithProviders(
|
||||
createElement(ModelFormModal, {
|
||||
editingModel: ENABLED_MODEL,
|
||||
onCancel: () => undefined,
|
||||
onCreate: () => Promise.resolve(),
|
||||
onOpenChange: () => undefined,
|
||||
onUpdate: () => Promise.resolve(),
|
||||
open: true,
|
||||
providers: [ENABLED_PROVIDER],
|
||||
providersError: null,
|
||||
providersLoading: false,
|
||||
submitting: false,
|
||||
testModelConnection,
|
||||
}),
|
||||
);
|
||||
renderWithProviders(
|
||||
createElement(ModelFormModal, {
|
||||
editingModel: ENABLED_MODEL,
|
||||
onCancel: () => undefined,
|
||||
onCreate: () => Promise.resolve(),
|
||||
onOpenChange: () => undefined,
|
||||
onUpdate: () => Promise.resolve(),
|
||||
open: true,
|
||||
providers: [ENABLED_PROVIDER],
|
||||
providersError: null,
|
||||
providersLoading: false,
|
||||
submitting: false,
|
||||
testModelConnection,
|
||||
}),
|
||||
);
|
||||
|
||||
await screen.findByRole("button", { name: "测试连接" });
|
||||
fireEvent.click(screen.getByRole("button", { name: "测试连接" }));
|
||||
await screen.findByRole("button", { name: "测试连接" });
|
||||
fireEvent.click(screen.getByRole("button", { name: "测试连接" }));
|
||||
|
||||
await waitFor(() =>
|
||||
expect(testModelConnection).toHaveBeenCalledWith({
|
||||
externalId: "gpt-4o",
|
||||
providerId: "pv1",
|
||||
}),
|
||||
);
|
||||
});
|
||||
await waitFor(() =>
|
||||
expect(testModelConnection).toHaveBeenCalledWith({
|
||||
externalId: "gpt-4o",
|
||||
providerId: "pv1",
|
||||
}),
|
||||
);
|
||||
},
|
||||
{ timeout: 15000 },
|
||||
);
|
||||
|
||||
test("新建模型也显示测试连接按钮", async () => {
|
||||
renderWithProviders(
|
||||
@@ -300,7 +316,7 @@ describe("ModelListPage", () => {
|
||||
expect(screen.getByPlaceholderText("搜索模型名称或 ID")).not.toBeNull();
|
||||
expect(screen.getByRole("button", { name: /新建模型/ })).not.toBeNull();
|
||||
expect(calls.some((call) => call.url.includes("/api/models"))).toBe(true);
|
||||
}, 15000);
|
||||
}, 30000);
|
||||
|
||||
test("搜索模型更新请求参数", async () => {
|
||||
const calls = createModelFetchMock();
|
||||
@@ -312,7 +328,7 @@ describe("ModelListPage", () => {
|
||||
fireEvent.change(input, { target: { value: "gpt" } });
|
||||
fireEvent.keyDown(input, { key: "Enter" });
|
||||
await waitFor(() => expect(calls.some((call) => call.url.includes("keyword=gpt"))).toBe(true));
|
||||
}, 15000);
|
||||
}, 30000);
|
||||
|
||||
test("新建模型弹窗可以打开", async () => {
|
||||
createModelFetchMock();
|
||||
@@ -322,5 +338,5 @@ describe("ModelListPage", () => {
|
||||
|
||||
fireEvent.click(screen.getByRole("button", { name: /新建模型/ }));
|
||||
await screen.findByPlaceholderText("请输入模型名称");
|
||||
}, 15000);
|
||||
}, 30000);
|
||||
});
|
||||
|
||||
@@ -148,7 +148,7 @@ describe("ProjectsPage", () => {
|
||||
await waitFor(() => expect(calls.some((call) => call.url.includes("status=archived"))).toBe(true));
|
||||
|
||||
await screen.findByText("归档项目");
|
||||
});
|
||||
}, 30000);
|
||||
|
||||
test("清空搜索条件复位请求参数并重新展示全部项目", async () => {
|
||||
const calls = createProjectFetchMock();
|
||||
@@ -190,7 +190,7 @@ describe("ProjectsPage", () => {
|
||||
const createCall = calls.find((call) => call.url.endsWith("/api/projects") && call.method === "POST");
|
||||
expect(createCall).toBeDefined();
|
||||
expect(jsonBody(createCall?.body)).toEqual({ description: "新增描述", name: "新增项目" });
|
||||
});
|
||||
}, 30000);
|
||||
|
||||
test("编辑项目表单只提交变更字段", async () => {
|
||||
const updateCalls: unknown[] = [];
|
||||
@@ -217,7 +217,7 @@ describe("ProjectsPage", () => {
|
||||
|
||||
await waitFor(() => expect(onUpdate).toHaveBeenCalled());
|
||||
expect(updateCalls[0]).toEqual({ data: { name: "编辑项目" }, id: "p1" });
|
||||
});
|
||||
}, 30000);
|
||||
|
||||
test("项目表单校验失败不会提交,接口失败时保留弹窗", async () => {
|
||||
const onCreate = mock(() => Promise.reject(new Error("创建失败")));
|
||||
@@ -244,7 +244,7 @@ describe("ProjectsPage", () => {
|
||||
await waitFor(() => expect(onCreate).toHaveBeenCalled());
|
||||
expect(onOpenChange).not.toHaveBeenCalledWith(false);
|
||||
expect(screen.getByText("新建项目")).not.toBeNull();
|
||||
});
|
||||
}, 30000);
|
||||
|
||||
test("项目表格操作触发导航和行级动作", async () => {
|
||||
const onArchive = mock(() => Promise.resolve());
|
||||
@@ -287,5 +287,5 @@ describe("ProjectsPage", () => {
|
||||
await screen.findByText("确认永久删除此项目?");
|
||||
await clickLatestConfirmButton();
|
||||
await waitFor(() => expect(onDelete).toHaveBeenCalledWith("p2"));
|
||||
}, 15000);
|
||||
}, 30000);
|
||||
});
|
||||
|
||||
@@ -49,7 +49,7 @@ describe("ProviderFormModal", () => {
|
||||
|
||||
await waitFor(() => expect(updateCalls.length).toBe(1));
|
||||
expect(updateCalls[0]).toEqual({ data: { name: "New OpenAI" }, id: "pv1" });
|
||||
});
|
||||
}, 30000);
|
||||
|
||||
test("新建供应商默认使用 openai-compatible 类型", async () => {
|
||||
const createCalls: unknown[] = [];
|
||||
@@ -85,7 +85,7 @@ describe("ProviderFormModal", () => {
|
||||
name: "兼容供应商",
|
||||
type: "openai-compatible",
|
||||
});
|
||||
});
|
||||
}, 30000);
|
||||
|
||||
test("供应商表单可使用当前表单配置测试连接", async () => {
|
||||
const testCalls: unknown[] = [];
|
||||
@@ -121,7 +121,7 @@ describe("ProviderFormModal", () => {
|
||||
name: "兼容供应商",
|
||||
type: "openai-compatible",
|
||||
});
|
||||
});
|
||||
}, 30000);
|
||||
});
|
||||
|
||||
const TEST_PROVIDER: Provider = {
|
||||
@@ -197,7 +197,7 @@ describe("ProviderListPage", () => {
|
||||
expect(screen.getByPlaceholderText("搜索供应商名称")).not.toBeNull();
|
||||
expect(screen.getByRole("button", { name: /新建供应商/ })).not.toBeNull();
|
||||
expect(calls.some((call) => call.url.includes("/api/providers"))).toBe(true);
|
||||
}, 15000);
|
||||
}, 30000);
|
||||
|
||||
test("搜索供应商更新请求参数", async () => {
|
||||
const calls = createProviderFetchMock();
|
||||
@@ -209,7 +209,7 @@ describe("ProviderListPage", () => {
|
||||
fireEvent.change(input, { target: { value: "Open" } });
|
||||
fireEvent.keyDown(input, { key: "Enter" });
|
||||
await waitFor(() => expect(calls.some((call) => call.url.includes("keyword=Open"))).toBe(true));
|
||||
}, 15000);
|
||||
}, 30000);
|
||||
|
||||
test("新建供应商弹窗可以打开", async () => {
|
||||
createProviderFetchMock();
|
||||
@@ -219,5 +219,5 @@ describe("ProviderListPage", () => {
|
||||
|
||||
fireEvent.click(screen.getByRole("button", { name: /新建供应商/ }));
|
||||
await screen.findByPlaceholderText("请输入供应商名称");
|
||||
}, 15000);
|
||||
}, 30000);
|
||||
});
|
||||
|
||||
@@ -65,7 +65,7 @@ describe("Workbench 路由", () => {
|
||||
},
|
||||
{ timeout: 10000 },
|
||||
);
|
||||
});
|
||||
}, 30000);
|
||||
|
||||
test("Workbench 显示返回管理台按钮", async () => {
|
||||
createMockHandler();
|
||||
@@ -75,7 +75,7 @@ describe("Workbench 路由", () => {
|
||||
});
|
||||
|
||||
await screen.findByText("返回管理台", {}, { timeout: 10000 });
|
||||
});
|
||||
}, 30000);
|
||||
|
||||
test("不存在项目显示不可访问", async () => {
|
||||
createMockHandler();
|
||||
@@ -85,7 +85,7 @@ describe("Workbench 路由", () => {
|
||||
});
|
||||
|
||||
await screen.findByText("项目不存在或不可访问", {}, { timeout: 10000 });
|
||||
});
|
||||
}, 30000);
|
||||
|
||||
test("archived 项目显示不可访问", async () => {
|
||||
createMockHandler({ status: "archived" });
|
||||
@@ -95,7 +95,7 @@ describe("Workbench 路由", () => {
|
||||
});
|
||||
|
||||
await screen.findByText("项目不存在或不可访问", {}, { timeout: 10000 });
|
||||
});
|
||||
}, 30000);
|
||||
|
||||
test("Workbench 显示聊天室菜单", async () => {
|
||||
createMockHandler();
|
||||
@@ -105,7 +105,7 @@ describe("Workbench 路由", () => {
|
||||
});
|
||||
|
||||
await screen.findByText("聊天室", {}, { timeout: 10000 });
|
||||
});
|
||||
}, 30000);
|
||||
|
||||
test("Workbench 收集箱路由可达", async () => {
|
||||
createMockHandler();
|
||||
@@ -115,7 +115,7 @@ describe("Workbench 路由", () => {
|
||||
});
|
||||
|
||||
await screen.findByText("新增素材", {}, { timeout: 10000 });
|
||||
});
|
||||
}, 30000);
|
||||
|
||||
test("Workbench 显示收集箱菜单", async () => {
|
||||
createMockHandler();
|
||||
@@ -125,5 +125,5 @@ describe("Workbench 路由", () => {
|
||||
});
|
||||
|
||||
await screen.findByText("收集箱", {}, { timeout: 10000 });
|
||||
});
|
||||
}, 30000);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user