fix(测试跟踪): 修复测试计划报告中场景报告跳转错误问题

--bug=1018864 --user=赵勇 【测试跟踪】测试计划-报告统计中场景执行结果的跳转链接失败 https://www.tapd.cn/55049933/s/1276946
This commit is contained in:
fit2-zhao 2022-10-25 18:11:14 +08:00 committed by fit2-zhao
parent b818366cd9
commit 0b05cd12e0
5 changed files with 30 additions and 7 deletions

View File

@ -230,4 +230,9 @@ public class TestPlanScenarioCaseController {
public Map<String, List<String>> getPlanProjectEnvMap(@RequestBody List<String> resourceIds) {
return testPlanScenarioCaseService.getPlanProjectEnvMap(resourceIds);
}
@GetMapping("/get-scenario-id/{id}")
public String getScenarioId(@PathVariable("id") String planScenarioId) {
return testPlanScenarioCaseService.getScenarioId(planScenarioId);
}
}

View File

@ -1207,4 +1207,12 @@ public class TestPlanScenarioCaseService {
}
return nodeTrees;
}
public String getScenarioId(String planScenarioId) {
TestPlanApiScenario planApiScenario = testPlanApiScenarioMapper.selectByPrimaryKey(planScenarioId);
if (planApiScenario != null) {
return planApiScenario.getApiScenarioId();
}
return planScenarioId;
}
}

View File

@ -316,7 +316,6 @@ public class ApiScenarioReportService {
public ApiScenarioReport updateSchedulePlanCase(ResultDTO dto) {
List<String> testPlanReportIdList = new ArrayList<>();
StringBuilder scenarioNames = new StringBuilder();
String status = ReportStatusUtil.getStatus(dto);
ApiScenarioReportWithBLOBs report = editReport(dto.getReportType(), dto.getReportId(), status, dto.getRunMode());
@ -326,19 +325,14 @@ public class ApiScenarioReportService {
}
TestPlanApiScenario testPlanApiScenario = testPlanApiScenarioMapper.selectByPrimaryKey(dto.getTestId());
if (testPlanApiScenario != null) {
report.setScenarioId(testPlanApiScenario.getApiScenarioId());
report.setEndTime(System.currentTimeMillis());
apiScenarioReportMapper.updateByPrimaryKeySelective(report);
testPlanApiScenario.setLastResult(report.getStatus());
long successSize = dto.getRequestResults().stream().filter(requestResult -> StringUtils.equalsIgnoreCase(requestResult.getStatus(), ApiReportStatus.SUCCESS.name())).count();
String passRate = new DecimalFormat("0%").format((float) successSize / dto.getRequestResults().size());
testPlanApiScenario.setPassRate(passRate);
testPlanApiScenario.setReportId(report.getId());
report.setEndTime(System.currentTimeMillis());
testPlanApiScenario.setUpdateTime(System.currentTimeMillis());
testPlanApiScenarioMapper.updateByPrimaryKeySelective(testPlanApiScenario);
scenarioNames.append(report.getName()).append(",");
// 更新场景状态
ApiScenario scenario = apiScenarioMapper.selectByPrimaryKey(testPlanApiScenario.getApiScenarioId());

View File

@ -9,3 +9,7 @@ export function getPlanStageOption() {
export function planPage(page, pageSize, params) {
return post('/test/plan/list/all/', params);
}
export function getApiScenarioIdByPlanScenarioId(id) {
return get('/test/plan/scenario/case/get-scenario-id/' + id);
}

View File

@ -85,6 +85,7 @@ import MsTag from "metersphere-frontend/src/components/MsTag";
import {getProjectApplicationConfig} from "../../../api/project";
import {apiTestReRun} from "../../../api/xpack";
import {getUUID} from "metersphere-frontend/src/utils";
import {getApiScenarioIdByPlanScenarioId} from "@/api/test-plan";
export default {
name: "MsApiReportViewHeader",
@ -151,6 +152,17 @@ export default {
$event.target.blur();
},
redirect() {
let resourceId = this.scenarioId;
if (this.isPlan) {
getApiScenarioIdByPlanScenarioId(this.scenarioId).then((res) => {
resourceId = res.data;
this.showDetails(resourceId);
});
} else {
this.showDetails(resourceId);
}
},
showDetails(resourceId) {
let uuid = getUUID().substring(1, 5);
let projectId = getCurrentProjectID();
let workspaceId = getCurrentWorkspaceId();
@ -159,7 +171,7 @@ export default {
&& this.$route.query && this.$route.query.list) {
prefix = ""
}
let path = `${prefix}/api/automation/?redirectID=${uuid}&dataType=scenario&projectId=${projectId}&workspaceId=${workspaceId}&resourceId=${this.scenarioId}`;
let path = `${prefix}/api/automation/?redirectID=${uuid}&dataType=scenario&projectId=${projectId}&workspaceId=${workspaceId}&resourceId=${resourceId}`;
let data = this.$router.resolve({
path: path
});