refactor: 接口测试保存提示

This commit is contained in:
AgAngle 2020-07-19 22:35:53 +08:00
parent e24ab7a2ad
commit 2860b91508
5 changed files with 57 additions and 22 deletions

View File

@ -14,18 +14,18 @@
</el-select>
</el-input>
<el-button type="primary" plain :disabled="isDisabled || isReadOnly" @click="saveTest">
<el-button type="primary" plain :disabled="isReadOnly" @click="saveTest">
{{$t('commons.save')}}
</el-button>
<el-button type="primary" plain v-if="!isShowRun" :disabled="isDisabled || isReadOnly"
<el-button type="primary" plain :disabled="isReadOnly"
@click="saveRunTest">
{{$t('load_test.save_and_run')}}
</el-button>
<el-button :disabled="isReadOnly" type="primary" plain v-if="isShowRun" @click="runTest">
{{$t('api_test.run')}}
</el-button>
<!-- <el-button :disabled="isReadOnly" type="primary" plain v-if="isShowRun" @click="runTest">-->
<!-- {{$t('api_test.run')}}-->
<!-- </el-button>-->
<el-button :disabled="isReadOnly" type="warning" plain @click="cancel">{{$t('commons.cancel')}}
</el-button>
@ -142,6 +142,11 @@
});
},
save(callback) {
let validator = this.test.isValid();
if (!validator.isValid) {
this.$warning(this.$t(validator.info));
return;
}
this.change = false;
let url = this.create ? "/api/create" : "/api/update";
this.result = this.$request(this.getOptions(url), () => {
@ -236,7 +241,7 @@
if (param.id) {
url = '/api/schedule/update';
}
this.$post(url, param, response => {
this.$post(url, param, () => {
this.$success(this.$t('commons.save_success'));
this.getTest(this.test.id);
});
@ -250,15 +255,6 @@
}
},
computed: {
isShowRun() {
return this.test.isValid() && !this.change;
},
isDisabled() {
return !(this.test.isValid() && this.change);
}
},
created() {
this.init();
}

View File

@ -124,11 +124,23 @@ export class Test extends BaseConfig {
isValid() {
for (let i = 0; i < this.scenarioDefinition.length; i++) {
if (this.scenarioDefinition[i].isValid()) {
return this.projectId && this.name;
let validator = this.scenarioDefinition[i].isValid();
if (!validator.isValid) {
return validator;
}
}
return false;
if (!this.projectId) {
return {
isValid: false,
info: 'api_test.select_project'
}
} else if (!this.name) {
return {
isValid: false,
info: 'api_test.input_name'
}
}
return { isValid: true};
}
toJMX() {
@ -165,11 +177,12 @@ export class Scenario extends BaseConfig {
isValid() {
for (let i = 0; i < this.requests.length; i++) {
if (!this.requests[i].isValid()) {
return false;
let validator = this.requests[i].isValid();
if (!validator.isValid) {
return validator;
}
}
return true;
return {isValid: true};
}
}
@ -202,7 +215,27 @@ export class Request extends BaseConfig {
}
isValid() {
return ((!this.useEnvironment && !!this.url) || (this.useEnvironment && !!this.path && this.environment)) && !!this.method
if (this.useEnvironment){
if (!this.environment) {
return {
isValid: false,
info: 'api_test.request.please_configure_environment_in_scenario'
}
} else if (!this.path) {
return {
isValid: false,
info: 'api_test.request.input_path'
}
}
} else if (!this.url){
return {
isValid: false,
info: 'api_test.request.input_url'
}
}
return {
isValid: true
}
}
}

View File

@ -363,6 +363,8 @@ export default {
copy: "Copy request",
delete: "Delete request",
input_name: "Please enter the request name",
input_url: "Please enter the request URL",
input_path: "Please enter the request path",
name: "Name",
method: "Method",
url: "URL",

View File

@ -361,6 +361,8 @@ export default {
copy: "复制请求",
delete: "删除请求",
input_name: "请输入请求名称",
input_url: "请输入请求URL",
input_path: "请输入请求路径",
name: "请求名称",
method: "请求方法",
url: "请求URL",

View File

@ -361,6 +361,8 @@ export default {
copy: "複製請求",
delete: "删除請求",
input_name: "請輸入請求名稱",
input_url: "請輸入請求URL",
input_path: "請輸入請求路徑",
name: "請求名稱",
method: "請求方法",
url: "請求URL",