fix(用例管理): 修复用例执行历史是否显示步骤问题

--bug=1044969 --user=郭雨琦 https://www.tapd.cn/55049933/bugtrace/bugs/view/1155049933001044969
This commit is contained in:
guoyuqi 2024-08-14 14:41:14 +08:00 committed by 刘瑞斌
parent 8b6dff99b1
commit 65e810de6f
10 changed files with 67 additions and 13 deletions

View File

@ -31,4 +31,7 @@ public class TestPlanCaseExecuteHistoryDTO extends TestPlanCaseExecuteHistory {
@Schema(description = "编辑模式")
private String caseEditType;
@Schema(description = "是否显示步骤信息")
private boolean showResult = false;
}

View File

@ -804,7 +804,7 @@
fc.project_Id = #{request.projectId}
AND
fc.module_id = #{request.moduleId}
order by fc.pos
order by fc.pos desc
</select>
<select id="getCaseCustomFieldList" resultType="io.metersphere.functional.domain.FunctionalCaseCustomField">
@ -830,7 +830,7 @@
#{fieldId}
</foreach>
</if>
order by fc.pos
order by fc.pos desc
</select>

View File

@ -7,6 +7,7 @@ import io.metersphere.dto.TestCaseProviderDTO;
import io.metersphere.functional.constants.AssociateCaseType;
import io.metersphere.functional.domain.FunctionalCaseTest;
import io.metersphere.functional.domain.FunctionalCaseTestExample;
import io.metersphere.functional.dto.FunctionalCaseStepDTO;
import io.metersphere.functional.dto.FunctionalCaseTestDTO;
import io.metersphere.functional.dto.FunctionalCaseTestPlanDTO;
import io.metersphere.functional.dto.TestPlanCaseExecuteHistoryDTO;
@ -22,12 +23,14 @@ import io.metersphere.provider.BaseAssociateScenarioProvider;
import io.metersphere.provider.BaseTestPlanProvider;
import io.metersphere.request.*;
import io.metersphere.sdk.constants.TestPlanConstants;
import io.metersphere.sdk.util.JSON;
import io.metersphere.sdk.util.LogUtils;
import io.metersphere.sdk.util.Translator;
import io.metersphere.system.dto.sdk.BaseTreeNode;
import io.metersphere.system.uid.IDGenerator;
import jakarta.annotation.Resource;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.session.ExecutorType;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
@ -292,7 +295,14 @@ public class FunctionalTestCaseService {
planCaseExecuteHistoryDTO.setContentText(new String(planCaseExecuteHistoryDTO.getContent(), StandardCharsets.UTF_8));
}
if (planCaseExecuteHistoryDTO.getSteps() != null) {
planCaseExecuteHistoryDTO.setStepsText(new String(planCaseExecuteHistoryDTO.getSteps(), StandardCharsets.UTF_8));
String historyStepStr = new String(planCaseExecuteHistoryDTO.getSteps(), StandardCharsets.UTF_8);
planCaseExecuteHistoryDTO.setStepsText(historyStepStr);
if (StringUtils.isNotBlank(historyStepStr)) {
List<FunctionalCaseStepDTO> historySteps = JSON.parseArray(historyStepStr, FunctionalCaseStepDTO.class);
if (org.apache.commons.collections.CollectionUtils.isNotEmpty(historySteps)) {
planCaseExecuteHistoryDTO.setShowResult(true);
}
}
}
}
return planExecuteHistoryList;

View File

