From f8b35a9e72facbeb517c616168b600fd69bb9ec9 Mon Sep 17 00:00:00 2001 From: Ambitiousliga <73278880+Ambitiousliga@users.noreply.github.com> Date: Tue, 30 Mar 2021 11:02:59 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix(=E6=B5=8B=E8=AF=95=E8=B7=9F=E8=B8=AA):E?= =?UTF-8?q?xcel=E5=AF=BC=E5=85=A5=E7=94=A8=E4=BE=8B=E6=97=B6=E6=A0=87?= =?UTF-8?q?=E7=AD=BE=E6=9C=89=E5=86=85=E5=AE=B9=E4=BC=9A=E6=8A=A5=E9=94=99?= =?UTF-8?q?=20(#1747)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix(测试跟踪):Excel导入用例时标签有内容报错 * fix(测试跟踪):excel导入只有新增用例且和错误用例时,关闭窗口会自动刷新。 Co-authored-by: 黎龙鑫 --- .../excel/listener/TestCaseDataListener.java | 30 ++++++++++++++++++- .../track/service/TestCaseService.java | 3 +- .../resources/i18n/messages_en_US.properties | 3 ++ .../resources/i18n/messages_zh_CN.properties | 3 ++ .../resources/i18n/messages_zh_TW.properties | 3 ++ 5 files changed, 40 insertions(+), 2 deletions(-) diff --git a/backend/src/main/java/io/metersphere/excel/listener/TestCaseDataListener.java b/backend/src/main/java/io/metersphere/excel/listener/TestCaseDataListener.java index ad588dc8cd..ba941aad35 100644 --- a/backend/src/main/java/io/metersphere/excel/listener/TestCaseDataListener.java +++ b/backend/src/main/java/io/metersphere/excel/listener/TestCaseDataListener.java @@ -19,6 +19,7 @@ import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Collectors; +import java.util.stream.Stream; public class TestCaseDataListener extends EasyExcelListener { @@ -151,6 +152,7 @@ public class TestCaseDataListener extends EasyExcelListener { .map(item -> this.convert2TestCase(item)) .collect(Collectors.toList()); testCaseService.saveImportData(result, projectId); + this.isUpdated = true; } if (!(updateList.size() == 0)) { @@ -180,9 +182,11 @@ public class TestCaseDataListener extends EasyExcelListener { if (nodePath.endsWith("/")) { nodePath = nodePath.substring(0, nodePath.length() - 1); } - testCase.setNodePath(nodePath); + //将标签设置为前端可解析的格式 + String modifiedTags = modifyTagPattern(data); + testCase.setTags(modifiedTags); String steps = getSteps(data); testCase.setSteps(steps); @@ -201,6 +205,7 @@ public class TestCaseDataListener extends EasyExcelListener { testCase.setProjectId(this.projectId); testCase.setUpdateTime(System.currentTimeMillis()); + //调整nodePath格式 String nodePath = data.getNodePath(); if (!nodePath.startsWith("/")) { nodePath = "/" + nodePath; @@ -213,9 +218,32 @@ public class TestCaseDataListener extends EasyExcelListener { String steps = getSteps(data); testCase.setSteps(steps); + //将标签设置为前端可解析的格式 + String modifiedTags = modifyTagPattern(data); + testCase.setTags(modifiedTags); + return testCase; } + /** + * 调整tags格式,便于前端进行解析。 + * 例如对于:标签1,标签2。将调整为:["标签1","标签2"]。 + */ + public String modifyTagPattern(TestCaseExcelData data){ + String tags = data.getTags(); + if (tags != null) { + Stream stringStream = Arrays.stream(tags.split("[,;,;]")); //当标签值以中英文的逗号和分号分隔时才能正确解析 + List tagList = stringStream.map(tag -> tag = "\"" + tag + "\"") + .collect(Collectors.toList()); + String modifiedTags = StringUtils.join(tagList, ","); + modifiedTags = "[" + modifiedTags + "]"; + return modifiedTags; + }else { + return null; + } + } + + public String getSteps(TestCaseExcelData data) { JSONArray jsonArray = new JSONArray(); diff --git a/backend/src/main/java/io/metersphere/track/service/TestCaseService.java b/backend/src/main/java/io/metersphere/track/service/TestCaseService.java index 1ed153236f..44bda486db 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestCaseService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestCaseService.java @@ -547,9 +547,10 @@ public class TestCaseService { list.add(new TestCaseExcelData()); TestCaseExcelData explain = new TestCaseExcelData(); - explain.setName(Translator.get("do_not_modify_header_order")); + explain.setName(Translator.get("do_not_modify_header_order") + "," + Translator.get("num_needed_modify_testcase") + "," + Translator.get("num_needless_create_testcase")); explain.setNodePath(Translator.get("module_created_automatically")); explain.setType(Translator.get("options") + "(functional、performance、api)"); + explain.setTags(Translator.get("tag_tip_pattern")); // explain.setMethod(Translator.get("options") + "(manual、auto)"); explain.setPriority(Translator.get("options") + "(P0、P1、P2、P3)"); explain.setMaintainer(Translator.get("please_input_workspace_member")); diff --git a/backend/src/main/resources/i18n/messages_en_US.properties b/backend/src/main/resources/i18n/messages_en_US.properties index 7983790370..5b6cd25fad 100644 --- a/backend/src/main/resources/i18n/messages_en_US.properties +++ b/backend/src/main/resources/i18n/messages_en_US.properties @@ -125,6 +125,9 @@ test_manager=Test manager tester=Tester read_only_user=Read-only user module=Module +num_needed_modify_testcase=ID is needed when modifying testcase +num_needless_create_testcase=ID is needless when creating testcase +tag_tip_pattern=Labels should be separated by semicolons or commas preconditions_optional=Preconditions optional step_tip_separate=Each step is separated by a new line step_tip_order=The serial number can be marked before the step diff --git a/backend/src/main/resources/i18n/messages_zh_CN.properties b/backend/src/main/resources/i18n/messages_zh_CN.properties index 9d335a49e3..c09423629c 100644 --- a/backend/src/main/resources/i18n/messages_zh_CN.properties +++ b/backend/src/main/resources/i18n/messages_zh_CN.properties @@ -125,6 +125,9 @@ test_manager=测试经理 tester=测试成员 read_only_user=只读用户 module=模块 +num_needed_modify_testcase=修改用例时ID必填 +num_needless_create_testcase=创建用例时无需ID +tag_tip_pattern=标签之间以分号或者逗号隔开 preconditions_optional=前置条件选填 step_tip_separate=每个步骤以换行分隔 step_tip_order=步骤前可标序号 diff --git a/backend/src/main/resources/i18n/messages_zh_TW.properties b/backend/src/main/resources/i18n/messages_zh_TW.properties index 6cab6f1a81..9ff6f1ac5c 100644 --- a/backend/src/main/resources/i18n/messages_zh_TW.properties +++ b/backend/src/main/resources/i18n/messages_zh_TW.properties @@ -125,6 +125,9 @@ test_manager=測試經理 tester=測試成員 read_only_user=只讀用戶 module=模塊 +num_needed_modify_testcase=修改用例時ID必填 +num_needless_create_testcase=創建用例時無需ID +tag_tip_pattern=標籤之間以分號或者逗號隔開 preconditions_optional=前置條件選填 step_tip_separate=每個步驟以換行分隔 step_tip_order=步驟前可標序號 From 2b32f119a01df120d9debf89001faf5fba9094c2 Mon Sep 17 00:00:00 2001 From: "Captain.B" Date: Tue, 30 Mar 2021 12:58:52 +0800 Subject: [PATCH 2/2] chore: sync --- frontend/src/business/components/xpack | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/business/components/xpack b/frontend/src/business/components/xpack index 07951ba17a..2115bd28a9 160000 --- a/frontend/src/business/components/xpack +++ b/frontend/src/business/components/xpack @@ -1 +1 @@ -Subproject commit 07951ba17aef6f29e50cfd68e40de3266f9a60cd +Subproject commit 2115bd28a90854d2b6276a90878934715498c584