fix(接口测试): 修复断言root层级数据添加期望值保存失效的缺陷

--bug=1019961 --user=王孝刚 [接口测试]
GitHub#19876接口定义,接口用例,json文档结构校验,在预期结果处输入值后,再打开,值不见了。
https://www.tapd.cn/55049933/s/1301119
This commit is contained in:
wxg0103 2022-11-22 15:14:06 +08:00 committed by fit2-zhao
parent 07d947b081
commit 25e5c1d223
2 changed files with 63 additions and 18 deletions

View File

@ -158,32 +158,46 @@ export function stepCompute(array, request) {
} }
export function mergeDocumentData(originalData, childMap) { export function mergeDocumentData(originalData, childMap, rootData) {
originalData.forEach(item => { originalData.forEach((item) => {
if (childMap && childMap.has(item.id)) { if (item.id === 'root') {
item.type = rootData.type;
item.name = rootData.name;
item.typeVerification = rootData.typeVerification;
item.arrayVerification = rootData.arrayVerification;
item.contentVerification = rootData.contentVerification;
item.jsonPath = rootData.jsonPath;
item.expectedOutcome = rootData.expectedOutcome;
item.include = rootData.include;
item.conditions = rootData.conditions;
}
if (childMap && childMap.size !== 0 && childMap.has(item.id)) {
let sourceData = JSON.parse(JSON.stringify(item.children)); let sourceData = JSON.parse(JSON.stringify(item.children));
item.children = JSON.parse(JSON.stringify(childMap.get(item.id))); item.children = JSON.parse(JSON.stringify(childMap.get(item.id)));
item.children.forEach(target => { item.children.forEach((target) => {
let index = sourceData.findIndex(source => source.id === target.id); let index = sourceData.findIndex((source) => source.id === target.id);
if (index !== -1) { if (index !== -1) {
target.children = sourceData[index].children target.children = sourceData[index].children;
} }
}) });
if (item.children && item.children.length > 0) { if (item.children && item.children.length > 0) {
mergeDocumentData(item.children, childMap); mergeDocumentData(item.children, childMap);
} }
} }
});
})
} }
export function mergeRequestDocumentData(request) { export function mergeRequestDocumentData(request) {
if (request && request.hashTree && request.hashTree.length > 0) { if (request && request.hashTree && request.hashTree.length > 0) {
let index = request.hashTree.findIndex(item => item.type === 'Assertions'); let index = request.hashTree.findIndex((item) => item.type === 'Assertions');
if (index !== -1) { if (index !== -1) {
if (request.hashTree[index].document && request.hashTree[index].document.originalData && request.hashTree[index].document.tableData.size && request.hashTree[index].document.tableData.size !== 0) { if (request.hashTree[index].document && request.hashTree[index].document.originalData) {
mergeDocumentData(request.hashTree[index].document.originalData, request.hashTree[index].document.tableData); mergeDocumentData(
if (request.hashTree[index].document.type === 'json') { request.hashTree[index].document.originalData,
request.hashTree[index].document.tableData,
request.hashTree[index].document.rootData
);
if (request.hashTree[index].document.type === 'JSON') {
request.hashTree[index].document.data.json = request.hashTree[index].document.originalData; request.hashTree[index].document.data.json = request.hashTree[index].document.originalData;
} else { } else {
request.hashTree[index].document.data.xml = request.hashTree[index].document.originalData; request.hashTree[index].document.data.xml = request.hashTree[index].document.originalData;
@ -191,6 +205,20 @@ export function mergeRequestDocumentData(request) {
} }
} }
} }
//场景断言merge文档断言数据
if (
request &&
request.document &&
request.document.originalData &&
request.document.tableData.size &&
request.document.tableData.size !== 0
) {
mergeDocumentData(request.document.originalData, request.document.tableData);
if (request.document.type === 'json') {
request.document.data.json = request.document.originalData;
} else {
request.document.data.xml = request.document.originalData;
}
}
} }

View File

@ -31,10 +31,21 @@
<el-table-column prop="name" :label="$t('api_test.definition.request.esb_table.name')" width="230"> <el-table-column prop="name" :label="$t('api_test.definition.request.esb_table.name')" width="230">
<template slot-scope="scope"> <template slot-scope="scope">
<el-input <el-input
v-if="(scope.row.status && scope.column.fixed && scope.row.id!=='root') || (scope.row.type !=='object' && !scope.row.name)" v-if="
v-model="scope.row.name" style="width: 140px" size="mini" (scope.row.status && scope.column.fixed && scope.row.id !== 'root') ||
(scope.row.type !== 'object' && !scope.row.name)
"
v-model="scope.row.name"
style="width: 140px"
size="mini"
:placeholder="$t('api_test.definition.request.esb_table.name')" />
<el-input
v-else
:disabled="document.type === 'JSON'"
v-model="scope.row.name"
style="width: 140px"
size="mini"
:placeholder="$t('api_test.definition.request.esb_table.name')" /> :placeholder="$t('api_test.definition.request.esb_table.name')" />
<span v-else>{{ scope.row.name }}</span>
</template> </template>
</el-table-column> </el-table-column>
@ -207,6 +218,9 @@ export default {
// hasChildren // hasChildren
item.hasChildren = item.children && item.children.length > 0 item.hasChildren = item.children && item.children.length > 0
item.idList = [item.id]; item.idList = [item.id];
if (item.id === 'root') {
this.$set(this.document, 'rootData', item);
}
item.children = []; item.children = [];
return item; return item;
}); });
@ -246,6 +260,9 @@ export default {
tree.loadedChildren = true tree.loadedChildren = true
// //
resolve(resolveArr); resolve(resolveArr);
if (tree.id === 'root') {
this.$set(this.document, 'rootData', tree);
}
this.mapData.set(tree.id, resolveArr); this.mapData.set(tree.id, resolveArr);
}, },
checkedAPI() { checkedAPI() {