refactor(测试跟踪): 优化用例所属模块显示

--bug=1025638 --user=陈建星 重命名用例模块报错 https://www.tapd.cn/55049933/s/1364766
This commit is contained in:
chenjianxing 2023-04-20 14:44:52 +08:00 committed by jianxing
parent 793851e632
commit b152bd9411
11 changed files with 88 additions and 185 deletions

View File

@ -12,18 +12,21 @@ public class TestCase implements Serializable {
private String testId; private String testId;
@Deprecated
private String nodePath; private String nodePath;
private String projectId; private String projectId;
private String name; private String name;
@Deprecated
private String type; private String type;
private String maintainer; private String maintainer;
private String priority; private String priority;
@Deprecated
private String method; private String method;
private Long createTime; private Long createTime;
@ -69,4 +72,4 @@ public class TestCase implements Serializable {
private String lastExecuteResult; private String lastExecuteResult;
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
} }

View File

@ -150,9 +150,6 @@ public interface ExtTestCaseMapper {
int addLatestVersion(@Param("refId") String refId); int addLatestVersion(@Param("refId") String refId);
void updateVersionModule(@Param("refId") String refId, @Param("versionId") String versionId, @Param("moduleId") String moduleId, @Param("modulePath") String modulePath);
List<TestCase> getMaintainerMap(@Param("request") QueryTestCaseRequest request); List<TestCase> getMaintainerMap(@Param("request") QueryTestCaseRequest request);
List<TestCase> getMaintainerMapForPlanRepeat(@Param("request") QueryTestCaseRequest request); List<TestCase> getMaintainerMapForPlanRepeat(@Param("request") QueryTestCaseRequest request);

View File

@ -1327,14 +1327,6 @@
WHERE ref_id = #{refId,jdbcType=VARCHAR} WHERE ref_id = #{refId,jdbcType=VARCHAR}
</update> </update>
<update id="updateVersionModule">
UPDATE test_case
SET node_id = #{moduleId},
node_path = #{modulePath}
WHERE ref_id = #{refId}
AND version_id != #{versionId}
</update>
<update id="bathUpdateByCondition"> <update id="bathUpdateByCondition">
update test_case update test_case
<set> <set>

View File

@ -299,7 +299,6 @@ public class TestCaseNoModelDataListener extends AnalysisEventListener<Map<Integ
testCase.setProjectId(request.getProjectId()); testCase.setProjectId(request.getProjectId());
String steps = getSteps(data); String steps = getSteps(data);
testCase.setSteps(steps); testCase.setSteps(steps);
testCase.setType(TestCaseConstants.Type.Functional.getValue());
boolean dbExist = testCaseService.exist(testCase); boolean dbExist = testCaseService.exist(testCase);
boolean excelExist = false; boolean excelExist = false;
@ -614,7 +613,6 @@ public class TestCaseNoModelDataListener extends AnalysisEventListener<Map<Integ
//将标签设置为前端可解析的格式 //将标签设置为前端可解析的格式
String modifiedTags = modifyTagPattern(data); String modifiedTags = modifyTagPattern(data);
testCase.setTags(modifiedTags); testCase.setTags(modifiedTags);
testCase.setType(TestCaseConstants.Type.Functional.getValue());
data.setStatus(data.getStatus()); data.setStatus(data.getStatus());
// todo 这里要获取模板的自定义字段再新建关联关系 // todo 这里要获取模板的自定义字段再新建关联关系

View File

@ -169,38 +169,9 @@ public class TestCaseNodeService extends NodeTreeService<TestCaseNodeDTO> {
public int editNode(DragNodeRequest request) { public int editNode(DragNodeRequest request) {
request.setUpdateTime(System.currentTimeMillis()); request.setUpdateTime(System.currentTimeMillis());
if (!CollectionUtils.isEmpty(request.getNodeIds())) {
List<TestCaseDTO> testCases = extTestCaseMapper.getForNodeEdit(request.getNodeIds());
testCases.forEach(testCase -> {
StringBuilder path = new StringBuilder(testCase.getNodePath());
List<String> pathLists = Arrays.asList(path.toString().split("/"));
pathLists.set(request.getLevel(), request.getName());
path.delete(0, path.length());
for (int i = 1; i < pathLists.size(); i++) {
path = path.append("/").append(pathLists.get(i));
}
testCase.setNodePath(path.toString());
});
batchUpdateTestCase(testCases);
}
return testCaseNodeMapper.updateByPrimaryKeySelective(request); return testCaseNodeMapper.updateByPrimaryKeySelective(request);
} }
/**
* 修改用例的 nodePath
*
* @param editNodeIds
* @param projectId
*/
public void editCasePathForMinder(List<String> editNodeIds, String projectId) {
if (!CollectionUtils.isEmpty(editNodeIds)) {
List<TestCaseNodeDTO> nodeTrees = getNodeTrees(extTestCaseNodeMapper.getNodeTreeByProjectId(projectId));
List<TestCaseDTO> testCases = extTestCaseMapper.getForNodeEdit(editNodeIds);
nodeTrees.forEach(nodeTree -> buildUpdateTestCase(nodeTree, testCases, null, "/", "0", 1));
batchUpdateTestCase(testCases);
}
}
public int deleteNode(List<String> nodeIds) { public int deleteNode(List<String> nodeIds) {
if (CollectionUtils.isEmpty(nodeIds)) { if (CollectionUtils.isEmpty(nodeIds)) {
return 1; return 1;
@ -399,6 +370,24 @@ public class TestCaseNodeService extends NodeTreeService<TestCaseNodeDTO> {
return this.createNodes(nodePaths, projectId); return this.createNodes(nodePaths, projectId);
} }
public Map<String, String> getNodePathMap(String projectId) {
List<TestCaseNodeDTO> nodeTrees = getNodeTrees(getNodeTreeByProjectId(projectId));
Map<String, String> pathMap = new HashMap<>();
buildPathMap(nodeTrees, pathMap, "");
return pathMap;
}
private void buildPathMap(List<TestCaseNodeDTO> nodeTrees, Map<String, String> pathMap, String rootPath) {
for (TestCaseNodeDTO nodeTree : nodeTrees) {
String currentPath = rootPath + "/" + nodeTree.getName();
pathMap.put(nodeTree.getId(), currentPath);
List<TestCaseNodeDTO> children = nodeTree.getChildren();
if (!CollectionUtils.isEmpty(children)) {
buildPathMap(children, pathMap, currentPath);
}
}
}
public Map<String, String> createNodes(List<String> nodePaths, String projectId) { public Map<String, String> createNodes(List<String> nodePaths, String projectId) {
List<TestCaseNodeDTO> nodeTrees = getNodeTreeByProjectId(projectId); List<TestCaseNodeDTO> nodeTrees = getNodeTreeByProjectId(projectId);
Map<String, String> pathMap = new HashMap<>(); Map<String, String> pathMap = new HashMap<>();
@ -457,8 +446,6 @@ public class TestCaseNodeService extends NodeTreeService<TestCaseNodeDTO> {
List<String> nodeIds = request.getNodeIds(); List<String> nodeIds = request.getNodeIds();
List<TestCaseDTO> testCases = QueryTestCaseByNodeIds(nodeIds);
TestCaseNodeDTO nodeTree = request.getNodeTree(); TestCaseNodeDTO nodeTree = request.getNodeTree();
if (nodeTree == null) { if (nodeTree == null) {
@ -467,15 +454,13 @@ public class TestCaseNodeService extends NodeTreeService<TestCaseNodeDTO> {
List<TestCaseNode> updateNodes = new ArrayList<>(); List<TestCaseNode> updateNodes = new ArrayList<>();
buildUpdateTestCase(nodeTree, testCases, updateNodes, "/", "0", 1); buildUpdateTestCase(nodeTree, updateNodes, "0", 1);
updateNodes = updateNodes.stream() updateNodes = updateNodes.stream()
.filter(item -> nodeIds.contains(item.getId())) .filter(item -> nodeIds.contains(item.getId()))
.collect(Collectors.toList()); .collect(Collectors.toList());
batchUpdateTestCaseNode(updateNodes); batchUpdateTestCaseNode(updateNodes);
batchUpdateTestCase(testCases);
} }
private void batchUpdateTestCaseNode(List<TestCaseNode> updateNodes) { private void batchUpdateTestCaseNode(List<TestCaseNode> updateNodes) {
@ -490,31 +475,8 @@ public class TestCaseNodeService extends NodeTreeService<TestCaseNodeDTO> {
} }
} }
private void batchUpdateTestCase(List<TestCaseDTO> testCases) { private void buildUpdateTestCase(TestCaseNodeDTO rootNode,
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH); List<TestCaseNode> updateNodes, String pId, int level) {
TestCaseMapper testCaseMapper = sqlSession.getMapper(TestCaseMapper.class);
testCases.forEach((value) -> {
testCaseMapper.updateByPrimaryKeySelective(value);
});
sqlSession.flushStatements();
if (sqlSession != null && sqlSessionFactory != null) {
SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory);
}
}
private List<TestCaseDTO> QueryTestCaseByNodeIds(List<String> nodeIds) {
QueryTestCaseRequest testCaseRequest = new QueryTestCaseRequest();
testCaseRequest.setNodeIds(nodeIds);
if (testCaseRequest.getFilters() != null && !testCaseRequest.getFilters().containsKey("status")) {
testCaseRequest.getFilters().put("status", new ArrayList<>(0));
}
return extTestCaseMapper.list(testCaseRequest);
}
private void buildUpdateTestCase(TestCaseNodeDTO rootNode, List<TestCaseDTO> testCases,
List<TestCaseNode> updateNodes, String rootPath, String pId, int level) {
rootPath = rootPath + rootNode.getName();
if (level > 8) { if (level > 8) {
MSException.throwException(Translator.get("node_deep_limit")); MSException.throwException(Translator.get("node_deep_limit"));
@ -528,16 +490,10 @@ public class TestCaseNodeService extends NodeTreeService<TestCaseNodeDTO> {
updateNodes.add(testCaseNode); updateNodes.add(testCaseNode);
} }
for (TestCaseDTO item : testCases) {
if (StringUtils.equals(item.getNodeId(), rootNode.getId())) {
item.setNodePath(rootPath);
}
}
List<TestCaseNodeDTO> children = rootNode.getChildren(); List<TestCaseNodeDTO> children = rootNode.getChildren();
if (children != null && children.size() > 0) { if (children != null && children.size() > 0) {
for (int i = 0; i < children.size(); i++) { for (int i = 0; i < children.size(); i++) {
buildUpdateTestCase(children.get(i), testCases, updateNodes, rootPath + '/', rootNode.getId(), level + 1); buildUpdateTestCase(children.get(i), updateNodes, rootNode.getId(), level + 1);
} }
} }
} }
@ -715,8 +671,6 @@ public class TestCaseNodeService extends NodeTreeService<TestCaseNodeDTO> {
addNode(testCaseNode); addNode(testCaseNode);
} }
} }
editCasePathForMinder(editNodeIds, request.getProjectId());
} }
} }

