fix(接口自动化): 添加场景到测试计划时未选择环境
This commit is contained in:
parent
842cf07ccf
commit
e1d18909e2
|
@ -34,4 +34,14 @@ public class SaveApiPlanRequest {
|
||||||
|
|
||||||
private String projectId;
|
private String projectId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 项目环境对应关系
|
||||||
|
*/
|
||||||
|
private Map<String, String> envMap;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用例的环境的对应关系
|
||||||
|
*/
|
||||||
|
private Map<String, List<String>> mapping;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -611,27 +611,38 @@ public class ApiAutomationService {
|
||||||
if (CollectionUtils.isEmpty(request.getPlanIds())) {
|
if (CollectionUtils.isEmpty(request.getPlanIds())) {
|
||||||
MSException.throwException(Translator.get("plan id is null "));
|
MSException.throwException(Translator.get("plan id is null "));
|
||||||
}
|
}
|
||||||
List<String> scenarioIds = request.getScenarioIds();
|
// List<String> scenarioIds = request.getScenarioIds();
|
||||||
if (request.isSelectAllDate()) {
|
// if (request.isSelectAllDate()) {
|
||||||
scenarioIds = this.getAllScenarioIdsByFontedSelect(
|
// scenarioIds = this.getAllScenarioIdsByFontedSelect(
|
||||||
request.getModuleIds(), request.getName(), request.getProjectId(), request.getFilters(), request.getUnSelectIds());
|
// request.getModuleIds(), request.getName(), request.getProjectId(), request.getFilters(), request.getUnSelectIds());
|
||||||
}
|
// }
|
||||||
|
Map<String, List<String>> mapping = request.getMapping();
|
||||||
|
Map<String, String> envMap = request.getEnvMap();
|
||||||
|
Set<String> set = mapping.keySet();
|
||||||
List<TestPlanDTO> list = extTestPlanMapper.selectByIds(request.getPlanIds());
|
List<TestPlanDTO> list = extTestPlanMapper.selectByIds(request.getPlanIds());
|
||||||
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
|
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
|
||||||
ExtTestPlanScenarioCaseMapper scenarioBatchMapper = sqlSession.getMapper(ExtTestPlanScenarioCaseMapper.class);
|
ExtTestPlanScenarioCaseMapper scenarioBatchMapper = sqlSession.getMapper(ExtTestPlanScenarioCaseMapper.class);
|
||||||
ExtTestPlanApiCaseMapper apiCaseBatchMapper = sqlSession.getMapper(ExtTestPlanApiCaseMapper.class);
|
ExtTestPlanApiCaseMapper apiCaseBatchMapper = sqlSession.getMapper(ExtTestPlanApiCaseMapper.class);
|
||||||
|
|
||||||
for (TestPlanDTO testPlan : list) {
|
for (TestPlanDTO testPlan : list) {
|
||||||
if (scenarioIds != null) {
|
if (!set.isEmpty()) {
|
||||||
for (String scenarioId : scenarioIds) {
|
set.forEach(id -> {
|
||||||
|
Map<String, String> newEnvMap = new HashMap<>(16);
|
||||||
|
if (envMap != null && !envMap.isEmpty()) {
|
||||||
|
List<String> lt = mapping.get(id);
|
||||||
|
lt.forEach(l -> {
|
||||||
|
newEnvMap.put(l, envMap.get(l));
|
||||||
|
});
|
||||||
|
}
|
||||||
TestPlanApiScenario testPlanApiScenario = new TestPlanApiScenario();
|
TestPlanApiScenario testPlanApiScenario = new TestPlanApiScenario();
|
||||||
testPlanApiScenario.setId(UUID.randomUUID().toString());
|
testPlanApiScenario.setId(UUID.randomUUID().toString());
|
||||||
testPlanApiScenario.setApiScenarioId(scenarioId);
|
testPlanApiScenario.setApiScenarioId(id);
|
||||||
testPlanApiScenario.setTestPlanId(testPlan.getId());
|
testPlanApiScenario.setTestPlanId(testPlan.getId());
|
||||||
testPlanApiScenario.setCreateTime(System.currentTimeMillis());
|
testPlanApiScenario.setCreateTime(System.currentTimeMillis());
|
||||||
testPlanApiScenario.setUpdateTime(System.currentTimeMillis());
|
testPlanApiScenario.setUpdateTime(System.currentTimeMillis());
|
||||||
|
testPlanApiScenario.setEnvironment(JSON.toJSONString(newEnvMap));
|
||||||
scenarioBatchMapper.insertIfNotExists(testPlanApiScenario);
|
scenarioBatchMapper.insertIfNotExists(testPlanApiScenario);
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
if (request.getApiIds() != null) {
|
if (request.getApiIds() != null) {
|
||||||
for (String caseId : request.getApiIds()) {
|
for (String caseId : request.getApiIds()) {
|
||||||
|
|
|
@ -5,8 +5,8 @@
|
||||||
|
|
||||||
<insert id="insertIfNotExists" parameterType="io.metersphere.base.domain.TestPlanApiScenario">
|
<insert id="insertIfNotExists" parameterType="io.metersphere.base.domain.TestPlanApiScenario">
|
||||||
-- 查询没有数据再插入
|
-- 查询没有数据再插入
|
||||||
INSERT INTO test_plan_api_scenario(id, test_plan_id, api_scenario_id, create_time, update_time)
|
INSERT INTO test_plan_api_scenario(id, test_plan_id, api_scenario_id, create_time, update_time, environment)
|
||||||
SELECT #{request.id}, #{request.testPlanId}, #{request.apiScenarioId}, #{request.createTime}, #{request.updateTime}
|
SELECT #{request.id}, #{request.testPlanId}, #{request.apiScenarioId}, #{request.createTime}, #{request.updateTime}, #{request.environment}
|
||||||
FROM DUAL
|
FROM DUAL
|
||||||
WHERE NOT EXISTS(
|
WHERE NOT EXISTS(
|
||||||
SELECT id FROM
|
SELECT id FROM
|
||||||
|
|
|
@ -145,7 +145,7 @@
|
||||||
<!--测试计划-->
|
<!--测试计划-->
|
||||||
<el-drawer :visible.sync="planVisible" :destroy-on-close="true" direction="ltr" :withHeader="false"
|
<el-drawer :visible.sync="planVisible" :destroy-on-close="true" direction="ltr" :withHeader="false"
|
||||||
:title="$t('test_track.plan_view.test_result')" :modal="false" size="90%">
|
:title="$t('test_track.plan_view.test_result')" :modal="false" size="90%">
|
||||||
<ms-test-plan-list @addTestPlan="addTestPlan" @cancel="cancel"/>
|
<ms-test-plan-list @addTestPlan="addTestPlan(arguments)" @cancel="cancel" ref="testPlanList" :row="selectRows"/>
|
||||||
</el-drawer>
|
</el-drawer>
|
||||||
</div>
|
</div>
|
||||||
</el-card>
|
</el-card>
|
||||||
|
@ -318,7 +318,7 @@
|
||||||
],
|
],
|
||||||
principal: [],
|
principal: [],
|
||||||
environmentId: [],
|
environmentId: [],
|
||||||
projectEnv: []
|
projectEnv: [],
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -496,17 +496,31 @@
|
||||||
cancel() {
|
cancel() {
|
||||||
this.planVisible = false;
|
this.planVisible = false;
|
||||||
},
|
},
|
||||||
addTestPlan(plans) {
|
addTestPlan(params) {
|
||||||
let obj = {planIds: plans, scenarioIds: this.selection};
|
let obj = {planIds: params[0], scenarioIds: this.selection};
|
||||||
|
|
||||||
obj.projectId = getCurrentProjectID();
|
// obj.projectId = getCurrentProjectID();
|
||||||
obj.selectAllDate = this.isSelectAllDate;
|
// obj.selectAllDate = this.isSelectAllDate;
|
||||||
obj.unSelectIds = this.unSelection;
|
// obj.unSelectIds = this.unSelection;
|
||||||
obj = Object.assign(obj, this.condition);
|
// obj = Object.assign(obj, this.condition);
|
||||||
|
|
||||||
|
// todo 选取全部数据
|
||||||
|
if (this.isSelectAllDate) {
|
||||||
|
this.$warning("暂不支持批量添加所有场景到测试计划!");
|
||||||
|
}
|
||||||
|
|
||||||
this.planVisible = false;
|
this.planVisible = false;
|
||||||
|
|
||||||
|
let map = new Map();
|
||||||
|
this.selectRows.forEach(row => {
|
||||||
|
map.set(row.id, row.projectIds);
|
||||||
|
})
|
||||||
|
obj.mapping = strMapToObj(map);
|
||||||
|
obj.envMap = strMapToObj(params[1]);
|
||||||
|
|
||||||
this.$post("/api/automation/scenario/plan", obj, response => {
|
this.$post("/api/automation/scenario/plan", obj, response => {
|
||||||
this.$success(this.$t("commons.save_success"));
|
this.$success(this.$t("commons.save_success"));
|
||||||
|
this.search();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
getReport() {
|
getReport() {
|
||||||
|
|
|
@ -3,9 +3,11 @@
|
||||||
<template v-slot:header>
|
<template v-slot:header>
|
||||||
<ms-table-header :is-tester-permission="true" :condition.sync="condition"
|
<ms-table-header :is-tester-permission="true" :condition.sync="condition"
|
||||||
@search="initTableData" :showCreate="false"
|
@search="initTableData" :showCreate="false"
|
||||||
:title="$t('test_track.plan.test_plan')"/>
|
:title="$t('test_track.plan.test_plan')">
|
||||||
|
</ms-table-header>
|
||||||
</template>
|
</template>
|
||||||
|
<env-popover :env-map="projectEnvMap" :project-ids="projectIds" @setProjectEnvMap="setProjectEnvMap"
|
||||||
|
:project-list="projectList" ref="envPopover" class="env-popover" style="float: right; margin-top: 4px;"/>
|
||||||
<el-table
|
<el-table
|
||||||
border
|
border
|
||||||
class="adjust-table"
|
class="adjust-table"
|
||||||
|
@ -142,7 +144,7 @@ import MsTableOperatorButton from "../../../../common/components/MsTableOperator
|
||||||
import MsTableOperator from "../../../../common/components/MsTableOperator";
|
import MsTableOperator from "../../../../common/components/MsTableOperator";
|
||||||
import PlanStatusTableItem from "../../../../track/common/tableItems/plan/PlanStatusTableItem";
|
import PlanStatusTableItem from "../../../../track/common/tableItems/plan/PlanStatusTableItem";
|
||||||
import PlanStageTableItem from "../../../../track/common/tableItems/plan/PlanStageTableItem";
|
import PlanStageTableItem from "../../../../track/common/tableItems/plan/PlanStageTableItem";
|
||||||
import {checkoutTestManagerOrTestUser} from "@/common/js/utils";
|
import {checkoutTestManagerOrTestUser, strMapToObj} from "@/common/js/utils";
|
||||||
import TestReportTemplateList from "../../../../track/plan/view/comonents/TestReportTemplateList";
|
import TestReportTemplateList from "../../../../track/plan/view/comonents/TestReportTemplateList";
|
||||||
import TestCaseReportView from "../../../../track/plan/view/comonents/report/TestCaseReportView";
|
import TestCaseReportView from "../../../../track/plan/view/comonents/report/TestCaseReportView";
|
||||||
import MsDeleteConfirm from "../../../../common/components/MsDeleteConfirm";
|
import MsDeleteConfirm from "../../../../common/components/MsDeleteConfirm";
|
||||||
|
@ -150,6 +152,7 @@ import {TEST_PLAN_CONFIGS} from "../../../../common/components/search/search-com
|
||||||
import {LIST_CHANGE, TrackEvent} from "@/business/components/common/head/ListEvent";
|
import {LIST_CHANGE, TrackEvent} from "@/business/components/common/head/ListEvent";
|
||||||
import {getCurrentProjectID} from "../../../../../../common/js/utils";
|
import {getCurrentProjectID} from "../../../../../../common/js/utils";
|
||||||
import {_filter, _sort} from "@/common/js/tableUtils";
|
import {_filter, _sort} from "@/common/js/tableUtils";
|
||||||
|
import EnvPopover from "@/business/components/api/automation/scenario/EnvPopover";
|
||||||
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
@ -160,7 +163,10 @@ export default {
|
||||||
TestReportTemplateList,
|
TestReportTemplateList,
|
||||||
PlanStageTableItem,
|
PlanStageTableItem,
|
||||||
PlanStatusTableItem,
|
PlanStatusTableItem,
|
||||||
MsTableOperator, MsTableOperatorButton, MsDialogFooter, MsTableHeader, MsCreateBox, MsTablePagination
|
MsTableOperator, MsTableOperatorButton, MsDialogFooter, MsTableHeader, MsCreateBox, MsTablePagination, EnvPopover
|
||||||
|
},
|
||||||
|
props: {
|
||||||
|
row: Set
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
|
@ -187,6 +193,9 @@ export default {
|
||||||
{text: this.$t('test_track.plan.system_test'), value: 'system'},
|
{text: this.$t('test_track.plan.system_test'), value: 'system'},
|
||||||
{text: this.$t('test_track.plan.regression_test'), value: 'regression'},
|
{text: this.$t('test_track.plan.regression_test'), value: 'regression'},
|
||||||
],
|
],
|
||||||
|
projectEnvMap: new Map(),
|
||||||
|
projectList: [],
|
||||||
|
projectIds: new Set()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
|
@ -200,22 +209,37 @@ export default {
|
||||||
this.projectId = this.$route.params.projectId;
|
this.projectId = this.$route.params.projectId;
|
||||||
this.isTestManagerOrTestUser = checkoutTestManagerOrTestUser();
|
this.isTestManagerOrTestUser = checkoutTestManagerOrTestUser();
|
||||||
this.initTableData();
|
this.initTableData();
|
||||||
|
this.setScenarioSelectRows(this.row);
|
||||||
|
this.getWsProjects();
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
confirm() {
|
confirm() {
|
||||||
if (this.selection.length==0) {
|
if (this.selection.length==0) {
|
||||||
this.$warning(this.$t("api_test.definition.request.test_plan_select"));
|
this.$warning(this.$t("api_test.definition.request.test_plan_select"));
|
||||||
}else{
|
}else{
|
||||||
this.$emit('addTestPlan', this.selection);
|
const sign = this.checkEnv();
|
||||||
|
if (!sign) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
this.$emit('addTestPlan', this.selection, this.projectEnvMap);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
cancel(){
|
cancel(){
|
||||||
this.$emit('cancel');
|
this.$emit('cancel');
|
||||||
},
|
},
|
||||||
|
setProjectEnvMap(projectEnvMap) {
|
||||||
|
this.projectEnvMap = projectEnvMap;
|
||||||
|
},
|
||||||
select(selection) {
|
select(selection) {
|
||||||
this.selection = selection.map(s => s.id);
|
this.selection = selection.map(s => s.id);
|
||||||
this.$emit('selection', selection);
|
this.$emit('selection', selection);
|
||||||
},
|
},
|
||||||
|
setScenarioSelectRows(rows) {
|
||||||
|
this.projectIds.clear();
|
||||||
|
rows.forEach(row => {
|
||||||
|
row.projectIds.forEach(id => this.projectIds.add(id));
|
||||||
|
})
|
||||||
|
},
|
||||||
initTableData() {
|
initTableData() {
|
||||||
if (this.planId) {
|
if (this.planId) {
|
||||||
this.condition.planId = this.planId;
|
this.condition.planId = this.planId;
|
||||||
|
@ -284,6 +308,14 @@ export default {
|
||||||
this.$refs.testCaseReportView.open(planId, reportId);
|
this.$refs.testCaseReportView.open(planId, reportId);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
checkEnv() {
|
||||||
|
return this.$refs.envPopover.checkEnv();
|
||||||
|
},
|
||||||
|
getWsProjects() {
|
||||||
|
this.$get("/project/listAll", res => {
|
||||||
|
this.projectList = res.data;
|
||||||
|
})
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
Loading…
Reference in New Issue