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

@ -37,16 +37,16 @@
</template> </template>
<script> <script>
import MsContainer from "../../../../common/components/MsContainer"; import MsContainer from "../../../../common/components/MsContainer";
import MsAsideContainer from "../../../../common/components/MsAsideContainer"; import MsAsideContainer from "../../../../common/components/MsAsideContainer";
import MsMainContainer from "../../../../common/components/MsMainContainer"; import MsMainContainer from "../../../../common/components/MsMainContainer";
import MsApiScenarioModule from "../ApiScenarioModule"; import MsApiScenarioModule from "../ApiScenarioModule";
import MsApiScenarioList from "../ApiScenarioList"; import MsApiScenarioList from "../ApiScenarioList";
import {getUUID} from "../../../../../../common/js/utils"; import {getUUID} from "../../../../../../common/js/utils";
import RelevanceDialog from "../../../../track/plan/view/comonents/base/RelevanceDialog"; import RelevanceDialog from "../../../../track/plan/view/comonents/base/RelevanceDialog";
import TestCaseRelevanceBase from "@/business/components/track/plan/view/comonents/base/TestCaseRelevanceBase"; import TestCaseRelevanceBase from "@/business/components/track/plan/view/comonents/base/TestCaseRelevanceBase";
export default { export default {
name: "ScenarioRelevance", name: "ScenarioRelevance",
components: { components: {
TestCaseRelevanceBase, TestCaseRelevanceBase,
@ -84,65 +84,30 @@
} }
}, },
methods: { methods: {
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,32 +125,15 @@
} }
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;
} }
},(error) => { }, (error) => {
this.buttonIsWorking = false; this.buttonIsWorking = false;
}); });
},(error) => { }, (error) => {
this.buttonIsWorking = false; this.buttonIsWorking = false;
}); });
} else { } else {
@ -196,33 +144,22 @@
} }
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;
} }
},(error) => { }, (error) => {
this.buttonIsWorking = false; this.buttonIsWorking = false;
}); });
} }
}, },
reference() {
this.getScenarioDefinition("REF")
},
copy() {
this.getScenarioDefinition("Copy")
},
close() { close() {
this.$emit('close'); this.$emit('close');
this.refresh(); this.refresh();
@ -259,7 +196,7 @@
return this.$refs.apiScenarioList.getConditions(); return this.$refs.apiScenarioList.getConditions();
}, },
} }
} }
</script> </script>
<style scoped> <style scoped>