refactor(测试跟踪): 功能用例导入换行符优化

--story=1012551 --user=宋昌昌 #25705【功能用例】导入用例换行符优化 https://www.tapd.cn/55049933/s/1401943
This commit is contained in:
song-cc-rock 2023-08-09 16:30:36 +08:00 committed by fit2-zhao
parent 268a91d338
commit 3c64217203
6 changed files with 56 additions and 24 deletions

View File

@ -20,10 +20,10 @@ public enum TestCaseImportFiled {
MODULE("module","所属模块", "所屬模塊", "Module", TestCaseExcelData::getNodePath),
TAGS("tags","标签", "標簽", "Tag", TestCaseImportFiled::parseTags),
PREREQUISITE("prerequisite","前置条件", "前置條件", "Prerequisite", TestCaseExcelData::getPrerequisite),
REMARK("remark","备注", "備註", "Remark", TestCaseExcelData::getRemark),
STEP_DESC("stepDesc","步骤描述", "步驟描述", "Step description", TestCaseExcelData::getStepDesc),
STEP_RESULT("stepResult","预期结果", "預期結果", "Step result", TestCaseExcelData::getStepResult),
STEP_MODEL("stepModel","编辑模式", "編輯模式", "Edit Model", TestCaseExcelData::getStepModel),
REMARK("remark","备注", "備註", "Remark", TestCaseExcelData::getRemark),
STATUS("status","用例状态", "用例狀態", "Case status", TestCaseExcelData::getStatus),
MAINTAINER("maintainer","责任人", "責任人", "Maintainer", TestCaseExcelData::getMaintainer),
PRIORITY("priority","用例等级", "用例等級", "Priority", TestCaseExcelData::getPriority);

View File

@ -34,6 +34,8 @@ public class FunctionCaseTemplateWriteHandler implements RowWriteHandler {
private Integer priorityIndex;
private Integer tagIndex;
private Integer statusIndex;
private Integer stepDescIndex;
private Integer stepResultIndex;
private Integer stepModelIndex;
private Sheet sheet;
@ -61,6 +63,10 @@ public class FunctionCaseTemplateWriteHandler implements RowWriteHandler {
tagIndex = index;
} else if (TestCaseImportFiled.STATUS.containsHead(head)) {
statusIndex = index;
} else if (TestCaseImportFiled.STEP_DESC.containsHead(head)) {
stepDescIndex = index;
} else if (TestCaseImportFiled.STEP_RESULT.containsHead(head)) {
stepResultIndex = index;
} else if (TestCaseImportFiled.STEP_MODEL.containsHead(head)) {
stepModelIndex = index;
}
@ -83,6 +89,8 @@ public class FunctionCaseTemplateWriteHandler implements RowWriteHandler {
setComment(moduleIndex, Translator.get("module_created_automatically"));
setComment(maintainerIndex, Translator.get("please_input_project_member"));
setComment(tagIndex, Translator.get("tag_tip_pattern"));
setComment(stepDescIndex, Translator.get("step_desc_tip"));
setComment(stepResultIndex, Translator.get("step_result_tip"));
setComment(stepModelIndex, Translator.get("step_model_tip"));
List<String> list = new ArrayList<>();

View File

@ -685,41 +685,61 @@ public class TestCaseNoModelDataListener extends AnalysisEventListener<Map<Integ
}
}
/**
* 解析合并步骤描述, 预期结果单元格数据
* @param data Excel数据
* @return 步骤JSON-String
*/
public String getSteps(TestCaseExcelData data) {
List jsonArray = new ArrayList<>();
List<Map<String, Object>> steps = new ArrayList<>();
// 如果是合并单元格则组合多条单元格的数据
if (CollectionUtils.isNotEmpty(data.getMergeStepDesc())
|| CollectionUtils.isNotEmpty(data.getMergeStepResult())) {
if (CollectionUtils.isNotEmpty(data.getMergeStepDesc()) || CollectionUtils.isNotEmpty(data.getMergeStepResult())) {
// 如果是合并单元格则组合多条单元格的数据
for (int i = 0; i < data.getMergeStepDesc().size(); i++) {
Map<String, Object> step = new LinkedHashMap<>();
step.put("num", i + 1);
step.put("desc", Optional.ofNullable(data.getMergeStepDesc().get(i)).orElse(StringUtils.EMPTY));
step.put("result", Optional.ofNullable(data.getMergeStepResult().get(i)).orElse(StringUtils.EMPTY));
jsonArray.add(step);
List<Map<String, Object>> rowSteps = getSingleRowSteps(data.getMergeStepDesc().get(i), data.getMergeStepResult().get(i), steps.size());
steps.addAll(rowSteps);
}
return JSON.toJSONString(jsonArray);
} else {
// 如果不是合并单元格则直接解析单元格数据
steps.addAll(getSingleRowSteps(data.getStepDesc(), data.getStepResult(), steps.size()));
}
return JSON.toJSONString(steps);
}
/**
* 解析单行步骤描述, 预期结果数据
* @param cellDesc 步骤描述
* @param cellResult 预期结果
* @param startStepIndex 步骤开始序号
* @return 步骤JSON-String
*/
private List<Map<String, Object>> getSingleRowSteps(String cellDesc, String cellResult, Integer startStepIndex) {
List<Map<String, Object>> steps = new ArrayList<>();
List<String> stepDescList = new ArrayList<>();
List<String> stepResList = new ArrayList<>();
Set<Integer> rowNums = new HashSet<>();
if (data.getStepDesc() != null) {
String[] stepDesc = data.getStepDesc().split("\r|\n|\r\n");
if (StringUtils.isNotEmpty(cellDesc)) {
// 根据[1], [2]...分割步骤描述, 开头空字符去掉, 末尾保留
String[] stepDesc = cellDesc.split("\\[\\d+]", -1);
if (StringUtils.isEmpty(stepDesc[0])) {
stepDesc = Arrays.copyOfRange(stepDesc, 1, stepDesc.length);
}
int rowIndex = 1;
for (String row : stepDesc) {
RowInfo rowInfo = this.parseIndexInRow(row, rowIndex);
stepDescList.add(rowInfo.rowInfo);
rowNums.add(rowIndex++);
}
} else {
stepDescList.add(StringUtils.EMPTY);
}
if (data.getStepResult() != null) {
String[] stepRes = data.getStepResult().split("\r|\n|\r\n");
if (StringUtils.isNotEmpty(cellResult)) {
// 根据[1], [2]...分割步骤描述, 开头空字符去掉, 末尾保留
String[] stepRes = cellResult.split("\\[\\d+]", -1);
if (StringUtils.isEmpty(stepRes[0])) {
stepRes = Arrays.copyOfRange(stepRes, 1, stepRes.length);
}
int lastStepIndex = 1;
for (String row : stepRes) {
RowInfo rowInfo = this.parseIndexInRow(row, lastStepIndex);
@ -731,13 +751,11 @@ public class TestCaseNoModelDataListener extends AnalysisEventListener<Map<Integ
stepResList.add(StringUtils.EMPTY);
}
int index = stepDescList.size() > stepResList.size() ? stepDescList.size() : stepResList.size();
int index = Math.max(stepDescList.size(), stepResList.size());
for (int i = 0; i < index; i++) {
// 保持插入顺序判断用例是否有相同的steps
Map<String, Object> step = new LinkedHashMap<>();
step.put("num", i + 1);
step.put("num", startStepIndex + i + 1);
if (i < stepDescList.size()) {
step.put("desc", stepDescList.get(i));
} else {
@ -750,9 +768,9 @@ public class TestCaseNoModelDataListener extends AnalysisEventListener<Map<Integ
step.put("result", StringUtils.EMPTY);
}
jsonArray.add(step);
steps.add(step);
}
return JSON.toJSONString(jsonArray);
return steps;
}
private RowInfo parseIndexInRow(String row, int rowIndex) {

View File

@ -158,6 +158,8 @@ custom_num_is_exist=Use case custom ID already exists
custom_num_is_not_exist=Use case custom ID not exists
id_required=ID required
id_repeat_in_table=ID is repeat in table
step_desc_tip=(not required) When the step mode is STEP, the step description will be defined according to the flags [1] [2] [3]... To determine whether the cell should be split into multiple steps or a single step
step_result_tip=(not required) When the step mode is STEP, the expected result is based on the flags [1] [2] [3]... To determine whether the cell should be split into multiple steps or a single step
step_model_tip=Step description fill in STEP, text description please fill in TEXT (not required)
case_status_not_exist=The use case status must be Prepare, Underway way and Completed
custom_field_option_not_exist=%s must be %s

View File

@ -130,6 +130,8 @@ custom_num_is_exist=用例自定义ID已存在
custom_num_is_not_exist=用例自定义ID不存在
id_required=ID必填
id_repeat_in_table=表格内ID重复
step_desc_tip=(非必填) 编辑模式为STEP时,步骤描述会根据标识[1] [2] [3]...来判断是否将单元格拆分为多个步骤,没有则为一个步骤
step_result_tip=(非必填) 编辑模式为STEP时,预期结果会根据标识[1] [2] [3]...来判断是否将单元格拆分为多个步骤,没有则为一个步骤
step_model_tip=步骤描述填写 STEP,文本描述请填写 TEXT (非必填)
case_status_not_exist=用例状态必须为未开始(Prepare)、进行中(Underway)、已完成(Completed)
custom_field_option_not_exist=%s必须为%s

View File

@ -130,6 +130,8 @@ custom_num_is_exist=用例自定義ID已存在
custom_num_is_not_exist=用例自定義ID不存在
id_required=ID必填
id_repeat_in_table=表格內ID重復
step_desc_tip=(非必填) 編輯模式爲STEP時,步驟描述會根據標識[1] [2] [3]...來判斷是否將單元格拆分爲多個步驟,沒有則爲一個步驟
step_result_tip=(非必填) 編輯模式爲STEP時,預期結果會根據標識[1] [2] [3]...來判斷是否將單元格拆分爲多個步驟,沒有則爲一個步驟
step_model_tip=步驟描述填寫 STEP,文本描述請填寫 TEXT (非必填)
case_status_not_exist=用例狀態必須為未開始Prepare、進行中Underway、已完成Completed
custom_field_option_not_exist=%s必須為%s