From 2711467cfc1b95c885db0a25635dad4457c3019f Mon Sep 17 00:00:00 2001 From: wxg0103 <727495428@qq.com> Date: Thu, 14 Jul 2022 15:16:47 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E5=AE=9A=E4=B9=89):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=A4=8D=E5=88=B6=E7=9A=84=E5=9C=BA=E6=99=AF?= =?UTF-8?q?=E5=8F=AF=E4=BB=A5=E6=B7=BB=E5=8A=A0=E5=A4=9A=E4=B8=AA=E5=9C=BA?= =?UTF-8?q?=E6=99=AF=E6=96=AD=E8=A8=80=E7=9A=84=E7=BC=BA=E9=99=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1014823 --user=王孝刚 [接口测试] github#15731场景断言,可以新增多个 https://www.tapd.cn/55049933/s/1201948 --- .../automation/scenario/EditApiScenario.vue | 44 +--------- .../api/automation/scenario/menu/Menu.js | 87 +++++++++++++++---- 2 files changed, 70 insertions(+), 61 deletions(-) diff --git a/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue b/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue index 93796b2dc3..bd2795167e 100644 --- a/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue +++ b/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue @@ -1157,50 +1157,8 @@ export default { } } }, - scenarioAssertion(type, plugin, isAssertions, data) { - let isChildren = true; - if (!data) { - data = this.scenarioDefinition; - isChildren = false; - } - data.forEach(item => { - if (item.type === type) { - item.active = true; - item.scenarioAss = true; - isAssertions = true; - } - if (!isChildren) { - this.reloadTree = getUUID(); - } - }) - if (!isAssertions) { - setComponent(type, this, plugin); - for (let i in data) { - if (data[i].type === "Assertions") { - data[i].active = true; - data[i].scenarioAss = true; - let assertions = data[i]; - data.splice(i, 1); - data.unshift(assertions); - this.sort(); - } - } - } - }, addComponent(type, plugin) { - let isAssertions = false; - if (type === 'Assertions') { - if (this.selectedTreeNode !== undefined && this.selectedTreeNode.type === 'scenario' && this.selectedTreeNode.referenced === 'Copy') { - this.selectedTreeNode.active = true; - this.scenarioAssertion(type, plugin, isAssertions, this.selectedTreeNode.hashTree); - this.selectedNode.expanded = true; - this.cancelBatchProcessing(); - } else { - this.scenarioAssertion(type, plugin, isAssertions); - } - } else { - setComponent(type, this, plugin); - } + setComponent(type, this, plugin); }, nodeClick(data, node) { if ((data.referenced != 'REF' && data.referenced != 'Deleted' && !data.disabled && this.stepFilter) || data.refType === 'CASE') { diff --git a/frontend/src/business/components/api/automation/scenario/menu/Menu.js b/frontend/src/business/components/api/automation/scenario/menu/Menu.js index 5ecfeafcfa..bbe1f7f7fb 100644 --- a/frontend/src/business/components/api/automation/scenario/menu/Menu.js +++ b/frontend/src/business/components/api/automation/scenario/menu/Menu.js @@ -1,5 +1,15 @@ import {ELEMENT_TYPE} from "@/business/components/api/automation/scenario/Setting"; -import {Assertions, ConstantTimer, Extract, IfController, JSR223Processor, JDBCProcessor, LoopController, TransactionController, PluginController} from "@/business/components/api/definition/model/ApiTestModel"; +import { + Assertions, + ConstantTimer, + Extract, + IfController, + JDBCProcessor, + JSR223Processor, + LoopController, + PluginController, + TransactionController +} from "@/business/components/api/definition/model/ApiTestModel"; import {getUUID} from "@/common/js/utils"; export function buttons(this_) { @@ -145,32 +155,69 @@ export function buttons(this_) { ]; return buttons.filter(btn => btn.show); } -export function setNode(_this,node) { - if(_this.selectedTreeNode !== undefined){ - if(_this.stepFilter.get("SpecialSteps").indexOf(_this.selectedTreeNode.type) !== -1){ - if (_this.selectedNode.parent.data.hashTree) { - _this.selectedNode.parent.data.hashTree.splice(_this.selectedTreeNode.index, 0, node); - } else { - _this.scenarioDefinition.splice(_this.selectedTreeNode.index, 0, node); - } - _this.$store.state.forceRerenderIndex = getUUID(); - }else{ - _this.selectedTreeNode.hashTree.push(node) ; + +export function scenarioAssertion(data, node) { + node.active = false; + let needAdd = true; + data.forEach(data => { + if (data.type === "Assertions") { + data.active = true; + data.scenarioAss = true; + needAdd = false; + return; } - }else{ - _this.scenarioDefinition.push(node); + }) + if (needAdd) { + data.splice(0, 0, node); } } + +export function setNode(_this, node) { + if (_this.selectedTreeNode !== undefined) { + if (_this.stepFilter.get("SpecialSteps").indexOf(_this.selectedTreeNode.type) !== -1) { + if (_this.selectedNode.parent.data.hashTree) { + //同级请求添加断言,添加到父级 + if (node.type === 'Assertions') { + scenarioAssertion(_this.selectedNode.parent.data.hashTree, node); + } else { + _this.selectedNode.parent.data.hashTree.splice(_this.selectedTreeNode.index, 0, node); + } + } else { + //没有父级的直接加到当前的置顶 + if (node.type === 'Assertions') { + scenarioAssertion(_this.scenarioDefinition, node); + } else { + _this.scenarioDefinition.splice(_this.selectedTreeNode.index, 0, node); + } + } + _this.$store.state.forceRerenderIndex = getUUID(); + } else { + //选择场景时,直接添加到当前场景 + if (node.type === 'Assertions' && _this.selectedTreeNode.type === 'scenario' && _this.selectedTreeNode.referenced === 'Copy') { + scenarioAssertion(_this.selectedTreeNode.hashTree, node); + } else { + _this.selectedTreeNode.hashTree.push(node); + } + } + } else { + if (node.type === 'Assertions') { + scenarioAssertion(_this.scenarioDefinition, node); + } else { + _this.scenarioDefinition.push(node); + } + } +} + export function setComponent(type, _this, plugin) { switch (type) { case ELEMENT_TYPE.IfController: - setNode(_this,new IfController()); + setNode(_this, new IfController()); break; case ELEMENT_TYPE.ConstantTimer: - setNode(_this,new ConstantTimer({label: "SCENARIO-REF-STEP"})); + setNode(_this, new ConstantTimer({label: "SCENARIO-REF-STEP"})); break; case ELEMENT_TYPE.JSR223Processor: - setNode(_this,new JSR223Processor({label: "SCENARIO-REF-STEP"})); + setNode(_this, new JSR223Processor({label: "SCENARIO-REF-STEP"})); break; case ELEMENT_TYPE.JSR223PreProcessor: setNode(_this, new JSR223Processor({type: "JSR223PreProcessor", label: "SCENARIO-REF-STEP"})); @@ -205,7 +252,11 @@ export function setComponent(type, _this, plugin) { _this.$refs.scenarioRelevance.open(); break; default: - setNode(_this,new PluginController({type: plugin.jmeterClazz, stepName: plugin.name, pluginId: plugin.scriptId})); + setNode(_this, new PluginController({ + type: plugin.jmeterClazz, + stepName: plugin.name, + pluginId: plugin.scriptId + })); break; } if (_this.selectedNode) {