refactor: 脑图性能优化

This commit is contained in:
chenjianxing 2021-06-04 14:54:52 +08:00 committed by jianxing
parent b19beaf740
commit 9ea5c34c85
19 changed files with 458 additions and 319 deletions

View File

@ -452,6 +452,9 @@
<include refid="io.metersphere.base.mapper.TestCaseMapper.Blob_Column_List"/>
from test_case
<include refid="queryWhereCondition"/>
<if test="request.nodeId != null">
and test_case.node_id = #{request.nodeId}
</if>
<include refid="io.metersphere.base.mapper.ext.ExtBaseMapper.orders"/>
</select>
<select id="getTestCaseByNotInIssue" resultType="io.metersphere.track.dto.TestCaseDTO">

View File

@ -48,7 +48,7 @@ public interface ExtTestPlanTestCaseMapper {
List<String> getExecResultByPlanId(String planId);
List<TestPlanCaseDTO> listForMinder(@Param("planId") String planId);
List<TestPlanCaseDTO> listForMinder(@Param("request") QueryTestPlanCaseRequest request);
List<TestCaseTestDTO> listTestCaseTest(@Param("caseId") String caseId);

View File

@ -532,7 +532,8 @@
from test_plan_test_case pc
inner join test_case t on pc.case_id = t.id
<where>
pc.plan_id = #{planId}
pc.plan_id = #{request.planId}
and t.node_id = #{request.nodeId}
</where>
order by pc.update_time desc;
</select>

View File

@ -34,4 +34,6 @@ public interface ExtTestReviewCaseMapper {
List<String> selectIds(@Param("request") QueryCaseReviewRequest request);
List<String> selectTestCaseIds(@Param("request") QueryCaseReviewRequest request);
List<TestReviewCaseDTO> listForMinder(@Param("request") QueryCaseReviewRequest request);
}

View File

@ -109,6 +109,10 @@
inner join test_case on test_case_review_test_case.case_id = test_case.id
left join test_case_node on test_case_node.id=test_case.node_id
inner join project on project.id = test_case.project_id
<include refid="queryWhereCondition"/>
<include refid="io.metersphere.base.mapper.ext.ExtBaseMapper.orders"/>
</select>
<sql id="queryWhereCondition">
<where>
<if test="request.combine != null">
<include refid="combine">
@ -118,9 +122,9 @@
</if>
<if test="request.name != null">
and (test_case.name like CONCAT('%', #{request.name},'%')
or test_case.num like CONCAT('%', #{request.name},'%')
or test_case.custom_num like CONCAT('%', #{request.name},'%')
)
or test_case.num like CONCAT('%', #{request.name},'%')
or test_case.custom_num like CONCAT('%', #{request.name},'%')
)
</if>
<if test="request.id != null">
and test_case.id = #{request.id}
@ -143,59 +147,43 @@
<if test="request.method != null">
and test_case.method = #{request.method}
</if>
<if test="request.filters != null and request.filters.size() > 0">
<foreach collection="request.filters.entrySet()" index="key" item="values">
<if test="values != null and values.size() > 0">
<choose>
<when test="key=='priority'">
and test_case.priority in
<foreach collection="values" item="value" separator="," open="(" close=")">
#{value}
</foreach>
</when>
<when test="key=='type'">
and test_case.type in
<foreach collection="values" item="value" separator="," open="(" close=")">
#{value}
</foreach>
</when>
<when test="key=='method'">
and test_case.method in
<foreach collection="values" item="value" separator="," open="(" close=")">
#{value}
</foreach>
</when>
<when test="key=='status'">
and test_case.review_status in
<foreach collection="values" item="value" separator="," open="(" close=")">
#{value}
</foreach>
</when>
</choose>
</if>
</foreach>
</if>
<include refid="filter"/>
</where>
<if test="request.orders != null and request.orders.size() > 0">
order by
<foreach collection="request.orders" separator="," item="order">
<choose>
<!-- <when test="order.name == 'num'">-->
<!-- test_case.num ${order.type}-->
<!-- </when>-->
<when test="order.name == 'custom_num'">
test_case.num ${order.type}, test_case.custom_num ${order.type}
</when>
<when test="order.name == 'priority'">
test_case.priority ${order.type}
</when>
<otherwise>
test_case_review_test_case.${order.name} ${order.type}
</otherwise>
</choose>
</sql>
<sql id="filter">
<if test="request.filters != null and request.filters.size() > 0">
<foreach collection="request.filters.entrySet()" index="key" item="values">
<if test="values != null and values.size() > 0">
<choose>
<when test="key=='priority'">
and test_case.priority in
<foreach collection="values" item="value" separator="," open="(" close=")">
#{value}
</foreach>
</when>
<when test="key=='type'">
and test_case.type in
<foreach collection="values" item="value" separator="," open="(" close=")">
#{value}
</foreach>
</when>
<when test="key=='method'">
and test_case.method in
<foreach collection="values" item="value" separator="," open="(" close=")">
#{value}
</foreach>
</when>
<when test="key=='status'">
and test_case.review_status in
<foreach collection="values" item="value" separator="," open="(" close=")">
#{value}
</foreach>
</when>
</choose>
</if>
</foreach>
</if>
</select>
</sql>
<select id="selectIds" resultType="java.lang.String">
select test_case_review_test_case.id as id
@ -398,4 +386,20 @@
#{id}
</foreach>
</select>
<select id="listForMinder" resultType="io.metersphere.track.dto.TestReviewCaseDTO">
select tcrtc.id as id,
tcrtc.review_id as reviewId,
test_case.id as caseId, test_case.name, test_case.priority,
test_case.type, test_case.node_path, test_case.method, test_case.review_status,
test_case.remark as remark, test_case.maintainer, test_case.steps as steps,
test_case.node_id as nodeId
from test_case_review_test_case tcrtc
inner join test_case
on tcrtc.case_id = test_case.id
<where>
tcrtc.review_id = #{request.reviewId}
and test_case.node_id = #{request.nodeId}
</where>
order by tcrtc.update_time desc;
</select>
</mapper>

View File

@ -62,6 +62,13 @@ public class TestCaseController {
return testCaseService.listTestCase(request);
}
@PostMapping("/list")
@RequiresPermissions("PROJECT_TRACK_CASE:READ")
public List<TestCaseDTO> list(@RequestBody QueryTestCaseRequest request) {
checkPermissionService.checkProjectOwner(request.getProjectId());
return testCaseService.listTestCase(request);
}
@PostMapping("/list/minder")
public List<TestCaseWithBLOBs> listDetail(@RequestBody QueryTestCaseRequest request) {
checkPermissionService.checkProjectOwner(request.getProjectId());
@ -91,11 +98,6 @@ public class TestCaseController {
return testCaseService.recentTestPlans(request, count);
}
@PostMapping("/list")
public List<TestCase> getTestCaseByNodeId(@RequestBody List<String> nodeIds) {
return testCaseService.getTestCaseByNodeId(nodeIds);
}
@PostMapping("/relate/{goPage}/{pageSize}")
public Pager<List<TestCase>> getTestCaseRelateList(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody QueryTestCaseRequest request) {
Page<Object> page = PageHelper.startPage(goPage, pageSize, true);

View File

@ -4,7 +4,6 @@ import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import io.metersphere.base.domain.TestPlanTestCaseWithBLOBs;
import io.metersphere.commons.constants.OperLogConstants;
import io.metersphere.commons.constants.RoleConstants;
import io.metersphere.commons.utils.PageUtils;
import io.metersphere.commons.utils.Pager;
import io.metersphere.log.annotation.MsAuditLog;
@ -13,8 +12,6 @@ import io.metersphere.track.request.testcase.TestPlanCaseBatchRequest;
import io.metersphere.track.request.testplancase.QueryTestPlanCaseRequest;
import io.metersphere.track.request.testplancase.TestPlanFuncCaseBatchRequest;
import io.metersphere.track.service.TestPlanTestCaseService;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
@ -43,11 +40,9 @@ public class TestPlanTestCaseController {
return testPlanTestCaseService.listByPlanId(request);
}
@GetMapping("/list/minder/{planId}")
public List<TestPlanCaseDTO> listForMinder(@PathVariable String planId) {
QueryTestPlanCaseRequest request = new QueryTestPlanCaseRequest();
request.setPlanId(planId);
return testPlanTestCaseService.listForMinder(planId);
@PostMapping("/list/minder")
public List<TestPlanCaseDTO> listForMinder(@RequestBody QueryTestPlanCaseRequest request) {
return testPlanTestCaseService.listForMinder(request);
}
@GetMapping("/list/node/{planId}/{nodePaths}")

View File

@ -4,7 +4,6 @@ import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import io.metersphere.base.domain.TestCaseReviewTestCase;
import io.metersphere.commons.constants.OperLogConstants;
import io.metersphere.commons.constants.RoleConstants;
import io.metersphere.commons.utils.PageUtils;
import io.metersphere.commons.utils.Pager;
import io.metersphere.log.annotation.MsAuditLog;
@ -13,8 +12,6 @@ import io.metersphere.track.request.testplancase.TestReviewCaseBatchRequest;
import io.metersphere.track.request.testreview.DeleteRelevanceRequest;
import io.metersphere.track.request.testreview.QueryCaseReviewRequest;
import io.metersphere.track.service.TestReviewTestCaseService;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
@ -57,9 +54,9 @@ public class TestReviewTestCaseController {
testReviewTestCaseService.editTestCaseForMinder(testCases);
}
@PostMapping("/list/all")
public List<TestReviewCaseDTO> getTestReviewCases(@RequestBody QueryCaseReviewRequest request) {
return testReviewTestCaseService.list(request);
@PostMapping("/list/minder")
public List<TestReviewCaseDTO> listForMinder(@RequestBody QueryCaseReviewRequest request) {
return testReviewTestCaseService.listForMinder(request);
}
@PostMapping("/edit")

View File

@ -27,6 +27,8 @@ public class QueryTestCaseRequest extends BaseQueryRequest {
private String caseCoverage;
private String nodeId;
private long createTime = 0;
private long relevanceCreateTime = 0;
private List<String> testCaseContainIds;

View File

@ -34,5 +34,7 @@ public class QueryTestPlanCaseRequest extends TestPlanTestCase {
private String method;
private String nodeId;
private Map<String, Object> combine;
}

View File

@ -1,6 +1,5 @@
package io.metersphere.track.request.testreview;
import io.metersphere.base.domain.TestCaseReview;
import io.metersphere.base.domain.TestCaseReviewTestCase;
import io.metersphere.controller.request.OrderRequest;
import lombok.Getter;
@ -32,6 +31,8 @@ public class QueryCaseReviewRequest extends TestCaseReviewTestCase {
private String node;
private String nodeId;
private String method;
private Map<String, Object> combine;

View File

@ -48,8 +48,6 @@ public class TestPlanTestCaseService {
@Resource
ExtTestPlanTestCaseMapper extTestPlanTestCaseMapper;
@Resource
private TestCaseTestMapper testCaseTestMapper;
@Resource
private LoadTestMapper loadTestMapper;
@Resource
private ApiTestCaseMapper apiTestCaseMapper;
@ -209,8 +207,8 @@ public class TestPlanTestCaseService {
return extTestPlanTestCaseMapper.updateTestCaseStates(ids, reportStatus);
}
public List<TestPlanCaseDTO> listForMinder(String planId) {
return extTestPlanTestCaseMapper.listForMinder(planId);
public List<TestPlanCaseDTO> listForMinder(QueryTestPlanCaseRequest request) {
return extTestPlanTestCaseMapper.listForMinder(request);
}
public void editTestCaseForMinder(List<TestPlanTestCaseWithBLOBs> testPlanTestCases) {

View File

@ -340,4 +340,8 @@ public class TestReviewTestCaseService {
}
return null;
}
public List<TestReviewCaseDTO> listForMinder(QueryCaseReviewRequest request) {
return extTestReviewCaseMapper.listForMinder(request);
}
}

View File

@ -23,7 +23,6 @@
<script>
import MsFullScreenButton from "@/business/components/common/components/MsFullScreenButton";
import {listenNodeSelected} from "@/business/components/track/common/minder/minderUtils";
export default {
name: "MsModuleMinder",
components: {MsFullScreenButton},
@ -35,12 +34,6 @@ export default {
return []
}
},
dataMap: {
type: Map,
default() {
return new Map();
}
},
tags: {
type: Array,
default() {
@ -65,7 +58,8 @@ export default {
tagDisableCheck: Function,
tagEditCheck: Function,
priorityDisableCheck: Function,
disabled: Boolean
disabled: Boolean,
ignoreNum: Boolean
},
data() {
return {
@ -100,18 +94,14 @@ export default {
this.defaultMode = Number.parseInt(model);
}
}
},
watch: {
dataMap() {
this.$nextTick(() => {
if (this.selectNode && this.selectNode.data) {
this.handleNodeSelect(this.selectNode);
} else {
this.parse(this.importJson.root, this.treeNodes);
}
this.reload();
})
}
this.$nextTick(() => {
if (this.selectNode && this.selectNode.data) {
this.handleNodeSelect(this.selectNode);
} else {
this.parse(this.importJson.root, this.treeNodes);
}
this.reload();
});
},
methods: {
handleMoldChange(index) {
@ -125,24 +115,21 @@ export default {
},
parse(root, children) {
root.children = [];
if (root.data.id === 'root') {
// nodeId
let rootChildData = this.dataMap.get("");
if (rootChildData) {
rootChildData.forEach((dataNode) => {
root.children.push(dataNode);
})
}
if (!children) {
children = [];
}
//
let dataNodes = this.dataMap.get(root.data.id);
if (dataNodes) {
dataNodes.forEach((dataNode) => {
root.children.push(dataNode);
})
let caseNum = root.data.caseNum;
if (children.length < 1 && (this.ignoreNum || caseNum && caseNum > 0)) {
root.children.push({
data: {
text: '',
type: 'tmp',
expandState:"collapse"
},
});
}
if (children == null || children.length < 1) {
if (children.length < 1) {
return;
}
@ -153,6 +140,7 @@ export default {
id: item.id,
disable: true,
type: 'node',
caseNum: item.caseNum,
path: root.data.path + "/" + item.name,
expandState:"collapse"
},
@ -168,10 +156,7 @@ export default {
this.isActive = false;
this.$nextTick(() => {
this.isActive = true;
})
this.$nextTick(() => {
listenNodeSelected();
})
});
},
setJsonImport(data) {
this.importJson = data;

View File

@ -2,12 +2,12 @@
<ms-module-minder
v-loading="result.loading"
:tree-nodes="treeNodes"
:data-map="dataMap"
:tags="tags"
minder-key="testCase"
:select-node="selectNode"
:distinct-tags="tags"
:tag-edit-check="tagEditCheck()"
@afterMount="handleAfterMount"
:priority-disable-check="priorityDisableCheck()"
:disabled="disabled"
@save="save"
@ -18,11 +18,15 @@
<script>
import MsModuleMinder from "@/business/components/common/components/MsModuleMinder";
import {
appendChild,
getTestCaseDataMap,
parseCase, priorityDisableCheck, tagEditCheck, updateNode
handleExpandToLevel, handleTestCaseAdd, handTestCaeEdit,
listenBeforeExecCommand,
listenNodeSelected,
loadSelectNodes,
priorityDisableCheck,
tagEditCheck,
} from "@/business/components/track/common/minder/minderUtils";
import {getNodePath, hasPermission} from "@/common/js/utils";
import {getTestCasesForMinder} from "@/network/testCase";
export default {
name: "TestCaseMinder",
components: {MsModuleMinder},
@ -31,7 +35,8 @@ name: "TestCaseMinder",
testCase: [],
dataMap: new Map(),
tags: [this.$t('api_test.definition.request.case'), this.$t('test_track.case.prerequisite'), this.$t('commons.remark')],
result: {}
result: {loading: false},
needRefresh: false
}
},
props: {
@ -63,7 +68,6 @@ name: "TestCaseMinder",
if (this.$refs.minder) {
this.$refs.minder.handleNodeSelect(this.selectNode);
}
// this.getTestCases();
}
},
mounted() {
@ -73,22 +77,32 @@ name: "TestCaseMinder",
this.$refs.minder.setJsonImport(importJson);
}
}
this.$nextTick(() => {
this.getTestCases();
})
},
methods: {
getTestCases() {
if (this.projectId) {
// let param = {
// projectId: this.projectId,
// nodeIds: this.selectNodeIds
// }
this.result = this.$post('/test/case/list/minder', this.condition,response => {
this.testCase = response.data;
this.dataMap = getTestCaseDataMap(this.testCase);
});
}
handleAfterMount() {
listenNodeSelected(() => {
let param = {
request: {
projectId: this.projectId,
},
result: this.result,
isDisable: false
}
loadSelectNodes(param, getTestCasesForMinder);
});
listenBeforeExecCommand((even) => {
if (even.commandName === 'expandtolevel') {
let level = Number.parseInt(even.commandArgs);
let param = {
request: {
projectId: this.projectId,
},
result: this.result,
isDisable: false
}
handleExpandToLevel(level, even.minder.getRoot(), param, getTestCasesForMinder);
}
});
},
save(data) {
let saveCases = [];
@ -101,7 +115,6 @@ name: "TestCaseMinder",
}
this.result = this.$post('/test/case/minder/edit', param, () => {
this.$success(this.$t('commons.save_success'));
this.getTestCases();
});
},
buildSaveCase(root, saveCases, deleteCases, parent) {
@ -190,20 +203,26 @@ name: "TestCaseMinder",
priorityDisableCheck() {
return priorityDisableCheck;
},
// tab
addCase(data, type) {
let nodeData = parseCase(data, new Map());
let minder = window.minder;
let jsonImport = minder.exportJson();
if (type === 'edit') {
updateNode(jsonImport.root, nodeData);
handTestCaeEdit(data);
} else {
appendChild(data.nodeId, jsonImport.root, nodeData);
handleTestCaseAdd(data.nodeId, data);
}
this.$refs.minder.setJsonImport(jsonImport);
this.needRefresh = true;
},
refresh() {
if (this.$refs.minder) {
this.$refs.minder.reload();
// tab
if (this.needRefresh) {
let jsonImport = window.minder.exportJson();
this.$refs.minder.setJsonImport(jsonImport);
this.$nextTick(() => {
if (this.$refs.minder) {
this.$refs.minder.reload();
}
});
this.needRefresh = false;
}
}
}

View File

@ -8,6 +8,7 @@
minder-key="testPlan"
:select-node="selectNode"
:distinct-tags="[...tags, this.$t('test_track.plan.plan_status_prepare')]"
:ignore-num="true"
@afterMount="handleAfterMount"
@save="save"
ref="minder"
@ -17,16 +18,17 @@
<script>
import MsModuleMinder from "@/business/components/common/components/MsModuleMinder";
import {
getTestCaseDataMap,
handleExpandToLevel, listenBeforeExecCommand, listenNodeSelected, loadSelectNodes,
tagBatch,
} from "@/business/components/track/common/minder/minderUtils";
import {getPlanCasesForMinder} from "@/network/testCase";
export default {
name: "TestPlanMinder",
components: {MsModuleMinder},
data() {
return{
dataMap: new Map(),
result: {},
result: {loading: false},
tags: [this.$t('test_track.plan_view.pass'), this.$t('test_track.plan_view.failure'), this.$t('test_track.plan_view.blocking'), this.$t('test_track.plan_view.skip')],
}
},
@ -57,39 +59,49 @@ name: "TestPlanMinder",
this.$refs.minder.setJsonImport(importJson);
}
}
this.$nextTick(() => {
this.getTestCases();
})
},
watch: {
selectNode() {
if (this.$refs.minder) {
this.$refs.minder.handleNodeSelect(this.selectNode);
}
// this.getTestCases();
}
},
methods: {
handleAfterMount() {
listenNodeSelected(() => {
let param = {
request: {planId: this.planId},
result: this.result,
isDisable: true
}
loadSelectNodes(param, getPlanCasesForMinder, this.setParamCallback);
});
listenBeforeExecCommand((even) => {
if (even.commandName === 'expandtolevel') {
let level = Number.parseInt(even.commandArgs);
let param = {
request: {planId: this.planId},
result: this.result,
isDisable: true
}
handleExpandToLevel(level, even.minder.getRoot(), param, getPlanCasesForMinder, this.setParamCallback);
}
});
tagBatch([...this.tags, this.$t('test_track.plan.plan_status_prepare')]);
},
getTestCases() {
if (this.projectId) {
this.result = this.$get('/test/plan/case/list/minder/' + this.planId, response => {
this.dataMap = getTestCaseDataMap(response.data, true, (data, item) => {
if (item.status === 'Pass') {
data.resource.push(this.$t('test_track.plan_view.pass'));
} else if (item.status === 'Failure') {
data.resource.push(this.$t('test_track.plan_view.failure'));
} else if (item.status === 'Blocking') {
data.resource.push(this.$t('test_track.plan_view.blocking'));
} else if (item.status === 'Skip') {
data.resource.push(this.$t('test_track.plan_view.skip'));
} else {
data.resource.push(this.$t('test_track.plan.plan_status_prepare'));
}
});
});
setParamCallback(data, item) {
if (item.status === 'Pass') {
data.resource.push(this.$t('test_track.plan_view.pass'));
} else if (item.status === 'Failure') {
data.resource.push(this.$t('test_track.plan_view.failure'));
} else if (item.status === 'Blocking') {
data.resource.push(this.$t('test_track.plan_view.blocking'));
} else if (item.status === 'Skip') {
data.resource.push(this.$t('test_track.plan_view.skip'));
} else {
data.resource.push(this.$t('test_track.plan.plan_status_prepare'));
}
},
save(data) {

View File

@ -8,6 +8,7 @@
minder-key="testReview"
:select-node="selectNode"
:distinct-tags="[...tags, $t('test_track.plan.plan_status_prepare')]"
:ignore-num="true"
@afterMount="handleAfterMount"
@save="save"
ref="minder"
@ -16,7 +17,13 @@
<script>
import MsModuleMinder from "@/business/components/common/components/MsModuleMinder";
import {getTestCaseDataMap, tagBatch} from "@/business/components/track/common/minder/minderUtils";
import {
handleExpandToLevel, listenBeforeExecCommand,
listenNodeSelected,
loadSelectNodes,
tagBatch
} from "@/business/components/track/common/minder/minderUtils";
import {getReviewCasesForMinder} from "@/network/testCase";
export default {
name: "TestReviewMinder",
components: {MsModuleMinder},
@ -24,7 +31,7 @@ name: "TestReviewMinder",
return{
dataMap: new Map(),
tags: [this.$t('test_track.plan_view.pass'), this.$t('test_track.plan_view.not_pass')],
result: {}
result: {loading: false}
}
},
props: {
@ -46,16 +53,13 @@ name: "TestReviewMinder",
this.$refs.minder.setJsonImport(importJson);
}
}
this.$nextTick(() => {
this.getTestCases();
})
},
watch: {
selectNode() {
if (this.$refs.minder) {
this.$refs.minder.handleNodeSelect(this.selectNode);
}
// this.getTestCases();
}
},
computed: {
@ -68,27 +72,41 @@ name: "TestReviewMinder",
},
methods: {
handleAfterMount() {
listenNodeSelected(() => {
let param = {
request: {
reviewId: this.reviewId,
},
result: this.result,
isDisable: true
}
loadSelectNodes(param, getReviewCasesForMinder, this.setParamCallback);
});
listenBeforeExecCommand((even) => {
if (even.commandName === 'expandtolevel') {
let level = Number.parseInt(even.commandArgs);
let param = {
request: {
reviewId: this.reviewId,
},
result: this.result,
isDisable: true
}
handleExpandToLevel(level, even.minder.getRoot(), param, getReviewCasesForMinder, this.setParamCallback);
}
});
tagBatch([...this.tags, this.$t('test_track.plan.plan_status_prepare')]);
},
getTestCases() {
if (this.projectId) {
let param = {
reviewId: this.reviewId,
nodeIds: this.selectNodeIds
};
this.result = this.$post('/test/review/case/list/all', param, response => {
this.dataMap = getTestCaseDataMap(response.data, true, (data, item) => {
if (item.reviewStatus === 'Pass') {
data.resource.push(this.$t('test_track.plan_view.pass'));
} else if (item.reviewStatus === 'UnPass') {
data.resource.push(this.$t('test_track.plan_view.not_pass'));
} else {
data.resource.push(this.$t('test_track.plan.plan_status_prepare'));
}
data.caseId = item.caseId;
});
});
setParamCallback(data, item) {
if (item.reviewStatus === 'Pass') {
data.resource.push(this.$t('test_track.plan_view.pass'));
} else if (item.reviewStatus === 'UnPass') {
data.resource.push(this.$t('test_track.plan_view.not_pass'));
} else {
data.resource.push(this.$t('test_track.plan.plan_status_prepare'));
}
data.caseId = item.caseId;
},
save(data) {
let saveCases = [];

View File

@ -1,101 +1,5 @@
import i18n from "@/i18n/i18n";
export function getTestCaseDataMap(testCase, isDisable, setParamCallback) {
let dataMap = new Map();
if (testCase) {
testCase.forEach(item => {
parseCase(item, dataMap, isDisable, setParamCallback);
})
}
return dataMap;
}
export function parseCase(item, dataMap, isDisable, setParamCallback) {
if (item.steps) {
item.steps = JSON.parse(item.steps);
} else {
item.steps = [];
}
// if (item.tags && item.tags.length > 0) {
// item.tags = JSON.parse(item.tags);
// }
let mapItem = dataMap.get(item.nodeId);
let nodeItem = {
data: {
id: item.id,
text: item.name,
priority: Number.parseInt(item.priority.substring(item.priority.length - 1 )) + 1,
resource: [i18n.t('api_test.definition.request.case')],
type: item.type,
method: item.method,
maintainer: item.maintainer,
stepModel: item.stepModel
}
}
if (setParamCallback) {
setParamCallback(nodeItem.data, item);
}
if (isDisable) {
nodeItem.data.disable = true;
// 用例节点可以打标签
nodeItem.data.allowDisabledTag = true;
}
parseChildren(nodeItem, item, isDisable);
if (mapItem) {
mapItem.push(nodeItem);
} else {
mapItem = [];
mapItem.push(nodeItem);
dataMap.set(item.nodeId, mapItem);
}
return nodeItem;
}
function _parseChildren(children, k, v, isDisable) {
if (k) {
let node = {
data: {
text: k,
resource: v ? [v] : []
},
children: []
}
if (isDisable) {
node.data.disable = true;
}
children.push(node);
return node;
}
}
function parseChildren(nodeItem, item, isDisable) {
nodeItem.children = [];
let children = [];
_parseChildren(children, item.prerequisite, i18n.t('test_track.case.prerequisite'), isDisable);
if (item.stepModel === 'TEXT') {
let descNode = _parseChildren(children, item.stepDescription, null, isDisable);
if (descNode) {
descNode.children = [];
_parseChildren(descNode.children, item.expectedResult, null, isDisable);
}
} else {
if (item.steps) {
item.steps.forEach((step) => {
let descNode = _parseChildren(children, step.desc, undefined, isDisable);
if (descNode) {
descNode.data.num = step.num;
descNode.children = [];
_parseChildren(descNode.children, step.result, undefined, isDisable);
}
});
}
}
_parseChildren(children, item.remark, i18n.t('commons.remark'), isDisable);
nodeItem.children = children;
}
export function listenNodeSelected(callback) {
let minder = window.minder;
minder.on('selectionchange ', function (even) {
@ -123,41 +27,77 @@ export function listenBeforeExecCommand(callback) {
});
}
export function appendChild(appendPid, root, node) {
if (root.data.id === appendPid) {
root.children.push(node);
return;
/**
* 加载模块下的用例
* @param projectId
* @param result
*/
export function loadNode(node, param, getCaseFuc, setParamCallback) {
let data = node.data;
if (!data.loaded && data.type === 'node') {
if (param.result) {
param.result.loading = true;
}
let request = param.request;
request.nodeId = data.id;
if (data.id === 'root') {
request.nodeId = '';
}
if (getCaseFuc) {
getCaseFuc(request, (testCases) => {
appendCaseNodes(node, testCases, param, setParamCallback);
});
}
}
if (!root.children) {
root.children = [];
}
let children = root.children;
for (const index in children) {
let item = children[index];
if (item.data.id === appendPid) {
item.data.expandState = "expand";
item.children.push(node);
return;
} else {
appendChild(appendPid, item, node);
data.loaded = true;
}
/**
* 加载当前选中的模块下的用例
* @param projectId
* @param result
*/
export function loadSelectNodes(param, getCaseFuc, setParamCallback) {
let minder = window.minder;
let selectNodes = minder.getSelectedNodes();
selectNodes.forEach(node => {
loadNode(node, param, getCaseFuc, setParamCallback);
});
}
export function handleExpandToLevel(level, node, param, getCaseFuc, setParamCallback) {
loadNode(node, param, getCaseFuc, setParamCallback);
level--;
if (level > 0) {
if (node.children) {
node.children.forEach(item => {
handleExpandToLevel(level, item, param, getCaseFuc, setParamCallback);
});
}
}
}
export function updateNode(root, node) {
if (!root.children) {
root.children = [];
}
let children = root.children;
for (const index in children) {
let item = children[index];
if (item.data.id === node.data.id) {
children[index] = node;
return;
} else {
updateNode(item, node);
export function handleTestCaseAdd(pid, data) {
window.minder.getRoot().traverse(function(node) {
if (node.data.id === pid && node.data.loaded) {
appendCase(node, data);
expandNode(node);
node.render();
}
}
});
}
export function handTestCaeEdit(data) {
window.minder.getRoot().traverse(function(node) {
if (node.data.id === data.id) {
let pNode = node.parent;
window.minder.removeNode(node);
appendCase(pNode, data);
expandNode(pNode);
pNode.render();
}
});
}
export function tagChildren(node, resourceName, distinctTags) {
@ -213,6 +153,135 @@ function modifyParentNodeTag(node, resourceName) {
}
export function appendCase(parent, item, isDisable, setParamCallback) {
let caseData = {
id: item.id,
text: item.name,
priority: Number.parseInt(item.priority.substring(item.priority.length - 1 )) + 1,
resource: [i18n.t('api_test.definition.request.case')],
type: item.type,
method: item.method,
maintainer: item.maintainer,
stepModel: item.stepModel
}
if (setParamCallback) {
setParamCallback(caseData, item);
}
if (isDisable) {
caseData.disable = true;
// 用例节点可以打标签
caseData.allowDisabledTag = true;
}
let caseNode = appendChildNode(parent, caseData);
appendChildNode(caseNode, getNodeData(item.prerequisite, i18n.t('test_track.case.prerequisite'), isDisable));
appendChildNode(caseNode, getNodeData(item.remark, i18n.t('commons.remark'), isDisable));
if (item.stepModel === 'TEXT') {
let descData = getNodeData(item.stepDescription, null, isDisable);
let descNode = appendChildNode(caseNode, descData);
if (descData) {
appendChildNode(descNode, getNodeData(item.expectedResult, null, isDisable));
}
} else {
if (item.steps) {
if (!(item.steps instanceof Array)) {
item.steps = JSON.parse(item.steps);
}
item.steps.forEach((step) => {
let descData = getNodeData(step.desc, null, isDisable);
if (descData) {
descData.num = step.num;
let descNode = appendChildNode(caseNode, descData);
appendChildNode(descNode, getNodeData(step.result, null, isDisable));
}
});
}
}
}
function getNodeData(text, resource, isDisable) {
if (text) {
let data = {
text: text,
resource: resource ? [resource] : []
};
if (isDisable) {
data.disable = true;
}
return data;
}
}
/**
* 添加用例节点
* @param parent
* @param testCases
* @param result
*/
export function appendCaseNodes(parent, testCases, param, setParamCallback) {
wipeTmp(parent);
if (testCases) {
for (let i = 0; i < testCases.length; i++) {
appendCase(parent, testCases[i], param.isDisable, setParamCallback);
}
}
expandNode(parent);
if (param.result) {
param.result.loading = false;
}
}
/**
* 去掉临时节点
* @param parent
*/
function wipeTmp(node) {
let children = node.children;
if (children) {
for (let i = 0; i < children.length; i++) {
let item = children[i];
if (item.data.type === 'tmp') {
window.minder.removeNode(item);
break;
}
}
}
}
function appendChildNode(parent, childData, fresh) {
if (!childData || !childData.text) {
return;
}
let km = window.minder;
var node = km.createNode(childData, parent);
km.select(node, true);
if (fresh) {
if (parent.isExpanded()) {
node.render();
} else {
parent.expand();
parent.renderTree();
}
km.layout(60);
}
return node;
}
function expandNode(node) {
node.expand();
node.renderTree();
window.minder.layout(60);
}
/**
* 测试计划和评审支持给模块批量打标签
* @param distinctTags
*/
export function tagBatch(distinctTags) {
listenBeforeExecCommand((even) => {
let minder = window.minder;

View File

@ -0,0 +1,25 @@
import {post} from "@/common/js/ajax";
export function getTestCasesForMinder(request, callback) {
return post('/test/case/list/minder', request, (response) => {
if (callback) {
callback(response.data);
}
});
}
export function getPlanCasesForMinder(request, callback) {
return post('/test/plan/case/list/minder', request, (response) => {
if (callback) {
callback(response.data);
}
});
}
export function getReviewCasesForMinder(request, callback) {
return post('/test/review/case/list/minder', request, (response) => {
if (callback) {
callback(response.data);
}
});
}