fix(测试跟踪): 功能用例列表,模块用例数显示有误

--bug=1025675 --user=陈建星 【测试跟踪】功能用例-新建用例保存后前置tab页的用例数量统计闪现数据不对 https://www.tapd.cn/55049933/s/1365416
This commit is contained in:
chenjianxing 2023-04-23 10:15:45 +08:00 committed by jianxing
parent 45dd154204
commit bf6f067c1e
6 changed files with 68 additions and 29 deletions

View File

@ -292,10 +292,7 @@ export default {
return hasPermissions(permission[0]);
},
init() {
let num = 0;
this.treeNodes.forEach(t => {
num += t.caseNum;
});
let num = this.getTotalCount();
this.extendTreeNodes = [];
this.extendTreeNodes.unshift({
"id": "root",
@ -308,6 +305,31 @@ export default {
this.expandedNode.push("root");
}
},
getTotalCount() {
let num = 0;
this.treeNodes.forEach(t => {
num += t.caseNum;
});
return num;
},
updateNodeCount(countMap) {
// countMap
this.doUpdateNodeCount(this.treeNodes, countMap);
// root
this.$refs.tree.root.childNodes[0].data.caseNum = this.getTotalCount();
},
doUpdateNodeCount(treeNodes, countMap) {
treeNodes.forEach(item => {
let children = item.children;
if (children && children.length > 0) {
this.doUpdateNodeCount(children, countMap);
item.caseNum = countMap[item.id] + children.map(i => i.caseNum)
.reduce((pre, curr) => pre + curr, 0);
} else {
item.caseNum = countMap[item.id];
}
});
},
handleNodeSelect(node) {
let nodeIds = [];
let pNodes = [];

View File

@ -44,7 +44,15 @@ public class TestCaseNodeController {
projectId = request.getProjectId();
}
baseCheckPermissionService.checkProjectOwner(projectId);
return testCaseNodeService.getNodeTreeByProjectId(projectId, Optional.ofNullable(request).orElse(new QueryTestCaseRequest()));
return testCaseNodeService.getNodeTreeByProjectId(projectId,
Optional.ofNullable(request).orElse(new QueryTestCaseRequest()));
}
@PostMapping("/count/{projectId}")
public Map<String, Integer> getNodeCountMapByProjectId(@PathVariable String projectId, @RequestBody(required = false) QueryTestCaseRequest request) {
baseCheckPermissionService.checkProjectOwner(projectId);
return testCaseNodeService.getNodeCountMapByProjectId(projectId,
Optional.ofNullable(request).orElse(new QueryTestCaseRequest()));
}
@PostMapping("/minder/extraNode/count")

View File

@ -18,7 +18,6 @@ import io.metersphere.commons.utils.CommonBeanFactory;
import io.metersphere.commons.utils.JSON;
import io.metersphere.commons.utils.SessionUtils;
import io.metersphere.dto.NodeNumDTO;
import io.metersphere.dto.TestCaseDTO;
import io.metersphere.dto.TestCaseNodeDTO;
import io.metersphere.dto.TestPlanCaseDTO;
import io.metersphere.exception.ExcelException;
@ -225,11 +224,27 @@ public class TestCaseNodeService extends NodeTreeService<TestCaseNodeDTO> {
request.setProjectId(projectId);
request.setUserId(SessionUtils.getUserId());
request.setNodeIds(null);
request.setOrders(null);
ServiceUtils.buildCombineTagsToSupportMultiple(request);
ServiceUtils.setBaseQueryRequestCustomMultipleFields(request);
List<TestCaseNodeDTO> countMNodes = extTestCaseMapper.getCountNodes(request);
List<TestCaseNodeDTO> countNodes = extTestCaseMapper.getCountNodes(request);
List<TestCaseNodeDTO> testCaseNodes = extTestCaseNodeMapper.getNodeTreeByProjectId(projectId);
return getNodeTrees(testCaseNodes, getCountMap(countMNodes));
return getNodeTrees(testCaseNodes, getCountMap(countNodes));
}
public Map<String, Integer> getNodeCountMapByProjectId(String projectId, QueryTestCaseRequest request) {
request.setProjectId(projectId);
request.setUserId(SessionUtils.getUserId());
request.setNodeIds(null);
request.setOrders(null);
ServiceUtils.buildCombineTagsToSupportMultiple(request);
ServiceUtils.setBaseQueryRequestCustomMultipleFields(request);
List<TestCaseNodeDTO> countNodes = extTestCaseMapper.getCountNodes(request);
Map<String, Integer> countMap = getCountMap(countNodes);
countMap.remove(null); // 脏数据没有模块 ID 的会有 null 的清空
return countMap;
}
/**

View File

@ -193,6 +193,10 @@ export function getTestCaseNodesByCaseFilter(projectId, param) {
return post('/case/node/list/' + projectId, param);
}
export function getTestCaseNodesCountMap(projectId, param) {
return post('/case/node/count/' + projectId, param);
}
export function getTestPlanCaseNodesByCaseFilter(planId, param) {
return post('/case/node/list/plan/' + planId, param);
}

View File

@ -840,29 +840,11 @@ export default {
item.customFields = JSON.parse(item.customFields);
}
});
this.updateTestCaseNodeCount();
});
this.$emit("getTrashList");
this.$emit("getPublicList")
}
},
// tab
updateTestCaseNodeCount() {
if (this.selectNode && this.treeNodes && this.selectNode.data
&& this.selectNode.data.caseNum !== this.page.total) {
let updateCount = this.page.total - this.selectNode.data.caseNum;
let node = this.selectNode;
this.selectNode.data.caseNum = this.page.total;
while (node) {
node = node.parent;
if (node && node.data) {
node.data.caseNum += updateCount;
}
}
}
},
search() {
this.refreshBySearch = true;
//

View File

@ -50,7 +50,7 @@ import MsSearchBar from "metersphere-frontend/src/components/new-ui/MsSearchBar"
import {buildTree, buildNodePath} from "metersphere-frontend/src/model/NodeTree";
import {getCurrentProjectID} from "metersphere-frontend/src/utils/token";
import ModuleTrashButton from "metersphere-frontend/src/components/ModuleTrashButton";
import {getTestCaseNodesByCaseFilter} from "@/api/testCase";
import {getTestCaseNodesByCaseFilter, getTestCaseNodesCountMap} from "@/api/testCase";
import IsChangeConfirm from "metersphere-frontend/src/components/IsChangeConfirm";
import ModulePublicButton from "metersphere-frontend/src/components/module/ModulePublicButton";
import {useStore} from "@/store";
@ -296,8 +296,16 @@ export default {
this.currentNode = node;
this.$emit("nodeSelectEvent", node, node.data.id === 'root' ? [] : nodeIds, pNodes);
// TAB
// this.nohupReloadTree(node.data.id);
//
this.updateNodeCount();
},
updateNodeCount() {
getTestCaseNodesCountMap(this.projectId, this.caseCondition)
.then((r) => {
if (this.$refs.nodeTree) {
this.$refs.nodeTree.updateNodeCount(r.data);
}
});
},
nohupReloadTree(selectNodeId) {
if (this.projectId) {