View File

@ -113,10 +113,6 @@ public class TestCaseService {
@Resource @Resource
TestCaseNodeService testCaseNodeService; TestCaseNodeService testCaseNodeService;
// @Resource
// ApiTestCaseMapper apiTestCaseMapper;
@Resource @Resource
TestCaseIssueService testCaseIssueService; TestCaseIssueService testCaseIssueService;
@Resource @Resource
@ -133,10 +129,6 @@ public class TestCaseService {
AttachmentModuleRelationMapper attachmentModuleRelationMapper; AttachmentModuleRelationMapper attachmentModuleRelationMapper;
@Resource @Resource
ExtAttachmentModuleRelationMapper extAttachmentModuleRelationMapper; ExtAttachmentModuleRelationMapper extAttachmentModuleRelationMapper;
// @Resource
// private LoadTestMapper loadTestMapper;
// @Resource
// private ApiScenarioMapper apiScenarioMapper;
@Resource @Resource
private TestCaseIssuesMapper testCaseIssuesMapper; private TestCaseIssuesMapper testCaseIssuesMapper;
@Resource @Resource
@ -149,15 +141,6 @@ public class TestCaseService {
private RelevanceLoadCaseService relevanceLoadCaseService; private RelevanceLoadCaseService relevanceLoadCaseService;
@Resource @Resource
private RelevanceUiCaseService relevanceUiCaseService; private RelevanceUiCaseService relevanceUiCaseService;
// @Resource
// @Lazy
// private ApiTestCaseService apiTestCaseService;
// @Resource
// @Lazy
// private ApiAutomationService apiAutomationService;
// @Resource
// @Lazy
// private PerformanceTestService performanceTestService;
@Resource @Resource
private TestCaseFollowMapper testCaseFollowMapper; private TestCaseFollowMapper testCaseFollowMapper;
@Resource @Resource
@ -218,7 +201,6 @@ public class TestCaseService {
List<TestCaseNode> nodes = testCaseNodeMapper.selectByExample(example); List<TestCaseNode> nodes = testCaseNodeMapper.selectByExample(example);
if (CollectionUtils.isNotEmpty(nodes)) { if (CollectionUtils.isNotEmpty(nodes)) {
testCase.setNodeId(nodes.get(0).getId()); testCase.setNodeId(nodes.get(0).getId());
testCase.setNodePath("/" + nodes.get(0).getName());
} }
} }
} }
@ -523,14 +505,6 @@ public class TestCaseService {
if (StringUtils.equalsIgnoreCase(testCase.getVersionId(), defaultVersion)) { if (StringUtils.equalsIgnoreCase(testCase.getVersionId(), defaultVersion)) {
checkAndSetLatestVersion(testCase.getRefId()); checkAndSetLatestVersion(testCase.getRefId());
} }
if (StringUtils.isNotBlank(testCase.getNodePath())) {
//同步修改所有版本的模块路径
updateOtherVersionModule(testCase);
}
}
private void updateOtherVersionModule(EditTestCaseRequest testCase) {
extTestCaseMapper.updateVersionModule(testCase.getRefId(), testCase.getVersionId(), testCase.getNodeId(), testCase.getNodePath());
} }
/** /**
@ -604,28 +578,12 @@ public class TestCaseService {
// 全部字段值相同才判断为用例存在 // 全部字段值相同才判断为用例存在
if (testCase != null) { if (testCase != null) {
/*
例如对于/模块5用户的输入可能为模块5或者/模块5/或者模块5/
不这样处理的话下面进行判断时就会用用户输入的错误格式进行判断而模块名为/模块5
模块5/模块5/模块5/它们应该被认为是同一个模块
数据库存储的node_path都是/模块5这种格式的
*/
String nodePath = testCase.getNodePath();
if (!nodePath.startsWith("/")) {
nodePath = "/" + nodePath;
}
if (nodePath.endsWith("/")) {
nodePath = nodePath.substring(0, nodePath.length() - 1);
}
TestCaseExample example = new TestCaseExample(); TestCaseExample example = new TestCaseExample();
TestCaseExample.Criteria criteria = example.createCriteria(); TestCaseExample.Criteria criteria = example.createCriteria();
criteria.andNameEqualTo(testCase.getName()) criteria.andNameEqualTo(testCase.getName())
.andProjectIdEqualTo(testCase.getProjectId()) .andProjectIdEqualTo(testCase.getProjectId())
.andNodePathEqualTo(nodePath) .andNodePathEqualTo(testCase.getNodeId())
.andTypeEqualTo(testCase.getType()) .andStatusNotEqualTo(CommonConstants.TrashStatus);
.andStatusNotEqualTo("Trash");
if (StringUtils.isNotBlank(testCase.getPriority())) { if (StringUtils.isNotBlank(testCase.getPriority())) {
criteria.andPriorityEqualTo(testCase.getPriority()); criteria.andPriorityEqualTo(testCase.getPriority());
} }
@ -1403,7 +1361,6 @@ public class TestCaseService {
testCase.setCustomNum(dbCase.getCustomNum()); testCase.setCustomNum(dbCase.getCustomNum());
testCase.setNum(dbCase.getNum()); testCase.setNum(dbCase.getNum());
testCase.setLatest(false); testCase.setLatest(false);
testCase.setType(dbCase.getType());
if (StringUtils.isBlank(testCase.getStatus())) { if (StringUtils.isBlank(testCase.getStatus())) {
testCase.setStatus(TestCaseReviewStatus.Prepare.name()); testCase.setStatus(TestCaseReviewStatus.Prepare.name());
} }
@ -1575,6 +1532,9 @@ public class TestCaseService {
TestCaseBatchRequest batchRequest = setTestCaseExportParamIds(initParam); TestCaseBatchRequest batchRequest = setTestCaseExportParamIds(initParam);
// 1000条截取一次, 生成EXCEL // 1000条截取一次, 生成EXCEL
AtomicInteger i = new AtomicInteger(0); AtomicInteger i = new AtomicInteger(0);
Map<String, String> nodePathMap = testCaseNodeService.getNodePathMap(request.getProjectId());
SubListUtil.dealForSubList(batchRequest.getIds(), EXPORT_CASE_MAX_COUNT, (subIds) -> { SubListUtil.dealForSubList(batchRequest.getIds(), EXPORT_CASE_MAX_COUNT, (subIds) -> {
i.getAndIncrement(); i.getAndIncrement();
batchRequest.setIds(subIds); batchRequest.setIds(subIds);
@ -1583,9 +1543,12 @@ public class TestCaseService {
FunctionCaseMergeWriteHandler writeHandler = new FunctionCaseMergeWriteHandler(rowMergeInfo, headList); FunctionCaseMergeWriteHandler writeHandler = new FunctionCaseMergeWriteHandler(rowMergeInfo, headList);
Map<String, List<String>> caseLevelAndStatusValueMap = trackTestCaseTemplateService.getCaseLevelAndStatusMapByProjectId(request.getProjectId()); Map<String, List<String>> caseLevelAndStatusValueMap = trackTestCaseTemplateService.getCaseLevelAndStatusMapByProjectId(request.getProjectId());
FunctionCaseTemplateWriteHandler handler = new FunctionCaseTemplateWriteHandler(true, headList, caseLevelAndStatusValueMap); FunctionCaseTemplateWriteHandler handler = new FunctionCaseTemplateWriteHandler(true, headList, caseLevelAndStatusValueMap);
List<TestCaseDTO> exportData = getExportData(batchRequest); List<TestCaseDTO> exportData = getExportData(batchRequest);
exportData.forEach(item -> item.setNodePath(nodePathMap.get(item.getNodeId())));
List<TestCaseExcelData> excelData = parseCaseData2ExcelData(exportData, rowMergeInfo, isUseCustomId, request.getOtherHeaders()); List<TestCaseExcelData> excelData = parseCaseData2ExcelData(exportData, rowMergeInfo, isUseCustomId, request.getOtherHeaders());
List<List<Object>> data = parseExcelData2List(headList, excelData); List<List<Object>> data = parseExcelData2List(headList, excelData);
File createFile = new File(tmpZipPath + File.separatorChar + "caseExport_" + i.get() + ".xlsx"); File createFile = new File(tmpZipPath + File.separatorChar + "caseExport_" + i.get() + ".xlsx");
if (!createFile.exists()) { if (!createFile.exists()) {
try { try {
@ -2056,22 +2019,6 @@ public class TestCaseService {
BeanUtils.copyBean(batchEdit, request); BeanUtils.copyBean(batchEdit, request);
batchEdit.setUpdateTime(System.currentTimeMillis()); batchEdit.setUpdateTime(System.currentTimeMillis());
bathUpdateByCondition(request, batchEdit); bathUpdateByCondition(request, batchEdit);
//批量修改选中数据其他版本的模块路径
if (request != null && (request.getIds() != null || !request.getIds().isEmpty())) {
request.getIds().forEach(testCaseId -> {
TestCaseWithBLOBs testCaseWithBLOBs = testCaseMapper.selectByPrimaryKey(testCaseId);
if (testCaseWithBLOBs == null) {
return;
}
if (StringUtils.isNotEmpty(request.getNodeId()) && StringUtils.isNotEmpty(request.getNodePath())) {
testCaseWithBLOBs.setNodeId(request.getNodeId());
testCaseWithBLOBs.setNodePath(request.getNodePath());
EditTestCaseRequest editTestCaseRequest = new EditTestCaseRequest();
BeanUtils.copyBean(editTestCaseRequest, testCaseWithBLOBs);
updateOtherVersionModule(editTestCaseRequest);
}
});
}
} }
} }
@ -2184,7 +2131,7 @@ public class TestCaseService {
batchCopy.setMaintainer(SessionUtils.getUserId()); batchCopy.setMaintainer(SessionUtils.getUserId());
batchCopy.setReviewStatus(TestCaseReviewStatus.Prepare.name()); batchCopy.setReviewStatus(TestCaseReviewStatus.Prepare.name());
batchCopy.setStatus(TestCaseReviewStatus.Prepare.name()); batchCopy.setStatus(TestCaseReviewStatus.Prepare.name());
batchCopy.setNodePath(request.getNodePath()); batchCopy.setNodePath(StringUtils.EMPTY);
batchCopy.setNodeId(request.getNodeId()); batchCopy.setNodeId(request.getNodeId());
batchCopy.setCasePublic(false); batchCopy.setCasePublic(false);
batchCopy.setRefId(id); batchCopy.setRefId(id);
@ -2753,24 +2700,6 @@ public class TestCaseService {
return null; return null;
} }
// public List<ApiTestCaseDTO> getTestCaseApiCaseRelateList(ApiTestCaseRequest request) {
// List<ApiTestCaseDTO> apiTestCaseDTOS = testCaseTestMapper.relevanceApiList(request);
// ServiceUtils.buildVersionInfo(apiTestCaseDTOS);
// return apiTestCaseDTOS;
// }
//
// public List<ApiScenarioDTO> getTestCaseScenarioCaseRelateList(ApiScenarioRequest request) {
// List<ApiScenarioDTO> apiScenarioDTOS = testCaseTestMapper.relevanceScenarioList(request);
// ServiceUtils.buildVersionInfo(apiScenarioDTOS);
// return apiScenarioDTOS;
// }
//
// public List<LoadTestDTO> getTestCaseLoadCaseRelateList(LoadCaseRequest request) {
// List<LoadTestDTO> loadTestDTOS = testCaseTestMapper.relevanceLoadList(request);
// ServiceUtils.buildVersionInfo(loadTestDTOS);
// return loadTestDTOS;
// }
public void relateTest(String type, String caseId, List<String> apiIds) { public void relateTest(String type, String caseId, List<String> apiIds) {
apiIds.forEach(testId -> { apiIds.forEach(testId -> {
TestCaseTest testCaseTest = new TestCaseTest(); TestCaseTest testCaseTest = new TestCaseTest();
@ -3147,7 +3076,7 @@ public class TestCaseService {
testCase.setName(testCase.getName().substring(0, 250) + testCase.getName().substring(testCase.getName().length() - 5)); testCase.setName(testCase.getName().substring(0, 250) + testCase.getName().substring(testCase.getName().length() - 5));
} }
testCase.setNodeId(request.getNodeId()); testCase.setNodeId(request.getNodeId());
testCase.setNodePath(request.getNodePath()); testCase.setNodePath(StringUtils.EMPTY);
testCase.setOrder(nextOrder += ServiceUtils.ORDER_STEP); testCase.setOrder(nextOrder += ServiceUtils.ORDER_STEP);
testCase.setCustomNum(String.valueOf(nextNum)); testCase.setCustomNum(String.valueOf(nextNum));
testCase.setNum(nextNum++); testCase.setNum(nextNum++);

View File

@ -1,6 +1,5 @@
package io.metersphere.xmind; package io.metersphere.xmind;
import com.google.common.collect.ImmutableMap;
import io.metersphere.base.domain.TestCaseWithBLOBs; import io.metersphere.base.domain.TestCaseWithBLOBs;
import io.metersphere.commons.constants.TestCaseConstants; import io.metersphere.commons.constants.TestCaseConstants;
import io.metersphere.commons.utils.BeanUtils; import io.metersphere.commons.utils.BeanUtils;
@ -106,7 +105,6 @@ public class XmindCaseParser {
return this.nodePaths; return this.nodePaths;
} }
private final Map<String, String> caseTypeMap = ImmutableMap.of("功能测试", "functional", "性能测试", "performance", "接口测试", "api");
private final List<String> priorityList = Arrays.asList("P0", "P1", "P2", "P3"); private final List<String> priorityList = Arrays.asList("P0", "P1", "P2", "P3");
/** /**
@ -188,20 +186,11 @@ public class XmindCaseParser {
} }
} }
if (StringUtils.equals(data.getType(), TestCaseConstants.Type.Functional.getValue()) && StringUtils.equals(data.getMethod(), TestCaseConstants.Method.Auto.getValue())) {
validatePass = false;
process.add(Translator.get("functional_method_tip"), nodePath + data.getName());
}
// 用例等级和用例性质处理 // 用例等级和用例性质处理
if (!priorityList.contains(data.getPriority())) { if (!priorityList.contains(data.getPriority())) {
validatePass = false; validatePass = false;
process.add(Translator.get("test_case_priority") + Translator.get("incorrect_format"), nodePath + data.getName()); process.add(Translator.get("test_case_priority") + Translator.get("incorrect_format"), nodePath + data.getName());
} }
if (data.getType() == null) {
validatePass = false;
process.add(Translator.get("test_case_type") + Translator.get("incorrect_format"), nodePath + data.getName());
}
// 重复用例校验 // 重复用例校验
TestCaseExcelData dataItem = new TestCaseExcelData(); TestCaseExcelData dataItem = new TestCaseExcelData();
@ -274,8 +263,8 @@ public class XmindCaseParser {
/** /**
* 递归处理案例数据 * 递归处理案例数据
*/ */
private void recursion(Attached parent, int level, List<Attached> attacheds) { private void recursion(Attached parent, int level, List<Attached> attachedList) {
for (Attached item : attacheds) { for (Attached item : attachedList) {
if (isAvailable(item.getTitle(), TC_REGEX)) { if (isAvailable(item.getTitle(), TC_REGEX)) {
item.setParent(parent); item.setParent(parent);
// 格式化一个用例 // 格式化一个用例
@ -354,8 +343,6 @@ public class XmindCaseParser {
testCase.setProjectId(request.getProjectId()); testCase.setProjectId(request.getProjectId());
testCase.setMaintainer(request.getUserId()); testCase.setMaintainer(request.getUserId());
testCase.setPriority(priorityList.get(0)); testCase.setPriority(priorityList.get(0));
testCase.setMethod("manual");
testCase.setType("functional");
String tc = title.replace("", ":"); String tc = title.replace("", ":");
String[] tcArrs = tc.split(":"); String[] tcArrs = tc.split(":");
@ -375,8 +362,6 @@ public class XmindCaseParser {
continue; continue;
} else if (item.toUpperCase().startsWith("P")) { } else if (item.toUpperCase().startsWith("P")) {
testCase.setPriority(item.toUpperCase()); testCase.setPriority(item.toUpperCase());
} else {
testCase.setType(caseTypeMap.get(item));
} }
} }
} }

View File

@ -187,6 +187,9 @@
:fields-width="fieldsWidth" :fields-width="fieldsWidth"
:label="$t('test_track.case.module')" :label="$t('test_track.case.module')"
min-width="150px"> min-width="150px">
<template v-slot:default="scope">
<span>{{ nodePathMap.get(scope.row.nodeId) }}</span>
</template>
</ms-table-column> </ms-table-column>
<ms-update-time-column :field="item" <ms-update-time-column :field="item"
@ -526,7 +529,16 @@ export default {
selectNode: 'testCaseSelectNode', selectNode: 'testCaseSelectNode',
moduleOptions: 'testCaseModuleOptions', moduleOptions: 'testCaseModuleOptions',
customNum: 'currentProjectIsCustomNum' customNum: 'currentProjectIsCustomNum'
}) }),
nodePathMap() {
let map = new Map();
if (this.moduleOptions) {
this.moduleOptions.forEach((item) => {
map.set(item.id, item.path);
});
}
return map;
}
}, },
created: function () { created: function () {
this.checkCurrentProject(); this.checkCurrentProject();
@ -824,13 +836,9 @@ export default {
parseCustomFilesForList(this.page.data); parseCustomFilesForList(this.page.data);
parseTag(this.page.data); parseTag(this.page.data);
this.page.data.forEach(item => { this.page.data.forEach(item => {
let nodePath = item.nodePath;
if (item.customFields) { if (item.customFields) {
item.customFields = JSON.parse(item.customFields); item.customFields = JSON.parse(item.customFields);
} }
if (nodePath.startsWith("/未规划用例", "0")) {
item.nodePath = nodePath.replaceAll("/未规划用例", "/" + this.$t('api_test.unplanned_case'));
}
}); });
this.updateTestCaseNodeCount(); this.updateTestCaseNodeCount();
}); });

View File

@ -9,6 +9,7 @@ import jakarta.annotation.Resource;
@RestController @RestController
@RequestMapping(path = { @RequestMapping(path = {
"issues", "issues",
"case/node",
"/test/case", "/test/case",
"/test/plan" "/test/plan"
}) })

View File

@ -0,0 +1,5 @@
import {post,get} from "metersphere-frontend/src/plugins/request";
export function getTestCaseNodes(projectId) {
return get('/case/node/list/' + projectId);
}

View File

@ -76,6 +76,9 @@
:label="$t('test_track.case.module')" :label="$t('test_track.case.module')"
min-width="150px" min-width="150px"
> >
<template v-slot:default="scope">
<span>{{ nodePathMap.get(scope.row.nodeId) }}</span>
</template>
</ms-table-column> </ms-table-column>
<ms-table-column <ms-table-column
@ -275,6 +278,8 @@ import TestPlanCaseStatusTableItem from "@/business/othermodule/track/TestPlanCa
import TestCasePreview from "@/business/othermodule/track/TestCasePreview"; import TestCasePreview from "@/business/othermodule/track/TestCasePreview";
import { parseTag } from "metersphere-frontend/src/utils"; import { parseTag } from "metersphere-frontend/src/utils";
import { getCustomFieldValueForTrack } from "@/business/component/js/table-head-util"; import { getCustomFieldValueForTrack } from "@/business/component/js/table-head-util";
import {getTestCaseNodes} from "@/api/test-case-node";
import {buildTree, buildNodePath} from "metersphere-frontend/src/model/NodeTree";
export default { export default {
name: "TableList", name: "TableList",
@ -334,6 +339,7 @@ export default {
rowCaseResult: {}, rowCaseResult: {},
store: {}, store: {},
userFilter: [], userFilter: [],
nodePathMap: new Map()
}; };
}, },
props: { props: {
@ -392,6 +398,7 @@ export default {
getProjectMemberUserFilter((data) => { getProjectMemberUserFilter((data) => {
this.userFilter = data; this.userFilter = data;
}); });
this.getNodePathMap();
if (this.isFocus) { if (this.isFocus) {
if (this.condition.filters) { if (this.condition.filters) {
delete this.condition.filters["user_id"]; delete this.condition.filters["user_id"];
@ -556,6 +563,30 @@ export default {
}); });
}); });
}, },
getNodePathMap() {
if (!this.projectId) {
return;
}
getTestCaseNodes(this.projectId)
.then((r) => {
let treeNodes = r.data;
treeNodes.forEach(node => {
node.name = node.name === '未规划用例' ? this.$t('api_test.unplanned_case') : node.name
buildTree(node, {path: ''});
});
let moduleOptions = [];
treeNodes.forEach(node => {
buildNodePath(node, {path: ''}, moduleOptions);
});
let map = new Map();
if (moduleOptions) {
moduleOptions.forEach((item) => {
map.set(item.id, item.path);
});
}
this.nodePathMap = map;
});
},
setTestCaseDefaultValue(template) { setTestCaseDefaultValue(template) {
let testCaseDefaultValue = {}; let testCaseDefaultValue = {};
template.customFields.forEach((item) => { template.customFields.forEach((item) => {