refactor(接口测试): 优化引用场景代码
This commit is contained in:
parent
ea5caf0ec8
commit
e94873c09d
|
@ -37,158 +37,87 @@
|
|||
</template>
|
||||
|
||||
<script>
|
||||
import MsContainer from "../../../../common/components/MsContainer";
|
||||
import MsAsideContainer from "../../../../common/components/MsAsideContainer";
|
||||
import MsMainContainer from "../../../../common/components/MsMainContainer";
|
||||
import MsApiScenarioModule from "../ApiScenarioModule";
|
||||
import MsApiScenarioList from "../ApiScenarioList";
|
||||
import {getUUID} from "../../../../../../common/js/utils";
|
||||
import RelevanceDialog from "../../../../track/plan/view/comonents/base/RelevanceDialog";
|
||||
import TestCaseRelevanceBase from "@/business/components/track/plan/view/comonents/base/TestCaseRelevanceBase";
|
||||
import MsContainer from "../../../../common/components/MsContainer";
|
||||
import MsAsideContainer from "../../../../common/components/MsAsideContainer";
|
||||
import MsMainContainer from "../../../../common/components/MsMainContainer";
|
||||
import MsApiScenarioModule from "../ApiScenarioModule";
|
||||
import MsApiScenarioList from "../ApiScenarioList";
|
||||
import {getUUID} from "../../../../../../common/js/utils";
|
||||
import RelevanceDialog from "../../../../track/plan/view/comonents/base/RelevanceDialog";
|
||||
import TestCaseRelevanceBase from "@/business/components/track/plan/view/comonents/base/TestCaseRelevanceBase";
|
||||
|
||||
export default {
|
||||
name: "ScenarioRelevance",
|
||||
components: {
|
||||
TestCaseRelevanceBase,
|
||||
RelevanceDialog,
|
||||
MsApiScenarioList,
|
||||
MsApiScenarioModule,
|
||||
MsMainContainer, MsAsideContainer, MsContainer
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
buttonIsWorking: false,
|
||||
result: {},
|
||||
currentProtocol: null,
|
||||
selectNodeIds: [],
|
||||
moduleOptions: {},
|
||||
isApiListEnable: true,
|
||||
currentScenario: [],
|
||||
currentScenarioIds: [],
|
||||
projectId: '',
|
||||
customNum: false
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
projectId(val) {
|
||||
this.$refs.nodeTree.list(this.projectId);
|
||||
if (val) {
|
||||
this.$get("/project/get/" + val, result => {
|
||||
let data = result.data;
|
||||
if (data) {
|
||||
this.customNum = data.scenarioCustomNum;
|
||||
}
|
||||
});
|
||||
}
|
||||
this.$refs.apiScenarioList.search(this.projectId);
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
changeButtonLoadingType(){
|
||||
this.buttonIsWorking = false;
|
||||
},
|
||||
reference() {
|
||||
this.buttonIsWorking = true;
|
||||
let scenarios = [];
|
||||
let conditions = this.getConditions();
|
||||
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 = {
|
||||
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;
|
||||
},(error) => {
|
||||
this.buttonIsWorking = false;
|
||||
});
|
||||
} else {
|
||||
if (!this.currentScenario || this.currentScenario.length < 1) {
|
||||
this.$emit('请选择场景');
|
||||
this.buttonIsWorking = false;
|
||||
return;
|
||||
export default {
|
||||
name: "ScenarioRelevance",
|
||||
components: {
|
||||
TestCaseRelevanceBase,
|
||||
RelevanceDialog,
|
||||
MsApiScenarioList,
|
||||
MsApiScenarioModule,
|
||||
MsMainContainer, MsAsideContainer, MsContainer
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
buttonIsWorking: false,
|
||||
result: {},
|
||||
currentProtocol: null,
|
||||
selectNodeIds: [],
|
||||
moduleOptions: {},
|
||||
isApiListEnable: true,
|
||||
currentScenario: [],
|
||||
currentScenarioIds: [],
|
||||
projectId: '',
|
||||
customNum: false
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
projectId(val) {
|
||||
this.$refs.nodeTree.list(this.projectId);
|
||||
if (val) {
|
||||
this.$get("/project/get/" + val, result => {
|
||||
let data = result.data;
|
||||
if (data) {
|
||||
this.customNum = data.scenarioCustomNum;
|
||||
}
|
||||
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;
|
||||
});
|
||||
}
|
||||
this.$refs.apiScenarioList.search(this.projectId);
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
changeButtonLoadingType() {
|
||||
this.buttonIsWorking = false;
|
||||
},
|
||||
createScenarioDefinition(scenarios, data, referenced) {
|
||||
data.forEach(item => {
|
||||
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: referenced,
|
||||
resourceId: getUUID(),
|
||||
hashTree: scenarioDefinition.hashTree,
|
||||
projectId: item.projectId
|
||||
};
|
||||
scenarios.push(obj);
|
||||
}
|
||||
},
|
||||
copy() {
|
||||
this.buttonIsWorking = true;
|
||||
let scenarios = [];
|
||||
let conditions = this.getConditions();
|
||||
if (conditions.selectAll) {
|
||||
let url = "/api/automation/id/all/";
|
||||
let params = {};
|
||||
params.ids = this.currentScenarioIds;
|
||||
params.condition = conditions;
|
||||
this.result = this.$post(url, params, (response) => {
|
||||
this.currentScenarioIds = response.data;
|
||||
if (!this.currentScenarioIds || this.currentScenarioIds.length < 1) {
|
||||
this.$warning('请选择场景');
|
||||
this.buttonIsWorking = false;
|
||||
return;
|
||||
}
|
||||
this.result = this.$post("/api/automation/getApiScenarios/", this.currentScenarioIds, response => {
|
||||
if (response.data) {
|
||||
response.data.forEach(item => {
|
||||
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.$refs.baseRelevance.close();
|
||||
this.buttonIsWorking = false;
|
||||
}
|
||||
},(error) => {
|
||||
this.buttonIsWorking = false;
|
||||
});
|
||||
},(error) => {
|
||||
this.buttonIsWorking = false;
|
||||
});
|
||||
} else {
|
||||
});
|
||||
},
|
||||
getScenarioDefinition(referenced) {
|
||||
this.buttonIsWorking = true;
|
||||
let scenarios = [];
|
||||
let conditions = this.getConditions();
|
||||
if (conditions.selectAll) {
|
||||
let url = "/api/automation/id/all/";
|
||||
let params = {};
|
||||
params.ids = this.currentScenarioIds;
|
||||
params.condition = conditions;
|
||||
this.result = this.$post(url, params, (response) => {
|
||||
this.currentScenarioIds = response.data;
|
||||
if (!this.currentScenarioIds || this.currentScenarioIds.length < 1) {
|
||||
this.$warning('请选择场景');
|
||||
this.buttonIsWorking = false;
|
||||
|
@ -196,70 +125,78 @@
|
|||
}
|
||||
this.result = this.$post("/api/automation/getApiScenarios/", this.currentScenarioIds, response => {
|
||||
if (response.data) {
|
||||
response.data.forEach(item => {
|
||||
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.createScenarioDefinition(scenarios, response.data, referenced);
|
||||
this.$emit('save', scenarios);
|
||||
this.$refs.baseRelevance.close();
|
||||
this.buttonIsWorking = false;
|
||||
}
|
||||
},(error) => {
|
||||
}, (error) => {
|
||||
this.buttonIsWorking = false;
|
||||
});
|
||||
}, (error) => {
|
||||
this.buttonIsWorking = false;
|
||||
});
|
||||
} else {
|
||||
if (!this.currentScenarioIds || this.currentScenarioIds.length < 1) {
|
||||
this.$warning('请选择场景');
|
||||
this.buttonIsWorking = false;
|
||||
return;
|
||||
}
|
||||
},
|
||||
close() {
|
||||
this.$emit('close');
|
||||
this.refresh();
|
||||
this.$refs.relevanceDialog.close();
|
||||
},
|
||||
open() {
|
||||
this.buttonIsWorking = false;
|
||||
this.$refs.baseRelevance.open();
|
||||
if (this.$refs.apiScenarioList) {
|
||||
this.$refs.apiScenarioList.search(this.projectId);
|
||||
}
|
||||
},
|
||||
nodeChange(node, nodeIds, pNodes) {
|
||||
this.selectNodeIds = nodeIds;
|
||||
},
|
||||
handleProtocolChange(protocol) {
|
||||
this.currentProtocol = protocol;
|
||||
},
|
||||
setModuleOptions(data) {
|
||||
this.moduleOptions = data;
|
||||
},
|
||||
refresh() {
|
||||
this.$refs.apiScenarioList.search();
|
||||
},
|
||||
setData(data) {
|
||||
this.currentScenario = Array.from(data).map(row => row);
|
||||
this.currentScenarioIds = Array.from(data).map(row => row.id);
|
||||
},
|
||||
setProject(projectId) {
|
||||
this.projectId = projectId;
|
||||
this.selectNodeIds = [];
|
||||
},
|
||||
getConditions() {
|
||||
return this.$refs.apiScenarioList.getConditions();
|
||||
},
|
||||
}
|
||||
this.result = this.$post("/api/automation/getApiScenarios/", this.currentScenarioIds, response => {
|
||||
if (response.data) {
|
||||
this.createScenarioDefinition(scenarios, response.data, referenced);
|
||||
this.$emit('save', scenarios);
|
||||
this.$refs.baseRelevance.close();
|
||||
this.buttonIsWorking = false;
|
||||
}
|
||||
}, (error) => {
|
||||
this.buttonIsWorking = false;
|
||||
});
|
||||
}
|
||||
},
|
||||
reference() {
|
||||
this.getScenarioDefinition("REF")
|
||||
},
|
||||
copy() {
|
||||
this.getScenarioDefinition("Copy")
|
||||
},
|
||||
close() {
|
||||
this.$emit('close');
|
||||
this.refresh();
|
||||
this.$refs.relevanceDialog.close();
|
||||
},
|
||||
open() {
|
||||
this.buttonIsWorking = false;
|
||||
this.$refs.baseRelevance.open();
|
||||
if (this.$refs.apiScenarioList) {
|
||||
this.$refs.apiScenarioList.search(this.projectId);
|
||||
}
|
||||
},
|
||||
nodeChange(node, nodeIds, pNodes) {
|
||||
this.selectNodeIds = nodeIds;
|
||||
},
|
||||
handleProtocolChange(protocol) {
|
||||
this.currentProtocol = protocol;
|
||||
},
|
||||
setModuleOptions(data) {
|
||||
this.moduleOptions = data;
|
||||
},
|
||||
refresh() {
|
||||
this.$refs.apiScenarioList.search();
|
||||
},
|
||||
setData(data) {
|
||||
this.currentScenario = Array.from(data).map(row => row);
|
||||
this.currentScenarioIds = Array.from(data).map(row => row.id);
|
||||
},
|
||||
setProject(projectId) {
|
||||
this.projectId = projectId;
|
||||
this.selectNodeIds = [];
|
||||
},
|
||||
getConditions() {
|
||||
return this.$refs.apiScenarioList.getConditions();
|
||||
},
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
|
Loading…
Reference in New Issue