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:
chenjianxing 2022-08-18 12:00:20 +08:00 committed by f2c-ci-robot[bot]
parent 4850dcab82
commit 09acd152f5
14 changed files with 127 additions and 70 deletions

View File

@ -1,7 +1,17 @@
package io.metersphere.commons.constants; package io.metersphere.commons.constants;
public enum TestCaseCommentType { public enum TestCaseCommentType {
CASE, CASE("test_case_comment"),
REVIEW, REVIEW("test_case_plan_comment"),
PLAN PLAN("test_case_review_comment");
private String i18nKey;
TestCaseCommentType(String i18nKey) {
this.i18nKey = i18nKey;
}
public String getI18nKey() {
return i18nKey;
}
} }

View File

@ -1,5 +1,20 @@
package io.metersphere.commons.constants; package io.metersphere.commons.constants;
public enum TestPlanTestCaseStatus { 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;
}
} }

View File

@ -1,5 +1,17 @@
package io.metersphere.commons.constants; package io.metersphere.commons.constants;
public enum TestReviewCaseStatus { 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;
}
} }

View File

@ -21,19 +21,17 @@ public class TestCaseExportCommendConverter implements TestCaseExportConverter {
private HashMap<String, String> reviewCaseStatusMap = new HashMap<>(); private HashMap<String, String> reviewCaseStatusMap = new HashMap<>();
public TestCaseExportCommendConverter() { public TestCaseExportCommendConverter() {
commendTypeMap.put(TestCaseCommentType.CASE.name(), "test_case_comment"); for (TestCaseCommentType value : TestCaseCommentType.values()) {
commendTypeMap.put(TestCaseCommentType.PLAN.name(), "test_case_plan_comment"); commendTypeMap.put(value.name(), value.getI18nKey());
commendTypeMap.put(TestCaseCommentType.REVIEW.name(), "test_case_review_comment"); }
planCaseStatusMap.put(TestPlanTestCaseStatus.Pass.name(), "execute_pass"); for (TestPlanTestCaseStatus value : TestPlanTestCaseStatus.values()) {
planCaseStatusMap.put(TestPlanTestCaseStatus.Underway.name(), "test_case_status_prepare"); planCaseStatusMap.put(value.name(), value.getI18nKey());
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");
reviewCaseStatusMap.put(TestReviewCaseStatus.Prepare.name(), "test_case_status_prepare"); for (TestReviewCaseStatus value : TestReviewCaseStatus.values()) {
reviewCaseStatusMap.put(TestReviewCaseStatus.Pass.name(), "execute_pass"); reviewCaseStatusMap.put(value.name(), value.getI18nKey());
reviewCaseStatusMap.put(TestReviewCaseStatus.UnPass.name(), "execute_not_pass"); }
} }
@Override @Override

View File

@ -11,11 +11,9 @@ public class TestCaseExportExecuteResultConverter implements TestCaseExportConve
private Map<String, String> planCaseStatusMap = new HashMap<>(); private Map<String, String> planCaseStatusMap = new HashMap<>();
public TestCaseExportExecuteResultConverter() { public TestCaseExportExecuteResultConverter() {
planCaseStatusMap.put(TestPlanTestCaseStatus.Pass.name(), "execute_pass"); for (TestPlanTestCaseStatus value : TestPlanTestCaseStatus.values()) {
planCaseStatusMap.put(TestPlanTestCaseStatus.Underway.name(), "test_case_status_prepare"); planCaseStatusMap.put(value.name(), value.getI18nKey());
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");
} }
@Override @Override

View File

@ -11,9 +11,9 @@ public class TestCaseExportReviewResultConverter implements TestCaseExportConver
private Map<String, String> reviewCaseStatusMap = new HashMap<>(); private Map<String, String> reviewCaseStatusMap = new HashMap<>();
public TestCaseExportReviewResultConverter() { public TestCaseExportReviewResultConverter() {
reviewCaseStatusMap.put(TestReviewCaseStatus.Prepare.name(), "test_case_status_prepare"); for (TestReviewCaseStatus value : TestReviewCaseStatus.values()) {
reviewCaseStatusMap.put(TestReviewCaseStatus.Pass.name(), "execute_pass"); reviewCaseStatusMap.put(value.name(), value.getI18nKey());
reviewCaseStatusMap.put(TestReviewCaseStatus.UnPass.name(), "execute_not_pass"); }
} }
@Override @Override

View File

@ -7,6 +7,8 @@ import com.alibaba.fastjson.JSONArray;
import io.metersphere.excel.constants.TestCaseImportFiled; import io.metersphere.excel.constants.TestCaseImportFiled;
import io.metersphere.i18n.Translator; import io.metersphere.i18n.Translator;
import org.apache.commons.collections.CollectionUtils; 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.Comment;
import org.apache.poi.ss.usermodel.Drawing; import org.apache.poi.ss.usermodel.Drawing;
import org.apache.poi.ss.usermodel.Sheet; 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 org.apache.poi.xssf.usermodel.XSSFRichTextString;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -26,7 +27,6 @@ import java.util.Map;
public class FunctionCaseTemplateWriteHandler implements RowWriteHandler { public class FunctionCaseTemplateWriteHandler implements RowWriteHandler {
private boolean isNeedId; private boolean isNeedId;
Map<String, Integer> rowDisposeIndexMap;
Map<String, List<String>> caseLevelAndStatusValueMap; Map<String, List<String>> caseLevelAndStatusValueMap;
private Integer idIndex; private Integer idIndex;
@ -37,15 +37,16 @@ public class FunctionCaseTemplateWriteHandler implements RowWriteHandler {
private Integer statusIndex; private Integer statusIndex;
private Integer stepModelIndex; private Integer stepModelIndex;
private Sheet sheet;
private Drawing<?> drawingPatriarch;
public FunctionCaseTemplateWriteHandler(boolean isNeedId, List<List<String>> headList, Map<String, List<String>> caseLevelAndStatusValueMap) { public FunctionCaseTemplateWriteHandler(boolean isNeedId, List<List<String>> headList, Map<String, List<String>> caseLevelAndStatusValueMap) {
this.isNeedId = isNeedId; this.isNeedId = isNeedId;
rowDisposeIndexMap = this.buildFiledMap(headList); this.initIndex(headList);
this.caseLevelAndStatusValueMap = caseLevelAndStatusValueMap; this.caseLevelAndStatusValueMap = caseLevelAndStatusValueMap;
} }
private Map<String, Integer> buildFiledMap(List<List<String>> headList) { private void initIndex(List<List<String>> headList) {
Map<String, Integer> returnMap = new HashMap<>();
int index = 0; int index = 0;
for (List<String> list : headList) { for (List<String> list : headList) {
for (String head : list) { for (String head : list) {
@ -67,48 +68,46 @@ public class FunctionCaseTemplateWriteHandler implements RowWriteHandler {
index++; index++;
} }
} }
return returnMap;
} }
@Override @Override
public void afterRowDispose(RowWriteHandlerContext context) { public void afterRowDispose(RowWriteHandlerContext context) {
if (BooleanUtils.isTrue(context.getHead())) { if (BooleanUtils.isTrue(context.getHead())) {
Sheet sheet = context.getWriteSheetHolder().getSheet(); sheet = context.getWriteSheetHolder().getSheet();
Drawing<?> drawingPatriarch = sheet.createDrawingPatriarch(); drawingPatriarch = sheet.createDrawingPatriarch();
if (rowDisposeIndexMap != null) { if (isNeedId) {
if (isNeedId) { setComment(idIndex, Translator.get("do_not_modify_header_order").concat("").concat(Translator.get("id_required")));
setComment(sheet, drawingPatriarch, idIndex, Translator.get("do_not_modify_header_order") + "" + Translator.get("id_required")); }
}
setComment(sheet, drawingPatriarch, moduleIndex, Translator.get("module_created_automatically")); setComment(moduleIndex, Translator.get("module_created_automatically"));
setComment(sheet, drawingPatriarch, maintainerIndex, Translator.get("please_input_project_member")); setComment(maintainerIndex, Translator.get("please_input_project_member"));
setComment(sheet, drawingPatriarch, tagIndex, Translator.get("tag_tip_pattern")); setComment(tagIndex, Translator.get("tag_tip_pattern"));
setComment(sheet, drawingPatriarch, stepModelIndex, Translator.get("step_model_tip")); setComment(stepModelIndex, Translator.get("step_model_tip"));
List<String> list = new ArrayList<>(); List<String> list = new ArrayList<>();
if (caseLevelAndStatusValueMap != null && caseLevelAndStatusValueMap.containsKey("caseLevel")) { if (MapUtils.isNotEmpty(caseLevelAndStatusValueMap) && caseLevelAndStatusValueMap.containsKey("caseLevel")) {
list = caseLevelAndStatusValueMap.get("caseLevel"); list = caseLevelAndStatusValueMap.get("caseLevel");
} }
if (CollectionUtils.isEmpty(list)) { if (CollectionUtils.isEmpty(list)) {
setComment(sheet, drawingPatriarch, priorityIndex, Translator.get("options") + "P0、P1、P2、P3"); setComment(priorityIndex, Translator.get("options").concat("P0、P1、P2、P3"));
} else { } else {
setComment(sheet, drawingPatriarch, priorityIndex, Translator.get("options") + JSONArray.toJSONString(list)); setComment(priorityIndex, Translator.get("options").concat(JSONArray.toJSONString(list)));
} }
list.clear(); list.clear();
if (caseLevelAndStatusValueMap != null && caseLevelAndStatusValueMap.containsKey("caseStatus")) { if (MapUtils.isNotEmpty(caseLevelAndStatusValueMap) && caseLevelAndStatusValueMap.containsKey("caseStatus")) {
list = caseLevelAndStatusValueMap.get("caseStatus"); list = caseLevelAndStatusValueMap.get("caseStatus");
} }
if (CollectionUtils.isNotEmpty(list)) { if (CollectionUtils.isNotEmpty(list)) {
setComment(sheet, drawingPatriarch, statusIndex, Translator.get("options") + JSONArray.toJSONString(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) { if (index == null) {
return; return;
} }

View File

@ -8,6 +8,7 @@
:show-operator="true" :show-operator="true"
:public-total="publicTotal" :public-total="publicTotal"
:case-condition="condition" :case-condition="condition"
@handleExportCheck="handleExportCheck"
@refreshTable="refresh" @refreshTable="refresh"
@setTreeNodes="setTreeNodes" @setTreeNodes="setTreeNodes"
@exportTestCase="exportTestCase" @exportTestCase="exportTestCase"
@ -585,6 +586,11 @@ export default {
this.activeName = "default"; this.activeName = "default";
} }
}, },
handleExportCheck() {
if (this.$refs.testCaseList.checkSelected()) {
this.$refs.nodeTree.openExport();
}
},
exportTestCase(type, param) { exportTestCase(type, param) {
if (this.activeDom !== 'left') { if (this.activeDom !== 'left') {
this.$warning(this.$t('test_track.case.export.export_tip')); this.$warning(this.$t('test_track.case.export.export_tip'));

View File

@ -1041,11 +1041,6 @@ export default {
fileNameSuffix = ".xlsx"; 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 => { this.page.result = this.$request(config).then(response => {
const filename = "Metersphere_case_" + this.projectName + fileNameSuffix; const filename = "Metersphere_case_" + this.projectName + fileNameSuffix;
const blob = new Blob([response.data]); 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() { getMaintainerOptions() {
this.$get('/user/project/member/list', response => { this.$get('/user/project/member/list', response => {
this.valueArr.maintainer = response.data; this.valueArr.maintainer = response.data;

View File

@ -1,5 +1,8 @@
<template> <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"> @close="close">
<span class="format-title"> <span class="format-title">
@ -39,28 +42,32 @@ export default {
return { return {
exportType: "excel", exportType: "excel",
dialogVisible: false, dialogVisible: false,
projectId: "" projectId: "",
loading: false
} }
}, },
activated() { activated() {
}, },
methods: { methods: {
handleError(err, file, fileList) { handleError(err, file, fileList) {
this.isLoading = false; this.loading = false;
this.$error(err.message); this.$error(err.message);
}, },
open() { open() {
listenGoBack(this.close); listenGoBack(this.close);
this.projectId = getCurrentProjectID(); this.projectId = getCurrentProjectID();
this.dialogVisible = true; this.dialogVisible = true;
this.loading = false;
}, },
close() { close() {
removeGoBackListener(this.close); removeGoBackListener(this.close);
this.dialogVisible = false; this.dialogVisible = false;
this.loading = false;
}, },
exportTestCase() { exportTestCase() {
let param = this.$refs.testCaseExportFieldSelect.getExportParam(); let param = this.$refs.testCaseExportFieldSelect.getExportParam();
this.$emit('exportTestCase', this.exportType, param); this.$emit('exportTestCase', this.exportType, param);
this.loading = true;
} }
} }
} }

View File

@ -5,7 +5,10 @@
:key="item.id"> :key="item.id">
<el-col :span="6" <el-col :span="6"
v-if="Math.floor(index / colCountEachRow) === rowIndex - 1"> 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 }} {{ item.name }}
</el-checkbox> </el-checkbox>
</el-col> </el-col>

View File

@ -73,7 +73,8 @@ export default {
id: 'name', id: 'name',
key: 'B', key: 'B',
name: this.$t("test_track.case.name"), name: this.$t("test_track.case.name"),
enable: true enable: true,
disabled: true
}, },
{ {
id: 'nodeId', id: 'nodeId',

View File

@ -66,7 +66,9 @@ export default {
selectAllChange(value) { selectAllChange(value) {
this.selectAll = value; this.selectAll = value;
this.fields.forEach(i => { this.fields.forEach(i => {
i.enable = value; if (!i.disabled) {
i.enable = value;
}
}); });
this.persistenceValues(); this.persistenceValues();
}, },
@ -91,7 +93,7 @@ export default {
} }
} }
this.selectAllChange(isSelectAll); this.selectAll = isSelectAll;
} }
} }
} }

View File

@ -242,6 +242,9 @@ export default {
this.$warning(this.$t('commons.check_project_tip')); this.$warning(this.$t('commons.check_project_tip'));
return; return;
} }
this.$emit('handleExportCheck')
},
openExport() {
this.$refs.testCaseExport.open(); this.$refs.testCaseExport.open();
}, },
exportTestCase(type, param){ exportTestCase(type, param){