提交 489077ad 编写于 作者: C Captain.B

Merge remote-tracking branch 'origin/master'

......@@ -86,7 +86,7 @@ public class ApiAutomationController {
}
@GetMapping("/getApiScenario/{id}")
public ApiScenario getScenarioDefinition(@PathVariable String id) {
public ApiScenarioDTO getScenarioDefinition(@PathVariable String id) {
return apiAutomationService.getApiScenario(id);
}
......
......@@ -18,4 +18,6 @@ public class ApiScenarioDTO extends ApiScenarioWithBLOBs {
* 场景跨项目ID
*/
private List<String> projectIds;
private String caseId;
}
......@@ -94,42 +94,38 @@ public class ApiAutomationService {
public List<ApiScenarioDTO> list(ApiScenarioRequest request) {
request = this.initRequest(request, true, true);
List<ApiScenarioDTO> list = extApiScenarioMapper.list(request);
setApiScenarioProjectIds(list);
return list;
}
public List<ApiScenarioDTO> listReview(ApiScenarioRequest request) {
request = this.initRequest(request, true, true);
List<ApiScenarioDTO> list = extApiScenarioMapper.listReview(request);
setApiScenarioProjectIds(list);
return list;
}
private void setApiScenarioProjectIds(List<ApiScenarioDTO> list) {
private void setApiScenarioProjectIds(ApiScenarioDTO data) {
// 如果场景步骤涉及多项目,则把涉及到的项目ID保存在projectIds属性
list.forEach(data -> {
List<String> idList = new ArrayList<>();
String definition = data.getScenarioDefinition();
if (StringUtils.isNotBlank(definition)) {
RunDefinitionRequest d = JSON.parseObject(definition, RunDefinitionRequest.class);
if (d != null) {
Map<String, String> map = d.getEnvironmentMap();
if (map != null) {
if (map.isEmpty()) {
List<String> ids = (List<String>) JSONPath.read(definition, "$..projectId");
idList.addAll(new HashSet<>(ids));
} else {
Set<String> set = d.getEnvironmentMap().keySet();
idList = new ArrayList<>(set);
}
List<String> idList = new ArrayList<>();
String definition = data.getScenarioDefinition();
if (StringUtils.isNotBlank(definition)) {
RunDefinitionRequest d = JSON.parseObject(definition, RunDefinitionRequest.class);
if (d != null) {
Map<String, String> map = d.getEnvironmentMap();
if (map != null) {
if (map.isEmpty()) {
List<String> ids = (List<String>) JSONPath.read(definition, "$..projectId");
idList.addAll(new HashSet<>(ids));
} else {
// 兼容历史数据,无EnvironmentMap直接赋值场景所属项目
idList.add(data.getProjectId());
Set<String> set = d.getEnvironmentMap().keySet();
idList = new ArrayList<>(set);
}
} else {
// 兼容历史数据,无EnvironmentMap直接赋值场景所属项目
idList.add(data.getProjectId());
}
}
data.setProjectIds(idList);
});
}
data.setProjectIds(idList);
}
/**
......@@ -333,8 +329,12 @@ public class ApiAutomationService {
}
}
public ApiScenarioWithBLOBs getApiScenario(String id) {
return apiScenarioMapper.selectByPrimaryKey(id);
public ApiScenarioDTO getApiScenario(String id) {
ApiScenarioDTO apiScenarioDTO = new ApiScenarioDTO();
ApiScenarioWithBLOBs scenarioWithBLOBs = apiScenarioMapper.selectByPrimaryKey(id);
BeanUtils.copyBean(apiScenarioDTO, scenarioWithBLOBs);
setApiScenarioProjectIds(apiScenarioDTO);
return apiScenarioDTO;
}
public List<ApiScenarioWithBLOBs> getApiScenarios(List<String> ids) {
......
......@@ -134,7 +134,6 @@
</sql>
<select id="list" resultMap="BaseResultMap">
select api_scenario.id, api_scenario.project_id, api_scenario.tags, api_scenario.user_id, api_scenario.num,
api_scenario.scenario_definition,
api_scenario.api_scenario_module_id,api_scenario.module_path, api_scenario.name, api_scenario.level,
api_scenario.status, api_scenario.principal, api_scenario.step_total, api_scenario.follow_people,
api_scenario.last_result,api_scenario.pass_rate,api_scenario.report_id,
......@@ -339,7 +338,6 @@
</select>
<select id="listReview" resultMap="BaseResultMap">
select api_scenario.id, api_scenario.project_id, api_scenario.tags, api_scenario.user_id, api_scenario.num,
api_scenario.scenario_definition,
api_scenario.api_scenario_module_id,api_scenario.module_path, api_scenario.name, api_scenario.level,
api_scenario.status, api_scenario.principal, api_scenario.step_total, api_scenario.follow_people,
api_scenario.last_result,api_scenario.pass_rate,api_scenario.report_id,
......
......@@ -101,6 +101,12 @@ public class TestPlanTestCaseController {
testPlanTestCaseService.editTestCase(testPlanTestCase);
}
@PostMapping("/minder/edit")
@RequiresRoles(value = {RoleConstants.TEST_USER, RoleConstants.TEST_MANAGER}, logical = Logical.OR)
public void editTestCaseForMinder(@RequestBody List<TestPlanTestCaseWithBLOBs> testPlanTestCases) {
testPlanTestCaseService.editTestCaseForMinder(testPlanTestCases);
}
@PostMapping("/batch/edit")
@RequiresRoles(value = {RoleConstants.TEST_USER, RoleConstants.TEST_MANAGER}, logical = Logical.OR)
public void editTestCaseBath(@RequestBody TestPlanCaseBatchRequest request) {
......
package io.metersphere.track.service;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONPath;
import io.metersphere.api.dto.automation.ApiScenarioDTO;
import io.metersphere.api.dto.automation.ApiScenarioRequest;
import io.metersphere.api.dto.automation.RunScenarioRequest;
import io.metersphere.api.dto.automation.TestPlanScenarioRequest;
import io.metersphere.api.dto.definition.RunDefinitionRequest;
import io.metersphere.api.service.ApiAutomationService;
import io.metersphere.api.service.ApiScenarioReportService;
import io.metersphere.base.domain.TestCaseReviewScenario;
import io.metersphere.base.domain.TestCaseReviewScenarioExample;
import io.metersphere.base.domain.TestPlanApiScenario;
import io.metersphere.base.domain.TestPlanApiScenarioExample;
import io.metersphere.base.mapper.TestCaseReviewScenarioMapper;
import io.metersphere.base.mapper.TestPlanApiScenarioMapper;
import io.metersphere.base.mapper.ext.ExtTestCaseReviewScenarioCaseMapper;
import io.metersphere.base.mapper.ext.ExtTestPlanScenarioCaseMapper;
import io.metersphere.commons.constants.ApiRunMode;
import io.metersphere.commons.utils.ServiceUtils;
import io.metersphere.track.dto.RelevanceScenarioRequest;
......@@ -45,46 +39,15 @@ public class TestCaseReviewScenarioCaseService {
request.setProjectId(null);
request.setOrders(ServiceUtils.getDefaultOrder(request.getOrders()));
List<ApiScenarioDTO> apiTestCases = extTestCaseReviewScenarioCaseMapper.list(request);
setApiScenarioProjectIds(apiTestCases);
if (CollectionUtils.isEmpty(apiTestCases)) {
return apiTestCases;
}
return apiTestCases;
}
private void setApiScenarioProjectIds(List<ApiScenarioDTO> list) {
// 如果场景步骤涉及多项目,则把涉及到的项目ID保存在projectIds属性
list.forEach(data -> {
List<String> idList = new ArrayList<>();
String definition = data.getScenarioDefinition();
if (org.apache.commons.lang3.StringUtils.isNotBlank(definition)) {
RunDefinitionRequest d = JSON.parseObject(definition, RunDefinitionRequest.class);
if (d != null) {
Map<String, String> map = d.getEnvironmentMap();
if (map != null) {
if (map.isEmpty()) {
List<String> ids = (List<String>) JSONPath.read(definition, "$..projectId");
idList.addAll(new HashSet<>(ids));
} else {
Set<String> set = d.getEnvironmentMap().keySet();
idList = new ArrayList<>(set);
}
} else {
// 兼容历史数据,无EnvironmentMap直接赋值场景所属项目
idList.add(data.getProjectId());
}
}
}
data.setProjectIds(idList);
});
}
public List<ApiScenarioDTO> relevanceList(ApiScenarioRequest request) {
request.setNotInTestPlan(true);
List<ApiScenarioDTO> list = apiAutomationService.listReview(request);
setApiScenarioProjectIds(list);
return list;
}
......
......@@ -42,46 +42,15 @@ public class TestPlanScenarioCaseService {
request.setProjectId(null);
request.setOrders(ServiceUtils.getDefaultOrder(request.getOrders()));
List<ApiScenarioDTO> apiTestCases = extTestPlanScenarioCaseMapper.list(request);
setApiScenarioProjectIds(apiTestCases);
if (CollectionUtils.isEmpty(apiTestCases)) {
return apiTestCases;
}
return apiTestCases;
}
private void setApiScenarioProjectIds(List<ApiScenarioDTO> list) {
// 如果场景步骤涉及多项目,则把涉及到的项目ID保存在projectIds属性
list.forEach(data -> {
List<String> idList = new ArrayList<>();
String definition = data.getScenarioDefinition();
if (org.apache.commons.lang3.StringUtils.isNotBlank(definition)) {
RunDefinitionRequest d = JSON.parseObject(definition, RunDefinitionRequest.class);
if (d != null) {
Map<String, String> map = d.getEnvironmentMap();
if (map != null) {
if (map.isEmpty()) {
List<String> ids = (List<String>) JSONPath.read(definition, "$..projectId");
idList.addAll(new HashSet<>(ids));
} else {
Set<String> set = d.getEnvironmentMap().keySet();
idList = new ArrayList<>(set);
}
} else {
// 兼容历史数据,无EnvironmentMap直接赋值场景所属项目
idList.add(data.getProjectId());
}
}
}
data.setProjectIds(idList);
});
}
public List<ApiScenarioDTO> relevanceList(ApiScenarioRequest request) {
request.setNotInTestPlan(true);
List<ApiScenarioDTO> list = apiAutomationService.list(request);
setApiScenarioProjectIds(list);
return list;
}
......
......@@ -154,4 +154,11 @@ public class TestPlanTestCaseService {
public List<TestPlanCaseDTO> listForMinder(String planId) {
return extTestPlanTestCaseMapper.listForMinder(planId);
}
public void editTestCaseForMinder(List<TestPlanTestCaseWithBLOBs> testPlanTestCases) {
testPlanTestCases.forEach(item -> {
item.setUpdateTime(System.currentTimeMillis());
testPlanTestCaseMapper.updateByPrimaryKeySelective(item);
});
}
}
......@@ -172,6 +172,8 @@ public class TestReviewTestCaseService {
testCase.setId(item.getCaseId());
testCase.setReviewStatus(item.getStatus());
testCaseList.add(testCase);
testCase.setUpdateTime(System.currentTimeMillis());
item.setUpdateTime(System.currentTimeMillis());
testCaseReviewTestCaseMapper.updateByPrimaryKeySelective(item);
});
testCaseList.forEach(testCaseMapper::updateByPrimaryKeySelective);
......
......@@ -49,7 +49,7 @@
"xml-js": "^1.6.11",
"yan-progress": "^1.0.3",
"jsonpath": "^1.1.0",
"vue-minder-editor-plus": "^1.0.17",
"vue-minder-editor-plus": "^1.0.18",
"jsencrypt": "^3.1.0"
},
"devDependencies": {
......
......@@ -439,7 +439,7 @@
},
handleBatchEdit() {
this.$refs.batchEdit.open(this.selectDataCounts);
this.$refs.batchEdit.setScenarioSelectRows(this.selectRows);
this.$refs.batchEdit.setScenarioSelectRows(this.selectRows, "scenario");
},
handleBatchMove() {
this.$refs.testBatchMove.open(this.moduleTree, [], this.moduleOptions);
......@@ -457,11 +457,7 @@
// 批量修改环境
if (form.type === 'projectEnv') {
let param = {};
let map = new Map();
this.selectRows.forEach(row => {
map.set(row.id, row.projectIds);
})
param.mapping = strMapToObj(map);
param.mapping = strMapToObj(form.map);
param.envMap = strMapToObj(form.projectEnvMap);
this.$post('/api/automation/batch/update/env', param, () => {
this.$success(this.$t('commons.save_success'));
......@@ -519,11 +515,7 @@
this.planVisible = false;
let map = new Map();
this.selectRows.forEach(row => {
map.set(row.id, row.projectIds);
})
obj.mapping = strMapToObj(map);
obj.mapping = strMapToObj(params[2]);
obj.envMap = strMapToObj(params[1]);
this.$post("/api/automation/scenario/plan", obj, response => {
......
......@@ -195,7 +195,8 @@ export default {
],
projectEnvMap: new Map(),
projectList: [],
projectIds: new Set()
projectIds: new Set(),
map: new Map(),
}
},
watch: {
......@@ -221,7 +222,7 @@ export default {
if (!sign) {
return false;
}
this.$emit('addTestPlan', this.selection, this.projectEnvMap);
this.$emit('addTestPlan', this.selection, this.projectEnvMap, this.map);
}
},
cancel(){
......@@ -237,7 +238,11 @@ export default {
setScenarioSelectRows(rows) {
this.projectIds.clear();
rows.forEach(row => {
row.projectIds.forEach(id => this.projectIds.add(id));
this.result = this.$get('/api/automation/getApiScenario/' + row.id, res => {
let data = res.data;
data.projectIds.forEach(d => this.projectIds.add(d));
this.map.set(row.id, data.projectIds);
})
})
},
initTableData() {
......
......@@ -7,6 +7,7 @@
:height="700"
:progress-enable="false"
:tags="tags"
:distinct-tags="distinctTags"
@save="save"
/>
</div>
......@@ -36,6 +37,12 @@ export default {
return []
}
},
distinctTags: {
type: Array,
default() {
return []
}
}
},
data() {
return {
......
......@@ -54,7 +54,6 @@ export default {
/*this.optionalField = items*/
},
saveHeader() {
console.log(this.type)
let param = {
userId: getCurrentUser().id,
type: this.type,
......
......@@ -7,6 +7,7 @@
class="batch-edit-dialog"
:destroy-on-close="true"
@close="handleClose"
v-loading="result.loading"
>
<el-form :model="form" label-position="right" label-width="150px" size="medium" ref="form" :rules="rules">
<el-form-item :label="$t('test_track.case.batch_update', [size])" prop="type">
......@@ -72,7 +73,10 @@
projectList: [],
projectIds: new Set(),
selectRows: new Set(),
projectEnvMap: new Map()
projectEnvMap: new Map(),
map: new Map(),
isScenario: '',
result: {}
}
},
methods: {
......@@ -84,6 +88,7 @@
if (!this.$refs.envPopover.checkEnv()) {
return false;
}
this.form.map = this.map;
}
this.$emit("batchEdit", this.form);
this.dialogVisible = false;
......@@ -113,12 +118,9 @@
this.projectIds.add(row.projectId)
})
},
setScenarioSelectRows(rows) {
setScenarioSelectRows(rows, sign) {
this.selectRows = rows;
this.projectIds.clear();
this.selectRows.forEach(row => {
row.projectIds.forEach(id => this.projectIds.add(id));
})
this.isScenario = sign;
},
handleClose() {
this.form = {};
......@@ -127,6 +129,17 @@
},
changeType(val) {
this.$set(this.form, "value", "");
if (val === 'projectEnv' && this.isScenario !== '') {
this.projectIds.clear();
this.selectRows.forEach(row => {
let id = this.isScenario === 'scenario' ? row.id : row.caseId;
this.result = this.$get('/api/automation/getApiScenario/' + id, res => {
let data = res.data;
data.projectIds.forEach(d => this.projectIds.add(d));
this.map.set(row.id, data.projectIds);
})
})
}
this.filterable = val === "maintainer" || val === "executor";
this.options = this.valueArr[val];
this.typeArr.forEach(item => {
......
......@@ -679,8 +679,6 @@ export default {
return param;
},
getOption(param) {
console.log(this.type)
console.log("3452")
let formData = new FormData();
let type = this.type
if (this.type === 'copy') {
......
......@@ -3,6 +3,7 @@
v-loading="result.loading"
:tree-nodes="treeNodes"
:data-map="dataMap"
:tags="tags"
@save="save"
/>
</template>
......@@ -17,6 +18,7 @@ name: "TestCaseMinder",
return{
testCase: [],
dataMap: new Map(),
tags: ['用例', '前置条件', '备注'],
result: {}
}
},
......
......@@ -3,6 +3,8 @@
v-loading="result.loading"
:tree-nodes="treeNodes"
:data-map="dataMap"
:tags="tags"
:distinct-tags="[...tags, '未开始']"
@save="save"
/>
</template>
......@@ -15,9 +17,9 @@ name: "TestPlanMinder",
components: {MsModuleMinder},
data() {
return{
testCase: [],
dataMap: new Map(),
result: {}
result: {},
tags: ['通过', '失败', '阻塞', '跳过'],
}
},
props: {
......@@ -44,24 +46,30 @@ name: "TestPlanMinder",
getTestCases() {
if (this.projectId) {
this.result = this.$get('/test/plan/case/list/minder/' + this.planId, response => {
this.testCase = response.data;
this.dataMap = getTestCaseDataMap(this.testCase);
this.dataMap = getTestCaseDataMap(response.data, true, (data, item) => {
if (item.stats === 'Pass') {
data.resource.push("通过");
} else if (item.reviewStatus === 'Failure') {
data.resource.push("失败");
} else if (item.reviewStatus === 'Blocking') {
data.resource.push("阻塞");
} else if (item.reviewStatus === 'Skip') {
data.resource.push("跳过");
} else {
data.resource.push("未开始");
}
});
});
}
},
save(data) {
// let saveCases = [];
// this.buildSaveCase(data.root, saveCases, undefined);
// console.log(saveCases);
// let param = {
// projectId: this.projectId,
// data: saveCases
// }
// this.result = this.$post('/test/case/minder/edit', param, () => {
// this.$success(this.$t('commons.save_success'));
// });
let saveCases = [];
this.buildSaveCase(data.root, saveCases);
this.result = this.$post('/test/plan/case/minder/edit', saveCases, () => {
this.$success(this.$t('commons.save_success'));
});
},
buildSaveCase(root, saveCases, parent) {
buildSaveCase(root, saveCases) {
let data = root.data;
if (data.resource && data.resource.indexOf("用例") > -1) {
this._buildSaveCase(root, saveCases, parent);
......@@ -73,52 +81,27 @@ name: "TestPlanMinder",
}
}
},
_buildSaveCase(node, saveCases, parent) {
_buildSaveCase(node, saveCases) {
let data = node.data;
let isChange = false;
if (!data.changed) {
return;
}
let testCase = {
id: data.id,
name: data.text,
nodeId: parent ? parent.id : "",
nodePath: parent ? parent.path : "",
type: data.type ? data.type : 'functional',
method: data.method ? data.method : 'manual',
maintainer: data.maintainer,
priority: 'P' + data.priority,
};
if (data.changed) isChange = true;
let steps = [];
let stepNum = 1;
if (node.children) {
node.children.forEach((childNode) => {
let childData = childNode.data;
if (childData.resource && childData.resource.indexOf('前置条件') > -1) {
testCase.prerequisite = childData.text;
} else if (childData.resource && childData.resource.indexOf('备注') > -1) {
testCase.remark = childData.text;
} else {
// 测试步骤
let step = {};
step.num = stepNum++;
step.desc = childData.text;
if (childNode.children) {
let result = "";
childNode.children.forEach((child) => {
result += child.data.text;
if (child.data.changed) isChange = true;
})
step.result = result;
}
steps.push(step);
}
if (childData.changed) isChange = true;
})
}
testCase.steps = JSON.stringify(steps);
if (isChange) {
saveCases.push(testCase);
if (data.resource.length > 1) {
if (data.resource.indexOf('失败') > -1) {
testCase.status = 'Failure';
} else if (data.resource.indexOf('通过') > -1) {
testCase.status = 'Pass';
} else if (data.resource.indexOf('阻塞') > -1) {
testCase.status = 'Blocking';
} else if (data.resource.indexOf('跳过') > -1) {
testCase.status = 'Skip';
}
}
},
saveCases.push(testCase);
}
}
}
</script>
......
......@@ -4,6 +4,7 @@
:tree-nodes="treeNodes"
:data-map="dataMap"
:tags="tags"
:distinct-tags="[...tags, '未开始']"
@save="save"
/>
</template>
......@@ -16,7 +17,6 @@ name: "TestReviewMinder",
components: {MsModuleMinder},
data() {
return{
testCase: [],
dataMap: new Map(),
tags: ['通过', '不通过'],
result: {}
......@@ -60,10 +60,8 @@ name: "TestReviewMinder",
}
},
save(data) {
console.log(data);
let saveCases = [];
this.buildSaveCase(data.root, saveCases);
console.log(saveCases);
this.result = this.$post('/test/review/case/minder/edit', saveCases, () => {
this.$success(this.$t('commons.save_success'));
});
......@@ -91,9 +89,9 @@ name: "TestReviewMinder",
// name: data.text,
};
if (data.resource.length > 1) {
if (data.resource.indexOf('不通过')) {
if (data.resource.indexOf('不通过') > -1) {
testCase.status = 'UnPass';
} else if (data.resource.indexOf('通过')) {
} else if (data.resource.indexOf('通过') > -1) {
testCase.status = 'Pass';
}
}
......
......@@ -42,11 +42,11 @@ function parseChildren(nodeItem, item, isDisable) {
let children = [];
_parseChildren(children, item.prerequisite, "前置条件", isDisable);
item.steps.forEach((step) => {
let descNode = _parseChildren(children, step.desc, "测试步骤", isDisable);
let descNode = _parseChildren(children, step.desc, undefined, isDisable);
if (descNode) {
descNode.data.num = step.num;
descNode.children = [];
_parseChildren(descNode.children, step.result, "预期结果", isDisable);
_parseChildren(descNode.children, step.result, undefined, isDisable);
}
});
_parseChildren(children, item.remark, "备注", isDisable);
......@@ -58,7 +58,7 @@ function _parseChildren(children, k, v, isDisable) {
let node = {
data: {
text: k,
resource: [v]
resource: v ? [v] : []
}
}
if (isDisable) {
......
......@@ -93,6 +93,7 @@
projectEnvMap: new Map(),
projectList: [],
projectIds: new Set(),
map: new Map()
}
},
watch: {
......@@ -159,8 +160,10 @@
initProjectIds() {
this.projectIds.clear();
this.selectRows.forEach(row => {
row.projectIds.forEach(id => {
this.projectIds.add(id);
this.result = this.$get('/api/automation/getApiScenario/' + row.id, res => {
let data = res.data;
data.projectIds.forEach(d => this.projectIds.add(d));
this.map.set(row.id, data.projectIds);
})
})
},
......
......@@ -104,12 +104,8 @@
}
let param = {};
let url = '/api/automation/relevance';
let rows = this.$refs.apiScenarioList.selectRows;
const envMap = this.$refs.apiScenarioList.projectEnvMap;
let map = new Map();
rows.forEach(row => {
map.set(row.id, row.projectIds);
})
let map = this.$refs.apiScenarioList.map;
param.planId = this.planId;
param.mapping = strMapToObj(map);
param.envMap = strMapToObj(envMap);
......
......@@ -358,15 +358,11 @@ export default {
},
handleBatchEdit() {
this.$refs.batchEdit.open(this.selectRows.size);
this.$refs.batchEdit.setScenarioSelectRows(this.selectRows);
this.$refs.batchEdit.setScenarioSelectRows(this.selectRows, "planScenario");
},
batchEdit(form) {
let param = {};
let map = new Map();
this.selectRows.forEach(row => {
map.set(row.id, row.projectIds);
})
param.mapping = strMapToObj(map);
param.mapping = strMapToObj(form.map);
param.envMap = strMapToObj(form.projectEnvMap);
if (this.planId) {
this.$post('/test/plan/scenario/case/batch/update/env', param, () => {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册