fix(UI测试): 修复测试计划环境展示相关问题

--bug=1023048_--user=张大海_【测试跟踪】复制测试计划-操作-执行-运行环境未显示跨项目环境_https
This commit is contained in:
CaptainB 2023-02-20 10:18:53 +08:00 committed by 刘瑞斌
parent fb9791e4d6
commit 9fdb2b0d9d
7 changed files with 126 additions and 13 deletions

View File

@ -6,4 +6,6 @@ import java.util.List;
public interface ExtTestPlanScenarioCaseMapper {
List<TestPlanApiScenarioInfoDTO> selectLegalDataByTestPlanId(String planId);
List<TestPlanApiScenarioInfoDTO> selectLegalUiDataByTestPlanId(String planId);
}

View File

@ -14,4 +14,18 @@
AND tpas.test_plan_id = #{0}
ORDER BY tpas.`order` DESC;
</select>
<select id="selectLegalUiDataByTestPlanId" resultType="io.metersphere.plan.dto.TestPlanApiScenarioInfoDTO">
SELECT tpas.id,
tpas.ui_scenario_id,
tpas.environment,
tpas.environment_type,
tpas.environment_group_id,
apis.project_id
FROM test_plan_ui_scenario tpas
INNER JOIN ui_scenario apis ON tpas.ui_scenario_id = apis.id
WHERE (apis.`status` IS NULL OR apis.`status` != 'Trash')
AND tpas.test_plan_id = #{0}
ORDER BY tpas.`order` DESC;
</select>
</mapper>

View File