@ -353,7 +353,7 @@ public class XMindCaseParser {
if (StringUtils.isBlank(tag)) {
testCase.setTags("");
} else {
String[] tagArr = tag.split("\\|");
String[] tagArr = tag.split("\\s*[|]\\s*");
if (CollectionUtils.isNotEmpty(Arrays.asList(tagArr))) {
testCase.setTags(String.join(",", tagArr));
}

View File

@ -1,6 +1,7 @@
package io.metersphere.functional.controller;
import io.metersphere.api.domain.ApiDefinitionModule;
import io.metersphere.api.domain.ApiScenario;
import io.metersphere.api.domain.ApiScenarioModule;
import io.metersphere.api.domain.ApiTestCase;
import io.metersphere.api.mapper.ApiDefinitionModuleMapper;
@ -11,6 +12,7 @@ import io.metersphere.functional.constants.AssociateCaseType;
import io.metersphere.functional.constants.FunctionalCaseReviewStatus;
import io.metersphere.functional.domain.FunctionalCase;
import io.metersphere.functional.domain.FunctionalCaseTest;
import io.metersphere.functional.dto.FunctionalCaseStepDTO;
import io.metersphere.functional.dto.FunctionalCaseTestDTO;
import io.metersphere.functional.dto.FunctionalCaseTestPlanDTO;
import io.metersphere.functional.dto.TestPlanCaseExecuteHistoryDTO;
@ -254,6 +256,21 @@ public class FunctionalTestCaseControllerTests extends BaseTest {
resultHolder = JSON.parseObject(returnData, ResultHolder.class);
Assertions.assertNotNull(resultHolder);
List<ApiScenario> operationScenarios = new ArrayList<>();
ApiScenario apiScenario = new ApiScenario();
apiScenario.setId("gyq_associate_scenario_id_1");
apiScenario.setVersionId("11");
operationScenarios.add(apiScenario);
Mockito.when(scenarioProvider.getSelectScenarioCases(request, false)).thenReturn(operationScenarios);
Assertions.assertNotNull(resultHolder);
request.setSelectAll(false);
request.setProjectId("project-associate-case-test");
request.setSelectIds(List.of("gyq_associate_case_id_1"));
mvcResult = this.requestPostWithOkAndReturn(URL_CASE_PAGE_ASSOCIATE, request);
returnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8);
resultHolder = JSON.parseObject(returnData, ResultHolder.class);
Assertions.assertNotNull(resultHolder);
}
@Test
@ -590,8 +607,13 @@ public class FunctionalTestCaseControllerTests extends BaseTest {
testPlanCaseExecuteHistory.setStatus(FunctionalCaseReviewStatus.RE_REVIEWED.toString());
testPlanCaseExecuteHistory.setId("testNoContent");
testPlanCaseExecuteHistory.setCreateTime(System.currentTimeMillis());
String steps = "你好评论";
testPlanCaseExecuteHistory.setSteps(steps.getBytes());
FunctionalCaseStepDTO functionalCaseStepDTO = new FunctionalCaseStepDTO();
functionalCaseStepDTO.setNum(1);
functionalCaseStepDTO.setDesc("步骤一");
functionalCaseStepDTO.setResult("你好评论");
List<FunctionalCaseStepDTO> list = new ArrayList<>();
list.add(functionalCaseStepDTO);
testPlanCaseExecuteHistory.setSteps(JSON.toJSONString(list).getBytes());
testPlanCaseExecuteHistory.setCreateTime(System.currentTimeMillis());
testPlanCaseExecuteHistoryMapper.insertSelective(testPlanCaseExecuteHistory);
gyqReviewCaseTest = getPlanExecuteHistoryList("gyq_associate_function_case");

View File

@ -25,6 +25,9 @@ public class TestPlanCaseExecHistoryResponse extends TestPlanCaseExecuteHistory
@Schema(description = "执行人邮箱")
private String email;
@Schema(description = "步骤描述")
@Schema(description = "编辑模式")
private String caseEditType;
@Schema(description = "是否显示步骤信息")
private boolean showResult = false;
}

View File

@ -708,7 +708,14 @@ public class TestPlanFunctionalCaseService extends TestPlanResourceService {
item.setContentText(new String(item.getContent(), StandardCharsets.UTF_8));
}
if (item.getSteps() != null) {
item.setStepsExecResult(new String(item.getSteps(), StandardCharsets.UTF_8));
String historyStepStr = new String(item.getSteps(), StandardCharsets.UTF_8);
item.setStepsExecResult(historyStepStr);
if (StringUtils.isNotBlank(historyStepStr)) {
List<FunctionalCaseStepDTO> historySteps = JSON.parseArray(historyStepStr, FunctionalCaseStepDTO.class);
if (CollectionUtils.isNotEmpty(historySteps)) {
item.setShowResult(true);
}
}
}
});
return list;

View File

@ -38,10 +38,7 @@ import org.springframework.test.context.jdbc.SqlConfig;
import org.springframework.test.web.servlet.MvcResult;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@ -280,6 +277,18 @@ public class TestPlanCaseControllerTests extends BaseTest {
request.setTestPlanId("plan_1");
request.setCaseId("fc_1");
this.requestPostWithOk(FUNCTIONAL_CASE_EXEC_HISTORY_URL, request);
TestPlanCaseExecuteHistory testPlanCaseExecuteHistory = new TestPlanCaseExecuteHistory();
testPlanCaseExecuteHistory.setId("123445");
FunctionalCaseStepDTO functionalCaseStepDTO = new FunctionalCaseStepDTO();
functionalCaseStepDTO.setId(UUID.randomUUID().toString());
functionalCaseStepDTO.setNum(1);
functionalCaseStepDTO.setDesc("步骤描述");
functionalCaseStepDTO.setResult("结果");
List<FunctionalCaseStepDTO>list = new ArrayList<>();
list.add(functionalCaseStepDTO);
testPlanCaseExecuteHistory.setSteps(JSON.toJSONString(list).getBytes());
testPlanCaseExecuteHistoryMapper.updateByPrimaryKeySelective(testPlanCaseExecuteHistory);
this.requestPostWithOk(FUNCTIONAL_CASE_EXEC_HISTORY_URL, request);
}
@Test

View File

@ -65,7 +65,7 @@ VALUES
INSERT INTO `test_plan_case_execute_history`(`id`, `test_plan_case_id`, `test_plan_id`, `case_id`, `status`, `content`, `steps`, `deleted`, `notifier`, `create_user`, `create_time`)
VALUES
('123445', 'relate_case_1', 'plan_1', 'fc_1', 'PASSED', '1234', '2132134', b'0', '', 'admin', 1715828421525);
('123445', 'relate_case_1', 'plan_1', 'fc_1', 'PASSED', '1234', null, b'0', '', 'admin', 1715828421525);
INSERT INTO functional_case_blob(id, steps, text_description, expected_result, prerequisite, description) VALUES ('fc_1', 'STEP', '1111', '', '', 'TEST');
INSERT INTO project (id, num, organization_id, name, description, create_user, update_user, create_time, update_time, module_setting)