fix: 修复测试套件质量审查问题——act环境、正则匹配、mock排序、超时设置

This commit is contained in:
2026-06-08 14:13:45 +08:00
parent 74266dc5cc
commit d02abce58d
11 changed files with 204 additions and 179 deletions

View File

@@ -54,6 +54,12 @@ function setupFetchMock() {
if (call.url.includes("/models")) {
return jsonResponse({ items: [TEXT_MODEL], total: 1 });
}
if (call.url.includes("/messages")) {
return jsonResponse({ items: [], total: 0 });
}
if (call.method === "GET" && /\/conversations\/conv-/.exec(call.url)) {
return jsonResponse({ conversation: CONVERSATION });
}
if (call.url.includes("/conversations") && call.method === "GET") {
return jsonResponse({ items: [CONVERSATION], page: 1, pageSize: 200, total: 1 });
}
@@ -63,12 +69,6 @@ function setupFetchMock() {
if (call.method === "DELETE" && call.url.includes("/conversations/")) {
return new Response(null, { status: 204 });
}
if (call.url.includes("/messages")) {
return jsonResponse({ items: [], total: 0 });
}
if (/\/conversations\/conv-1$/.exec(call.url)) {
return jsonResponse({ conversation: CONVERSATION });
}
return jsonResponse({ error: "not found" }, { status: 404 });
});
}
@@ -143,15 +143,18 @@ describe("ChatPage", () => {
if (call.url.includes("/models")) {
return jsonResponse({ items: [TEXT_MODEL], total: 1 });
}
if (call.url.includes("/messages")) {
return jsonResponse({ items: [], total: 0 });
}
if (call.method === "GET" && /\/conversations\/conv-/.exec(call.url)) {
return jsonResponse({ conversation: CONVERSATION });
}
if (call.url.includes("/conversations") && call.method === "GET") {
if (deleted) {
return jsonResponse({ items: [], page: 1, pageSize: 200, total: 0 });
}
return jsonResponse({ items: [CONVERSATION], page: 1, pageSize: 200, total: 1 });
}
if (call.url.includes("/messages")) {
return jsonResponse({ items: [], total: 0 });
}
return jsonResponse({ error: "not found" }, { status: 404 });
});

View File

@@ -65,7 +65,7 @@ const DEEPSEEK_PROVIDER: Provider = {
};
function clickLatestConfirmButton() {
const buttons = screen.getAllByRole("button", { name: /OK|确定/ });
const buttons = screen.getAllByRole("button", { name: /OK|确\s*定/ });
fireEvent.click(buttons[buttons.length - 1]!);
}
@@ -149,28 +149,37 @@ const TABLE_ACTION_TEST_CASES = [
];
describe("ResourceTable", () => {
// Ant Design Table 在 happy-dom 中渲染较慢,并行测试时需要更多时间
for (const tc of TABLE_TEST_CASES) {
test(`${tc.componentName} 渲染表格数据`, () => {
tc.render();
tc.assertData();
tc.assertNoExtra();
});
test(
`${tc.componentName} 渲染表格数据`,
() => {
tc.render();
tc.assertData();
tc.assertNoExtra();
},
{ timeout: 30000 },
);
}
for (const tc of TABLE_ACTION_TEST_CASES) {
test(`${tc.componentName} 表格操作触发 edit/delete`, async () => {
const onDelete = mock(() => Promise.resolve());
const onEdit = mock(() => undefined);
test(
`${tc.componentName} 表格操作触发 edit/delete`,
async () => {
const onDelete = mock(() => Promise.resolve());
const onEdit = mock(() => undefined);
tc.render({ onDelete, onEdit });
tc.render({ onDelete, onEdit });
fireEvent.click(screen.getAllByRole("button", { name: /编辑/ })[0]!);
expect(onEdit).toHaveBeenCalledWith(tc.editArg);
fireEvent.click(screen.getAllByRole("button", { name: /编辑/ })[0]!);
expect(onEdit).toHaveBeenCalledWith(tc.editArg);
fireEvent.click(screen.getAllByRole("button", { name: /删除/ })[0]!);
await screen.findByText(tc.deleteConfirmText);
clickLatestConfirmButton();
await waitFor(() => expect(onDelete).toHaveBeenCalledWith(tc.deleteId));
});
fireEvent.click(screen.getAllByRole("button", { name: /删除/ })[0]!);
await screen.findByText(tc.deleteConfirmText);
clickLatestConfirmButton();
await waitFor(() => expect(onDelete).toHaveBeenCalledWith(tc.deleteId));
},
{ timeout: 30000 },
);
}
});