refactor(测试跟踪): 导出功能用例代码优化
--story=1008224 --user=陈建星 用例导出/导入支持自定义字段 https://www.tapd.cn/55049933/s/1225482 refactor(测试跟踪): ddd --story=1008224 --user=陈建星 用例导出/导入支持自定义字段 https://www.tapd.cn/55049933/s/1225482
This commit is contained in:
parent
4850dcab82
commit
09acd152f5
|
@ -1,7 +1,17 @@
|
|||
package io.metersphere.commons.constants;
|
||||
|
||||
public enum TestCaseCommentType {
|
||||
CASE,
|
||||
REVIEW,
|
||||
PLAN
|
||||
CASE("test_case_comment"),
|
||||
REVIEW("test_case_plan_comment"),
|
||||
PLAN("test_case_review_comment");
|
||||
|
||||
private String i18nKey;
|
||||
|
||||
TestCaseCommentType(String i18nKey) {
|
||||
this.i18nKey = i18nKey;
|
||||
}
|
||||
|
||||
public String getI18nKey() {
|
||||
return i18nKey;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,20 @@
|
|||
package io.metersphere.commons.constants;
|
||||
|
||||
public enum TestPlanTestCaseStatus {
|
||||
Prepare, Pass, Failure, Blocking, Skip, Underway
|
||||
Prepare("test_case_status_prepare"),
|
||||
Pass("execute_pass"),
|
||||
Failure("test_case_status_error"),
|
||||
Blocking("plan_case_status_blocking"),
|
||||
Skip("plan_case_status_skip"),
|
||||
Underway("test_case_status_prepare");
|
||||
|
||||
private String i18nKey;
|
||||
|
||||
TestPlanTestCaseStatus(String i18nKey) {
|
||||
this.i18nKey = i18nKey;
|
||||
}
|
||||
|
||||
public String getI18nKey() {
|
||||
return i18nKey;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,17 @@
|
|||
package io.metersphere.commons.constants;
|
||||
|
||||
public enum TestReviewCaseStatus {
|
||||
Prepare, Pass, UnPass
|
||||
Prepare("test_case_status_prepare"),
|
||||
Pass("execute_pass"),
|
||||
UnPass("execute_not_pass");
|
||||
|
||||
private String i18nKey;
|
||||
|
||||
TestReviewCaseStatus(String i18nKey) {
|
||||
this.i18nKey = i18nKey;
|
||||
}
|
||||
|
||||
public String getI18nKey() {
|
||||
return i18nKey;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,19 +21,17 @@ public class TestCaseExportCommendConverter implements TestCaseExportConverter {
|
|||
private HashMap<String, String> reviewCaseStatusMap = new HashMap<>();
|
||||
|
||||
public TestCaseExportCommendConverter() {
|
||||
commendTypeMap.put(TestCaseCommentType.CASE.name(), "test_case_comment");
|
||||
commendTypeMap.put(TestCaseCommentType.PLAN.name(), "test_case_plan_comment");
|
||||
commendTypeMap.put(TestCaseCommentType.REVIEW.name(), "test_case_review_comment");
|
||||
for (TestCaseCommentType value : TestCaseCommentType.values()) {
|
||||
commendTypeMap.put(value.name(), value.getI18nKey());
|
||||
}
|
||||
|
||||
planCaseStatusMap.put(TestPlanTestCaseStatus.Pass.name(), "execute_pass");
|
||||
planCaseStatusMap.put(TestPlanTestCaseStatus.Underway.name(), "test_case_status_prepare");
|
||||
planCaseStatusMap.put(TestPlanTestCaseStatus.Blocking.name(), "plan_case_status_blocking");
|
||||
planCaseStatusMap.put(TestPlanTestCaseStatus.Failure.name(), "test_case_status_error");
|
||||
planCaseStatusMap.put(TestPlanTestCaseStatus.Skip.name(), "plan_case_status_skip");
|
||||
for (TestPlanTestCaseStatus value : TestPlanTestCaseStatus.values()) {
|
||||
planCaseStatusMap.put(value.name(), value.getI18nKey());
|
||||
}
|
||||
|
||||
reviewCaseStatusMap.put(TestReviewCaseStatus.Prepare.name(), "test_case_status_prepare");
|
||||
reviewCaseStatusMap.put(TestReviewCaseStatus.Pass.name(), "execute_pass");
|
||||
reviewCaseStatusMap.put(TestReviewCaseStatus.UnPass.name(), "execute_not_pass");
|
||||
for (TestReviewCaseStatus value : TestReviewCaseStatus.values()) {
|
||||
reviewCaseStatusMap.put(value.name(), value.getI18nKey());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -11,11 +11,9 @@ public class TestCaseExportExecuteResultConverter implements TestCaseExportConve
|
|||
private Map<String, String> planCaseStatusMap = new HashMap<>();
|
||||
|
||||
public TestCaseExportExecuteResultConverter() {
|
||||
planCaseStatusMap.put(TestPlanTestCaseStatus.Pass.name(), "execute_pass");
|
||||
planCaseStatusMap.put(TestPlanTestCaseStatus.Underway.name(), "test_case_status_prepare");
|
||||
planCaseStatusMap.put(TestPlanTestCaseStatus.Blocking.name(), "plan_case_status_blocking");
|
||||
planCaseStatusMap.put(TestPlanTestCaseStatus.Failure.name(), "test_case_status_error");
|
||||
planCaseStatusMap.put(TestPlanTestCaseStatus.Skip.name(), "plan_case_status_skip");
|
||||
for (TestPlanTestCaseStatus value : TestPlanTestCaseStatus.values()) {
|
||||
planCaseStatusMap.put(value.name(), value.getI18nKey());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -11,9 +11,9 @@ public class TestCaseExportReviewResultConverter implements TestCaseExportConver
|
|||
private Map<String, String> reviewCaseStatusMap = new HashMap<>();
|
||||
|
||||
public TestCaseExportReviewResultConverter() {
|
||||
reviewCaseStatusMap.put(TestReviewCaseStatus.Prepare.name(), "test_case_status_prepare");
|
||||
reviewCaseStatusMap.put(TestReviewCaseStatus.Pass.name(), "execute_pass");
|
||||
reviewCaseStatusMap.put(TestReviewCaseStatus.UnPass.name(), "execute_not_pass");
|
||||
for (TestReviewCaseStatus value : TestReviewCaseStatus.values()) {
|
||||
reviewCaseStatusMap.put(value.name(), value.getI18nKey());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -7,6 +7,8 @@ import com.alibaba.fastjson.JSONArray;
|
|||
import io.metersphere.excel.constants.TestCaseImportFiled;
|
||||
import io.metersphere.i18n.Translator;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
|
||||
import org.apache.commons.collections.MapUtils;
|
||||
import org.apache.poi.ss.usermodel.Comment;
|
||||
import org.apache.poi.ss.usermodel.Drawing;
|
||||
import org.apache.poi.ss.usermodel.Sheet;
|
||||
|
@ -14,7 +16,6 @@ import org.apache.poi.xssf.usermodel.XSSFClientAnchor;
|
|||
import org.apache.poi.xssf.usermodel.XSSFRichTextString;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -26,7 +27,6 @@ import java.util.Map;
|
|||
public class FunctionCaseTemplateWriteHandler implements RowWriteHandler {
|
||||
|
||||
private boolean isNeedId;
|
||||
Map<String, Integer> rowDisposeIndexMap;
|
||||
Map<String, List<String>> caseLevelAndStatusValueMap;
|
||||
|
||||
private Integer idIndex;
|
||||
|
@ -37,15 +37,16 @@ public class FunctionCaseTemplateWriteHandler implements RowWriteHandler {
|
|||
private Integer statusIndex;
|
||||
private Integer stepModelIndex;
|
||||
|
||||
private Sheet sheet;
|
||||
private Drawing<?> drawingPatriarch;
|
||||
|
||||
public FunctionCaseTemplateWriteHandler(boolean isNeedId, List<List<String>> headList, Map<String, List<String>> caseLevelAndStatusValueMap) {
|
||||
this.isNeedId = isNeedId;
|
||||
rowDisposeIndexMap = this.buildFiledMap(headList);
|
||||
this.initIndex(headList);
|
||||
this.caseLevelAndStatusValueMap = caseLevelAndStatusValueMap;
|
||||
}
|
||||
|
||||
private Map<String, Integer> buildFiledMap(List<List<String>> headList) {
|
||||
Map<String, Integer> returnMap = new HashMap<>();
|
||||
|
||||
private void initIndex(List<List<String>> headList) {
|
||||
int index = 0;
|
||||
for (List<String> list : headList) {
|
||||
for (String head : list) {
|
||||
|
@ -67,48 +68,46 @@ public class FunctionCaseTemplateWriteHandler implements RowWriteHandler {
|
|||
index++;
|
||||
}
|
||||
}
|
||||
return returnMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterRowDispose(RowWriteHandlerContext context) {
|
||||
|
||||
if (BooleanUtils.isTrue(context.getHead())) {
|
||||
Sheet sheet = context.getWriteSheetHolder().getSheet();
|
||||
Drawing<?> drawingPatriarch = sheet.createDrawingPatriarch();
|
||||
sheet = context.getWriteSheetHolder().getSheet();
|
||||
drawingPatriarch = sheet.createDrawingPatriarch();
|
||||
|
||||
if (rowDisposeIndexMap != null) {
|
||||
if (isNeedId) {
|
||||
setComment(sheet, drawingPatriarch, idIndex, Translator.get("do_not_modify_header_order") + "," + Translator.get("id_required"));
|
||||
}
|
||||
if (isNeedId) {
|
||||
setComment(idIndex, Translator.get("do_not_modify_header_order").concat(",").concat(Translator.get("id_required")));
|
||||
}
|
||||
|
||||
setComment(sheet, drawingPatriarch, moduleIndex, Translator.get("module_created_automatically"));
|
||||
setComment(sheet, drawingPatriarch, maintainerIndex, Translator.get("please_input_project_member"));
|
||||
setComment(sheet, drawingPatriarch, tagIndex, Translator.get("tag_tip_pattern"));
|
||||
setComment(sheet, drawingPatriarch, stepModelIndex, Translator.get("step_model_tip"));
|
||||
setComment(moduleIndex, Translator.get("module_created_automatically"));
|
||||
setComment(maintainerIndex, Translator.get("please_input_project_member"));
|
||||
setComment(tagIndex, Translator.get("tag_tip_pattern"));
|
||||
setComment(stepModelIndex, Translator.get("step_model_tip"));
|
||||
|
||||
List<String> list = new ArrayList<>();
|
||||
if (caseLevelAndStatusValueMap != null && caseLevelAndStatusValueMap.containsKey("caseLevel")) {
|
||||
list = caseLevelAndStatusValueMap.get("caseLevel");
|
||||
}
|
||||
if (CollectionUtils.isEmpty(list)) {
|
||||
setComment(sheet, drawingPatriarch, priorityIndex, Translator.get("options") + "(P0、P1、P2、P3)");
|
||||
} else {
|
||||
setComment(sheet, drawingPatriarch, priorityIndex, Translator.get("options") + JSONArray.toJSONString(list));
|
||||
}
|
||||
List<String> list = new ArrayList<>();
|
||||
if (MapUtils.isNotEmpty(caseLevelAndStatusValueMap) && caseLevelAndStatusValueMap.containsKey("caseLevel")) {
|
||||
list = caseLevelAndStatusValueMap.get("caseLevel");
|
||||
}
|
||||
if (CollectionUtils.isEmpty(list)) {
|
||||
setComment(priorityIndex, Translator.get("options").concat("(P0、P1、P2、P3)"));
|
||||
} else {
|
||||
setComment(priorityIndex, Translator.get("options").concat(JSONArray.toJSONString(list)));
|
||||
}
|
||||
|
||||
list.clear();
|
||||
if (caseLevelAndStatusValueMap != null && caseLevelAndStatusValueMap.containsKey("caseStatus")) {
|
||||
list = caseLevelAndStatusValueMap.get("caseStatus");
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(list)) {
|
||||
setComment(sheet, drawingPatriarch, statusIndex, Translator.get("options") + JSONArray.toJSONString(list));
|
||||
}
|
||||
list.clear();
|
||||
if (MapUtils.isNotEmpty(caseLevelAndStatusValueMap) && caseLevelAndStatusValueMap.containsKey("caseStatus")) {
|
||||
list = caseLevelAndStatusValueMap.get("caseStatus");
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(list)) {
|
||||
setComment(statusIndex, Translator.get("options").concat(JSONArray.toJSONString(list)));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void setComment(Sheet sheet, Drawing<?> drawingPatriarch, Integer index, String text) {
|
||||
private void setComment(Integer index, String text) {
|
||||
if (index == null) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
:show-operator="true"
|
||||
:public-total="publicTotal"
|
||||
:case-condition="condition"
|
||||
@handleExportCheck="handleExportCheck"
|
||||
@refreshTable="refresh"
|
||||
@setTreeNodes="setTreeNodes"
|
||||
@exportTestCase="exportTestCase"
|
||||
|
@ -585,6 +586,11 @@ export default {
|
|||
this.activeName = "default";
|
||||
}
|
||||
},
|
||||
handleExportCheck() {
|
||||
if (this.$refs.testCaseList.checkSelected()) {
|
||||
this.$refs.nodeTree.openExport();
|
||||
}
|
||||
},
|
||||
exportTestCase(type, param) {
|
||||
if (this.activeDom !== 'left') {
|
||||
this.$warning(this.$t('test_track.case.export.export_tip'));
|
||||
|
|
|
@ -1041,11 +1041,6 @@ export default {
|
|||
fileNameSuffix = ".xlsx";
|
||||
}
|
||||
|
||||
if (config.data.ids === undefined || config.data.ids.length < 1) {
|
||||
this.$warning(this.$t("test_track.case.check_select"));
|
||||
return;
|
||||
}
|
||||
|
||||
this.page.result = this.$request(config).then(response => {
|
||||
const filename = "Metersphere_case_" + this.projectName + fileNameSuffix;
|
||||
const blob = new Blob([response.data]);
|
||||
|
@ -1198,6 +1193,14 @@ export default {
|
|||
|
||||
}
|
||||
},
|
||||
checkSelected() {
|
||||
let selectIds = this.$refs.table.selectIds;
|
||||
if (!selectIds || selectIds.length < 1) {
|
||||
this.$warning(this.$t("test_track.case.check_select"));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
},
|
||||
getMaintainerOptions() {
|
||||
this.$get('/user/project/member/list', response => {
|
||||
this.valueArr.maintainer = response.data;
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
<template>
|
||||
<el-dialog class="testcase-import" :title="$t('test_track.case.import.case_export')" :visible.sync="dialogVisible"
|
||||
<el-dialog class="testcase-import"
|
||||
v-loading="loading"
|
||||
:title="$t('test_track.case.import.case_export')"
|
||||
:visible.sync="dialogVisible"
|
||||
@close="close">
|
||||
|
||||
<span class="format-title">
|
||||
|
@ -39,28 +42,32 @@ export default {
|
|||
return {
|
||||
exportType: "excel",
|
||||
dialogVisible: false,
|
||||
projectId: ""
|
||||
projectId: "",
|
||||
loading: false
|
||||
}
|
||||
},
|
||||
activated() {
|
||||
},
|
||||
methods: {
|
||||
handleError(err, file, fileList) {
|
||||
this.isLoading = false;
|
||||
this.loading = false;
|
||||
this.$error(err.message);
|
||||
},
|
||||
open() {
|
||||
listenGoBack(this.close);
|
||||
this.projectId = getCurrentProjectID();
|
||||
this.dialogVisible = true;
|
||||
this.loading = false;
|
||||
},
|
||||
close() {
|
||||
removeGoBackListener(this.close);
|
||||
this.dialogVisible = false;
|
||||
this.loading = false;
|
||||
},
|
||||
exportTestCase() {
|
||||
let param = this.$refs.testCaseExportFieldSelect.getExportParam();
|
||||
this.$emit('exportTestCase', this.exportType, param);
|
||||
this.loading = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,10 @@
|
|||
:key="item.id">
|
||||
<el-col :span="6"
|
||||
v-if="Math.floor(index / colCountEachRow) === rowIndex - 1">
|
||||
<el-checkbox v-model="item.enable" @change="change">
|
||||
<el-checkbox
|
||||
v-model="item.enable"
|
||||
:disabled="item.disabled"
|
||||
@change="change">
|
||||
{{ item.name }}
|
||||
</el-checkbox>
|
||||
</el-col>
|
||||
|
|
|
@ -73,7 +73,8 @@ export default {
|
|||
id: 'name',
|
||||
key: 'B',
|
||||
name: this.$t("test_track.case.name"),
|
||||
enable: true
|
||||
enable: true,
|
||||
disabled: true
|
||||
},
|
||||
{
|
||||
id: 'nodeId',
|
||||
|
|
|
@ -66,7 +66,9 @@ export default {
|
|||
selectAllChange(value) {
|
||||
this.selectAll = value;
|
||||
this.fields.forEach(i => {
|
||||
i.enable = value;
|
||||
if (!i.disabled) {
|
||||
i.enable = value;
|
||||
}
|
||||
});
|
||||
this.persistenceValues();
|
||||
},
|
||||
|
@ -91,7 +93,7 @@ export default {
|
|||
}
|
||||
}
|
||||
|
||||
this.selectAllChange(isSelectAll);
|
||||
this.selectAll = isSelectAll;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -242,6 +242,9 @@ export default {
|
|||
this.$warning(this.$t('commons.check_project_tip'));
|
||||
return;
|
||||
}
|
||||
this.$emit('handleExportCheck')
|
||||
},
|
||||
openExport() {
|
||||
this.$refs.testCaseExport.open();
|
||||
},
|
||||
exportTestCase(type, param){
|
||||
|
|
Loading…
Reference in New Issue