diff --git a/src/api/componentTestCase.ts b/src/api/componentTestCase.ts index bede628..3653b44 100644 --- a/src/api/componentTestCase.ts +++ b/src/api/componentTestCase.ts @@ -17,4 +17,9 @@ export function getComponentTestCaseList(params?: { componentBaseId: string, ide // 提交测试用例 export function submitTestCase(params) { return axios.post(`${urlPrefix}/componentTestCase/submit`, params); +} + +// 删除测试用例 +export function deleteTestCase(ids) { + return axios.post(`${urlPrefix}/componentTestCase/remove?ids=${ids}`); } \ No newline at end of file diff --git a/src/pages/componentDevelopment/componentTest/TestCaseModal.tsx b/src/pages/componentDevelopment/componentTest/TestCaseModal.tsx index b4b291b..48f87b4 100644 --- a/src/pages/componentDevelopment/componentTest/TestCaseModal.tsx +++ b/src/pages/componentDevelopment/componentTest/TestCaseModal.tsx @@ -9,6 +9,7 @@ interface TestCaseModalProps { design: Record; visible: boolean; operationIdent: string; + editingData?: any; onCancel: () => void; onOk: (values: any) => void; } @@ -40,7 +41,7 @@ const dict = [ } ]; -const TestCaseModal: React.FC = ({ design, visible, operationIdent, onCancel, onOk }) => { +const TestCaseModal: React.FC = ({ design, visible, operationIdent, editingData, onCancel, onOk }) => { const [testCaseFunctions, setTestCaseFunctions] = useState(null); const [form] = Form.useForm(); @@ -50,6 +51,7 @@ const TestCaseModal: React.FC = ({ design, visible, operatio // 构造完整的数据结构,包含原始字段信息和用户输入的值 const result = { + ...(editingData?.id && { id: editingData.id }), // 如果是编辑模式,保留id testCaseName: formValues.testCaseName, operation: operationIdent, expectDataIns: testCaseFunctions.parameters.map((param, index) => ({ @@ -86,9 +88,32 @@ const TestCaseModal: React.FC = ({ design, visible, operatio setTestCaseFunctions(design.find(item => item.ident === operationIdent)); }, [visible, operationIdent, design]); + // 回显编辑数据 + useEffect(() => { + if (editingData && testCaseFunctions) { + const formData: any = { + testCaseName: editingData.testCaseName + }; + + // 回显输入参数 + editingData.expectDataIns?.forEach((param: any, index: number) => { + formData[`parameters_${index}`] = param.value; + }); + + // 回显输出参数 + editingData.expectDataOuts?.forEach((resp: any, index: number) => { + formData[`responses_${index}`] = resp.value; + }); + + form.setFieldsValue(formData); + } else { + form.resetFields(); + } + }, [editingData, testCaseFunctions, form]); + return ( { const res: any = await getComponentDesign(parentId); @@ -39,9 +40,38 @@ const TestInstance = ({ instance, parentId, onBack }: { instance: any; parentId: const handleAddTestCase = (operationIdent: string) => { setSelectedOperationIdent(operationIdent); + setEditingTestCase(null); setModalVisible(true); }; + const handleEditTestCase = (testCase: any, operationIdent: string) => { + setSelectedOperationIdent(operationIdent); + setEditingTestCase(testCase); + setModalVisible(true); + }; + + const handleDeleteTestCase = (testCase: any) => { + Modal.confirm({ + title: '确认删除', + content: `确定要删除测试用例"${testCase.testCaseName}"吗?`, + okText: '确定', + cancelText: '取消', + onOk: async () => { + try { + const res: any = await deleteTestCase(testCase.id); + if (res.code === 200) { + Message.success('删除成功'); + getTestCaseList(); + } else { + Message.error(res.msg || '删除失败'); + } + } catch (error) { + Message.error('删除失败'); + } + } + }); + }; + const handleModalOk = async (values: any) => { const params = { ...values, @@ -59,6 +89,7 @@ const TestInstance = ({ instance, parentId, onBack }: { instance: any; parentId: const handleModalCancel = () => { setModalVisible(false); + setEditingTestCase(null); }; return ( @@ -149,8 +180,18 @@ const TestInstance = ({ instance, parentId, onBack }: { instance: any; parentId: {child.testCaseName}
- - + { + e.stopPropagation(); + handleEditTestCase(child, item.operationIdent); + }} + /> + { + e.stopPropagation(); + handleDeleteTestCase(child); + }} + />
))} @@ -273,6 +314,7 @@ const TestInstance = ({ instance, parentId, onBack }: { instance: any; parentId: design={design.operates} visible={modalVisible} operationIdent={selectedOperationIdent} + editingData={editingTestCase} onCancel={handleModalCancel} onOk={handleModalOk} />}