feat: 用例评审脑图编辑

This commit is contained in:
chenjianxing 2021-03-17 10:53:53 +08:00
parent 80dfe48968
commit fc04de0980
4 changed files with 63 additions and 65 deletions

View File

@ -49,7 +49,7 @@
"xml-js": "^1.6.11",
"yan-progress": "^1.0.3",
"jsonpath": "^1.1.0",
"vue-minder-editor-plus": "^1.0.16",
"vue-minder-editor-plus": "^1.0.17",
"jsencrypt": "^3.1.0"
},
"devDependencies": {

View File

@ -6,6 +6,7 @@
:import-json="importJson"
:height="700"
:progress-enable="false"
:tags="tags"
@save="save"
/>
</div>
@ -28,7 +29,13 @@ export default {
default() {
return new Map();
}
}
},
tags: {
type: Array,
default() {
return []
}
},
},
data() {
return {

View File

@ -3,6 +3,7 @@
v-loading="result.loading"
:tree-nodes="treeNodes"
:data-map="dataMap"
:tags="tags"
@save="save"
/>
</template>
@ -17,6 +18,7 @@ name: "TestReviewMinder",
return{
testCase: [],
dataMap: new Map(),
tags: ['通过', '不通过'],
result: {}
}
},
@ -44,27 +46,32 @@ name: "TestReviewMinder",
getTestCases() {
if (this.projectId) {
this.result = this.$post('/test/review/case/list/all', {reviewId: this.reviewId}, response => {
this.testCase = response.data;
this.dataMap = getTestCaseDataMap(this.testCase);
this.dataMap = getTestCaseDataMap(response.data, true, (data, item) => {
if (item.reviewStatus === 'Pass') {
data.resource.push("通过");
} else if (item.reviewStatus === 'UnPass') {
data.resource.push("不通过");
} else {
data.resource.push("未开始");
}
data.caseId = item.caseId;
});
});
}
},
save(data) {
// let saveCases = [];
// this.buildSaveCase(data.root, saveCases, undefined);
// console.log(saveCases);
// let param = {
// projectId: this.projectId,
// data: saveCases
// }
// this.result = this.$post('/test/case/minder/edit', param, () => {
// this.$success(this.$t('commons.save_success'));
// });
console.log(data);
let saveCases = [];
this.buildSaveCase(data.root, saveCases);
console.log(saveCases);
this.result = this.$post('/test/review/case/minder/edit', saveCases, () => {
this.$success(this.$t('commons.save_success'));
});
},
buildSaveCase(root, saveCases, parent) {
buildSaveCase(root, saveCases) {
let data = root.data;
if (data.resource && data.resource.indexOf("用例") > -1) {
this._buildSaveCase(root, saveCases, parent);
this._buildSaveCase(root, saveCases);
} else {
if (root.children) {
root.children.forEach((childNode) => {
@ -73,51 +80,24 @@ name: "TestReviewMinder",
}
}
},
_buildSaveCase(node, saveCases, parent) {
_buildSaveCase(node, saveCases) {
let data = node.data;
let isChange = false;
if (!data.changed) {
return;
}
let testCase = {
id: data.id,
name: data.text,
nodeId: parent ? parent.id : "",
nodePath: parent ? parent.path : "",
type: data.type ? data.type : 'functional',
method: data.method ? data.method : 'manual',
maintainer: data.maintainer,
priority: 'P' + data.priority,
caseId: data.caseId,
id: data.id
// name: data.text,
};
if (data.changed) isChange = true;
let steps = [];
let stepNum = 1;
if (node.children) {
node.children.forEach((childNode) => {
let childData = childNode.data;
if (childData.resource && childData.resource.indexOf('前置条件') > -1) {
testCase.prerequisite = childData.text;
} else if (childData.resource && childData.resource.indexOf('备注') > -1) {
testCase.remark = childData.text;
} else {
//
let step = {};
step.num = stepNum++;
step.desc = childData.text;
if (childNode.children) {
let result = "";
childNode.children.forEach((child) => {
result += child.data.text;
if (child.data.changed) isChange = true;
})
step.result = result;
}
steps.push(step);
}
if (childData.changed) isChange = true;
})
}
testCase.steps = JSON.stringify(steps);
if (isChange) {
saveCases.push(testCase);
if (data.resource.length > 1) {
if (data.resource.indexOf('不通过')) {
testCase.status = 'UnPass';
} else if (data.resource.indexOf('通过')) {
testCase.status = 'Pass';
}
}
saveCases.push(testCase);
},
}
}

View File

@ -1,4 +1,4 @@
export function getTestCaseDataMap(testCase) {
export function getTestCaseDataMap(testCase, isDisable, setParamCallback) {
let dataMap = new Map();
testCase.forEach(item => {
item.steps = JSON.parse(item.steps);
@ -17,7 +17,15 @@ export function getTestCaseDataMap(testCase) {
maintainer: item.maintainer
}
}
parseChildren(nodeItem, item);
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 {
@ -29,23 +37,23 @@ export function getTestCaseDataMap(testCase) {
return dataMap;
}
function parseChildren(nodeItem, item) {
function parseChildren(nodeItem, item, isDisable) {
nodeItem.children = [];
let children = [];
_parseChildren(children, item.prerequisite, "前置条件");
_parseChildren(children, item.prerequisite, "前置条件", isDisable);
item.steps.forEach((step) => {
let descNode = _parseChildren(children, step.desc, "测试步骤");
let descNode = _parseChildren(children, step.desc, "测试步骤", isDisable);
if (descNode) {
descNode.data.num = step.num;
descNode.children = [];
_parseChildren(descNode.children, step.result, "预期结果");
_parseChildren(descNode.children, step.result, "预期结果", isDisable);
}
});
_parseChildren(children, item.remark, "备注");
_parseChildren(children, item.remark, "备注", isDisable);
nodeItem.children = children;
}
function _parseChildren(children, k, v) {
function _parseChildren(children, k, v, isDisable) {
if (k) {
let node = {
data: {
@ -53,6 +61,9 @@ function _parseChildren(children, k, v) {
resource: [v]
}
}
if (isDisable) {
node.data.disable = true;
}
children.push(node);
return node;
}