fix(接口测试): 修复条件控制器添加后无法正确显示的bug

This commit is contained in:
q4speed 2020-12-23 10:57:41 +08:00
parent 6baf28bed3
commit f1dcd2191a
3 changed files with 6 additions and 49 deletions

View File

@ -1,7 +1,6 @@
package io.metersphere.api.dto.scenario.controller;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
@Data
public class IfController {
@ -11,46 +10,4 @@ public class IfController {
private String variable;
private String operator;
private String value;
public boolean isValid() {
if (StringUtils.contains(operator, "empty")) {
return StringUtils.isNotBlank(variable);
}
return StringUtils.isNotBlank(variable) && StringUtils.isNotBlank(operator) && StringUtils.isNotBlank(value);
}
public String getLabel() {
if (isValid()) {
String label = variable + " " + operator;
if (StringUtils.isNotBlank(value)) {
label += " " + this.value;
}
return label;
}
return "";
}
public String getCondition() {
String variable = "\"" + this.variable + "\"";
String operator = this.operator;
String value = "\"" + this.value + "\"";
if (StringUtils.contains(operator, "~")) {
value = "\".*" + this.value + ".*\"";
}
if (StringUtils.equals(operator, "is empty")) {
variable = "empty(" + variable + ")";
operator = "";
value = "";
}
if (StringUtils.equals(operator, "is not empty")) {
variable = "!empty(" + variable + ")";
operator = "";
value = "";
}
return "${__jexl3(" + variable + operator + value + ")}";
}
}

View File

@ -7,7 +7,7 @@
v-if="request.controller && request.controller.isValid()">
<el-row type="flex" align="middle">
<font-awesome-icon :icon="['fas', 'random']"/>
<div class="condition-label">{{ request.controller.label() }}</div>
<div class="condition-label">{{ request.controller.getLabel() }}</div>
</el-row>
</el-button>
</div>
@ -19,7 +19,7 @@
v-if="request.timer && request.timer.isValid()">
<el-row type="flex" align="middle">
<font-awesome-icon :icon="['fas', 'clock']"/>
<div class="condition-label">{{ request.timer && request.timer.label() }}</div>
<div class="condition-label">{{ request.timer && request.timer.getLabel() }}</div>
</el-row>
</el-button>
</div>

View File

@ -962,7 +962,7 @@ export class IfController extends Controller {
return !!this.variable && !!this.operator && !!this.value;
}
label() {
getLabel() {
if (this.isValid()) {
let label = this.variable;
if (this.operator) label += " " + this.operator;
@ -998,7 +998,7 @@ export class ConstantTimer extends Timer {
return this.delay > 0;
}
label() {
getLabel() {
if (this.isValid()) {
return this.delay + " ms";
}
@ -1362,14 +1362,14 @@ class JMXGenerator {
addConstantsTimer(sampler, request) {
if (request.timer && request.timer.isValid() && request.timer.enable) {
sampler.put(new JMXConstantTimer(request.timer.label(), request.timer));
sampler.put(new JMXConstantTimer(request.timer.getLabel(), request.timer));
}
}
getController(sampler, request) {
if (request.controller.isValid() && request.controller.enable) {
if (request.controller instanceof IfController) {
let name = request.controller.label();
let name = request.controller.getLabel();
let variable = "\"" + request.controller.variable + "\"";
let operator = request.controller.operator;
let value = "\"" + request.controller.value + "\"";