refactor: waitFor→findBy 替换 + renderWithBasicProviders + jsdom 条件化回退

This commit is contained in:
2026-06-06 10:15:02 +08:00
parent 121c6f764f
commit 5c0f02f1f8
7 changed files with 81 additions and 96 deletions

View File

@@ -67,7 +67,7 @@ describe("ModelFormModal", () => {
}),
);
await waitFor(() => expect(screen.getByPlaceholderText("请输入模型名称")).not.toBeNull());
await screen.findByPlaceholderText("请输入模型名称");
fireEvent.change(screen.getByPlaceholderText("请输入模型名称"), { target: { value: "GPT-4o Mini" } });
clickLatestConfirmButton();
@@ -93,7 +93,7 @@ describe("ModelFormModal", () => {
}),
);
await waitFor(() => expect(screen.getByPlaceholderText("请输入模型名称")).not.toBeNull());
await screen.findByPlaceholderText("请输入模型名称");
clickLatestConfirmButton();
expect(onCreate).not.toHaveBeenCalled();
});
@@ -114,7 +114,7 @@ describe("ModelFormModal", () => {
}),
);
await waitFor(() => expect(screen.getByLabelText("文本")).not.toBeNull());
await screen.findByLabelText("文本");
const textCheckbox = screen.getByLabelText("文本");
const reasoningCheckbox = screen.getByLabelText("推理");
expect((textCheckbox as { checked?: boolean }).checked).toBe(true);
@@ -137,7 +137,7 @@ describe("ModelFormModal", () => {
}),
);
await waitFor(() => expect(screen.getByPlaceholderText("请输入模型名称")).not.toBeNull());
await screen.findByPlaceholderText("请输入模型名称");
fireEvent.mouseDown(screen.getByRole("combobox"));
expect(await screen.findByText("OpenAI")).not.toBeNull();
@@ -160,7 +160,7 @@ describe("ModelFormModal", () => {
}),
);
await waitFor(() => expect(screen.getByPlaceholderText("请输入模型名称")).not.toBeNull());
await screen.findByPlaceholderText("请输入模型名称");
fireEvent.mouseDown(screen.getByRole("combobox"));
expect(await screen.findByText("供应商加载失败options failed")).not.toBeNull();
@@ -185,7 +185,7 @@ describe("ModelFormModal", () => {
}),
);
await waitFor(() => expect(screen.getByRole("button", { name: "测试连接" })).not.toBeNull());
await screen.findByRole("button", { name: "测试连接" });
fireEvent.click(screen.getByRole("button", { name: "测试连接" }));
await waitFor(() =>
@@ -213,7 +213,7 @@ describe("ModelFormModal", () => {
}),
);
await waitFor(() => expect(screen.getByRole("button", { name: "测试连接" })).not.toBeNull());
await screen.findByRole("button", { name: "测试连接" });
});
});
@@ -295,9 +295,7 @@ describe("ModelListPage", () => {
renderWithProviders(createElement(App), { initialRoute: "/models" });
await waitFor(() => {
expect(screen.getByText("GPT-4o")).not.toBeNull();
});
await screen.findByText("GPT-4o");
expect(screen.getByPlaceholderText("搜索模型名称或 ID")).not.toBeNull();
expect(screen.getByRole("button", { name: /新建模型/ })).not.toBeNull();
@@ -308,7 +306,7 @@ describe("ModelListPage", () => {
const calls = createModelFetchMock();
renderWithProviders(createElement(App), { initialRoute: "/models" });
await waitFor(() => expect(screen.getByText("GPT-4o")).not.toBeNull());
await screen.findByText("GPT-4o");
const input = screen.getByPlaceholderText("搜索模型名称或 ID");
fireEvent.change(input, { target: { value: "gpt" } });
@@ -320,9 +318,9 @@ describe("ModelListPage", () => {
createModelFetchMock();
renderWithProviders(createElement(App), { initialRoute: "/models" });
await waitFor(() => expect(screen.getByRole("button", { name: /新建模型/ })).not.toBeNull());
await screen.findByRole("button", { name: /新建模型/ });
fireEvent.click(screen.getByRole("button", { name: /新建模型/ }));
await waitFor(() => expect(screen.getByPlaceholderText("请输入模型名称")).not.toBeNull());
await screen.findByPlaceholderText("请输入模型名称");
}, 15000);
});