@ -17,11 +17,14 @@ public class TestPlanReportRunInfoDTO {
private String runMode;
// <测试计划场景关联表ID, <项目ID环境ID>>
private Map<String, Map<String, List<String>>> scenarioRunInfo;
// <测试计划场景关联表ID, <项目ID环境ID>>
private Map<String, Map<String, List<String>>> uiScenarioRunInfo;
// <测试计划用例关联表ID, <项目ID环境ID>>
private Map<String, Map<String, String>> apiCaseRunInfo;
public TestPlanReportRunInfoDTO() {
scenarioRunInfo = new HashMap<>();
uiScenarioRunInfo = new HashMap<>();
apiCaseRunInfo = new HashMap<>();
}
@ -45,6 +48,26 @@ public class TestPlanReportRunInfoDTO {
}
}
public void putUiScenarioRunInfo(String scenarioResourceId, String projectId, String environmentId) {
if (uiScenarioRunInfo.containsKey(scenarioResourceId)) {
if (uiScenarioRunInfo.get(scenarioResourceId).containsKey(projectId)) {
if (!uiScenarioRunInfo.get(scenarioResourceId).get(projectId).contains(environmentId)) {
uiScenarioRunInfo.get(scenarioResourceId).get(projectId).add(environmentId);
}
} else {
uiScenarioRunInfo.get(scenarioResourceId).put(projectId, new ArrayList<>() {{
this.add(environmentId);
}});
}
} else {
uiScenarioRunInfo.put(scenarioResourceId, new HashMap<>() {{
this.put(projectId, new ArrayList<>() {{
this.add(environmentId);
}});
}});
}
}
public void putApiCaseRunInfo(String apiCaseResourceId, String projectId, String environmentId) {
apiCaseRunInfo.put(apiCaseResourceId, new HashMap<>() {{
this.put(projectId, environmentId);

View File

@ -29,6 +29,7 @@ import io.metersphere.service.ServiceUtils;
import io.metersphere.utils.DiscoveryUtil;
import io.metersphere.utils.LoggerUtil;
import io.metersphere.xpack.track.dto.IssuesDao;
import jakarta.annotation.Resource;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.BooleanUtils;
@ -41,7 +42,6 @@ import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import jakarta.annotation.Resource;
import java.util.*;
import java.util.stream.Collectors;
@ -362,12 +362,20 @@ public class TestPlanReportService {
if (serviceIdSet.contains(MicroServiceName.UI_TEST)) {
Map<String, String> uiScenarioIdMap = new LinkedHashMap<>();
List<TestPlanUiScenario> testPlanUiScenarioList = planTestPlanUiScenarioCaseService.list(planId);
for (TestPlanUiScenario dto : testPlanUiScenarioList) {
uiScenarioIdMap.put(dto.getId(), dto.getUiScenarioId());
if (CollectionUtils.isNotEmpty(testPlanUiScenarioList)) {
for (TestPlanUiScenario dto : testPlanUiScenarioList) {
uiScenarioIdMap.put(dto.getId(), dto.getUiScenarioId());
}
List<TestPlanApiScenarioInfoDTO> testPlanUiScenarioInfoList = extTestPlanScenarioCaseMapper.selectLegalUiDataByTestPlanId(planId);
TestPlanReportRunInfoDTO uiRunInfoDTO = this.parseTestPlanUiRunInfo(runModeConfigDTO, testPlanUiScenarioInfoList);
if (runInfoDTO != null) {
runInfoDTO.setUiScenarioRunInfo(uiRunInfoDTO.getUiScenarioRunInfo());
} else {
runInfoDTO = uiRunInfoDTO;
}
}
saveRequest.setUiScenarioIsExecuting(!uiScenarioIdMap.isEmpty());
saveRequest.setUiScenarioIdMap(uiScenarioIdMap);
returnDTO.setUiScenarioIdMap(uiScenarioIdMap);
}
@ -391,6 +399,46 @@ public class TestPlanReportService {
return returnDTO;
}
private TestPlanReportRunInfoDTO parseTestPlanUiRunInfo(RunModeConfigDTO config, List<TestPlanApiScenarioInfoDTO> scenarios) {
TestPlanReportRunInfoDTO runInfoDTO = new TestPlanReportRunInfoDTO();
final Map<String, String> runEnvMap = MapUtils.isNotEmpty(config.getEnvMap()) ? config.getEnvMap() : new HashMap<>();
runInfoDTO.setRunMode(config.getMode());
if (StringUtils.equals(GROUP, config.getEnvironmentType()) && StringUtils.isNotEmpty(config.getEnvironmentGroupId())) {
Map<String, String> groupMap = baseEnvGroupProjectService.getEnvMap(config.getEnvironmentGroupId());
if (MapUtils.isNotEmpty(groupMap)) {
runEnvMap.putAll(groupMap);
}
runInfoDTO.setEnvGroupId(config.getEnvironmentGroupId());
}
// 场景环境处理
scenarios.forEach(item -> {
Map<String, String> envMap = null;
if (StringUtils.equalsIgnoreCase(GROUP, item.getEnvironmentType())
&& StringUtils.isNotEmpty(item.getEnvironmentGroupId())) {
envMap = baseEnvGroupProjectService.getEnvMap(item.getEnvironmentGroupId());
} else {
if (MapUtils.isNotEmpty(runEnvMap) && runEnvMap.containsKey(item.getProjectId())) {
runInfoDTO.putUiScenarioRunInfo(item.getId(), item.getProjectId(), runEnvMap.get(item.getProjectId()));
} else if (StringUtils.isNotEmpty(item.getEnvironment())) {
try {
envMap = JSON.parseObject(item.getEnvironment(), Map.class);
} catch (Exception e) {
LogUtil.error("解析场景环境失败!", e);
}
}
}
if (MapUtils.isNotEmpty(envMap)) {
for (Map.Entry<String, String> entry : envMap.entrySet()) {
String projectId = entry.getKey();
String envIdStr = entry.getValue();
runInfoDTO.putUiScenarioRunInfo(item.getId(), projectId, envIdStr);
}
}
});
return runInfoDTO;
}
/**
* saveRequest.reportId 报告ID(外部传入
@ -1193,9 +1241,12 @@ public class TestPlanReportService {
if (DiscoveryUtil.hasService(MicroServiceName.API_TEST)) {
TestPlanEnvInfoDTO testPlanEnvInfo = planTestPlanScenarioCaseService.generateEnvironmentInfo(testPlanReport);
BeanUtils.copyBean(testPlanReportDTO, testPlanEnvInfo);
} else if (DiscoveryUtil.hasService(MicroServiceName.UI_TEST)) {
}
if (DiscoveryUtil.hasService(MicroServiceName.UI_TEST)) {
TestPlanEnvInfoDTO testPlanEnvInfo = planTestPlanUiScenarioCaseService.generateEnvironmentInfo(testPlanReport);
Map<String, List<String>> projectMap = testPlanReportDTO.getProjectEnvMap();
BeanUtils.copyBean(testPlanReportDTO, testPlanEnvInfo);
testPlanReportDTO.setProjectEnvMap(planTestPlanUiScenarioCaseService.mergeProjectEnvMap(testPlanEnvInfo.getProjectEnvMap(), projectMap));
}
} catch (Exception e) {
LogUtil.error(e);

View File

@ -1602,6 +1602,8 @@ public class TestPlanService {
environmentIds.add(eId);
}
});
} else {
scenarioEnv.put(entry.getKey(), entry.getValue());
}
});
}

View File

@ -17,13 +17,14 @@ import io.metersphere.plan.service.remote.api.PlanUiScenarioReportService;
import io.metersphere.plan.utils.TestPlanStatusCalculator;
import io.metersphere.request.ResetOrderRequest;
import io.metersphere.utils.DiscoveryUtil;
import jakarta.annotation.Resource;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.jetbrains.annotations.NotNull;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import jakarta.annotation.Resource;
import java.util.*;
import java.util.stream.Collectors;
@ -71,11 +72,8 @@ public class PlanTestPlanUiScenarioCaseService extends UiTestService {
//记录UI用例的运行环境信息
List<String> idList = planReportCaseDTOS.stream().map(PlanReportCaseDTO::getId).collect(Collectors.toList());
try {
if (MapUtils.isEmpty(report.getProjectEnvMap())) {
report.setProjectEnvMap(getPlanProjectEnvMap(idList));
} else {
report.getProjectEnvMap().putAll(getPlanProjectEnvMap(idList));
}
Map<String, List<String>> projectEnvMap = getPlanProjectEnvMap(idList);
report.setProjectEnvMap(mergeProjectEnvMap(projectEnvMap, report.getProjectEnvMap()));
} catch (Exception e) {
LogUtil.error(e);
}
@ -83,6 +81,28 @@ public class PlanTestPlanUiScenarioCaseService extends UiTestService {
}
}
public Map<String, List<String>> mergeProjectEnvMap(Map<String, List<String>> projectEnvMap, Map<String, List<String>> originProjectEnvMap) {
if (MapUtils.isEmpty(projectEnvMap)) {
return originProjectEnvMap;
}
if (MapUtils.isEmpty(originProjectEnvMap)) {
return projectEnvMap;
}
Map<String, List<String>> r = new HashMap<>();
projectEnvMap.entrySet().forEach(e -> {
r.put(e.getKey(), e.getValue());
});
originProjectEnvMap.entrySet().forEach(e -> {
if (r.containsKey(e.getKey())) {
r.get(e.getKey()).addAll(e.getValue());
r.put(e.getKey(), r.get(e.getKey()).stream().distinct().collect(Collectors.toList()));
} else {
r.put(e.getKey(), e.getValue());
}
});
return r;
}
@NotNull
private TestPlanUiResultReportDTO getUiResult(TestPlanSimpleReportDTO report, List<PlanReportCaseDTO> planReportCaseDTOS) {
TestPlanUiResultReportDTO uiResult = report.getUiResult();

View File

@ -160,6 +160,7 @@ export default {
reportId: "",
infoDb: false,
selectRows: new Set(),
map: new Map(),
projectEnvMap: new Map(),
projectList: [],
customNum: false,
@ -272,12 +273,12 @@ export default {
},
initProjectIds() {
this.projectIds.clear();
// this.map.clear();
this.map.clear();
this.selectRows.forEach((row) => {
getUiScenarioEnvByProjectId(row.id).then((res) => {
let data = res.data;
data.projectIds.forEach((d) => this.projectIds.add(d));
// this.map.set(row.id, data.projectIds);
this.map.set(row.id, data.projectIds);
});
});
},