refactor(接口测试): 优化引用场景代码

This commit is contained in:
fit2-zhao 2022-01-14 15:33:05 +08:00 committed by fit2-zhao
parent ea5caf0ec8
commit e94873c09d
1 changed files with 142 additions and 205 deletions

View File

@ -87,62 +87,27 @@
changeButtonLoadingType() { changeButtonLoadingType() {
this.buttonIsWorking = false; this.buttonIsWorking = false;
}, },
reference() { createScenarioDefinition(scenarios, data, referenced) {
this.buttonIsWorking = true; data.forEach(item => {
let scenarios = []; let scenarioDefinition = JSON.parse(item.scenarioDefinition);
let conditions = this.getConditions(); if (scenarioDefinition && scenarioDefinition.hashTree) {
if (conditions.selectAll) {
let params = {};
params.ids = this.currentScenarioIds;
params.condition = conditions;
let url = "/api/automation/list/all/";
this.result = this.$post(url, params, (response) => {
this.currentScenario = response.data;
if (!this.currentScenario || this.currentScenario.length < 1) {
this.$emit('请选择场景');
this.buttonIsWorking = false;
return;
}
this.currentScenario.forEach(item => {
let obj = { let obj = {
id: item.id, id: item.id,
name: item.name, name: item.name,
type: "scenario", type: "scenario",
referenced: 'REF', headers: scenarioDefinition.headers,
variables: scenarioDefinition.variables,
environmentMap: scenarioDefinition.environmentMap,
referenced: referenced,
resourceId: getUUID(), resourceId: getUUID(),
hashTree: scenarioDefinition.hashTree,
projectId: item.projectId projectId: item.projectId
}; };
scenarios.push(obj); scenarios.push(obj);
});
this.$emit('save', scenarios);
this.$refs.baseRelevance.close();
this.buttonIsWorking = false;
},(error) => {
this.buttonIsWorking = false;
});
} else {
if (!this.currentScenario || this.currentScenario.length < 1) {
this.$emit('请选择场景');
this.buttonIsWorking = false;
return;
} }
this.currentScenario.forEach(item => {
let obj = {
id: item.id,
name: item.name,
type: "scenario",
referenced: 'REF',
resourceId: getUUID(),
projectId: item.projectId
};
scenarios.push(obj);
}); });
this.$emit('save', scenarios);
this.$refs.baseRelevance.close();
this.buttonIsWorking = false;
}
}, },
copy() { getScenarioDefinition(referenced) {
this.buttonIsWorking = true; this.buttonIsWorking = true;
let scenarios = []; let scenarios = [];
let conditions = this.getConditions(); let conditions = this.getConditions();
@ -160,24 +125,7 @@
} }
this.result = this.$post("/api/automation/getApiScenarios/", this.currentScenarioIds, response => { this.result = this.$post("/api/automation/getApiScenarios/", this.currentScenarioIds, response => {
if (response.data) { if (response.data) {
response.data.forEach(item => { this.createScenarioDefinition(scenarios, response.data, referenced);
let scenarioDefinition = JSON.parse(item.scenarioDefinition);
if (scenarioDefinition && scenarioDefinition.hashTree) {
let obj = {
id: item.id,
name: item.name,
type: "scenario",
headers: scenarioDefinition.headers,
variables: scenarioDefinition.variables,
environmentMap: scenarioDefinition.environmentMap,
referenced: 'Copy',
resourceId: getUUID(),
hashTree: scenarioDefinition.hashTree,
projectId: item.projectId
};
scenarios.push(obj);
}
});
this.$emit('save', scenarios); this.$emit('save', scenarios);
this.$refs.baseRelevance.close(); this.$refs.baseRelevance.close();
this.buttonIsWorking = false; this.buttonIsWorking = false;
@ -196,24 +144,7 @@
} }
this.result = this.$post("/api/automation/getApiScenarios/", this.currentScenarioIds, response => { this.result = this.$post("/api/automation/getApiScenarios/", this.currentScenarioIds, response => {
if (response.data) { if (response.data) {
response.data.forEach(item => { this.createScenarioDefinition(scenarios, response.data, referenced);
let scenarioDefinition = JSON.parse(item.scenarioDefinition);
if (scenarioDefinition && scenarioDefinition.hashTree) {
let obj = {
id: item.id,
name: item.name,
type: "scenario",
headers: scenarioDefinition.headers,
variables: scenarioDefinition.variables,
environmentMap: scenarioDefinition.environmentMap,
referenced: 'Copy',
resourceId: getUUID(),
hashTree: scenarioDefinition.hashTree,
projectId: item.projectId
};
scenarios.push(obj);
}
});
this.$emit('save', scenarios); this.$emit('save', scenarios);
this.$refs.baseRelevance.close(); this.$refs.baseRelevance.close();
this.buttonIsWorking = false; this.buttonIsWorking = false;
@ -223,6 +154,12 @@
}); });
} }
}, },
reference() {
this.getScenarioDefinition("REF")
},
copy() {
this.getScenarioDefinition("Copy")
},
close() { close() {
this.$emit('close'); this.$emit('close');
this.refresh(); this.refresh();