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