refactor(接口测试): 场景步骤过多时增加提示

https://www.tapd.cn/55049933/bugtrace/bugs/view/1155049933001025954
Signed-off-by: fit2-zhao <yong.zhao@fit2cloud.com>
This commit is contained in:
fit2-zhao 2023-05-06 11:41:57 +08:00 committed by fit2-zhao
parent 98dbd3437e
commit 069b420f29
11 changed files with 134 additions and 61 deletions

View File

@ -9,4 +9,7 @@ public interface ExtApiScenarioReferenceIdMapper {
List<ApiScenarioReferenceId> selectUrlByProjectId(@Param("projectId") String projectId, @Param("versionId") String versionId);
List<ApiScenarioReferenceId> selectReferenceIdByIds(List<String> ids);
int selectByScenarioIds(List<String> ids);
}

View File

@ -28,5 +28,16 @@
and api_scenario.status != 'Trash' and api_scenario_reference_id.reference_type = 'REF'
</where>
</select>
<select id="selectByScenarioIds" resultType="java.lang.Integer">
SELECT
count(*)
FROM
api_scenario_reference_id
WHERE
api_scenario_id IN
<foreach collection="ids" item="id" open="(" separator="," close=")">
#{id}
</foreach>
</select>
</mapper>

View File

@ -209,6 +209,11 @@ public class ApiScenarioController {
return apiAutomationService.getScenarioDetail(ids);
}
@PostMapping("/get-scenario-step")
public int getScenarioStep(@RequestBody List<String> ids) {
return apiAutomationService.getScenarioStep(ids);
}
@PostMapping(value = "/run/debug")
@MsAuditLog(module = OperLogModule.API_AUTOMATION, type = OperLogConstants.DEBUG, title = "#request.scenarioName", sourceId = "#request.scenarioId", project = "#request.projectId")
public String runDebug(@RequestPart("request") RunDefinitionRequest request, @RequestPart(value = "bodyFiles", required = false) List<MultipartFile> bodyFiles, @RequestPart(value = "scenarioFiles", required = false) List<MultipartFile> scenarioFiles) {

View File

@ -365,6 +365,9 @@ public class MsHashTreeService {
public void caseFormatting(JSONObject element, List<String> caseIds, ParameterConfig msParameter) {
List<ApiTestCaseInfo> caseInfos = apiTestCaseService.selectByCaseIds(caseIds);
if(CollectionUtils.isEmpty(caseInfos)){
return;
}
Map<String, ApiTestCaseInfo> caseMap = caseInfos.stream()
.collect(Collectors.toMap(ApiTestCase::getId, a -> a, (k1, k2) -> k1));
if (element != null && ElementConstants.REQUESTS.contains(element.optString(TYPE))) {

View File

@ -841,6 +841,9 @@ public class ApiScenarioService {
}
}
public int getScenarioStep(List<String> ids) {
return extApiScenarioReferenceIdMapper.selectByScenarioIds(ids);
}
public List<ApiScenarioDTO> getScenarioDetail(List<String> ids) {
if (CollectionUtils.isEmpty(ids)) {
return new ArrayList<>();

View File

@ -67,6 +67,10 @@ export function getApiScenarios(params) {
return post('/api/automation/get-scenario-list', params);
}
export function getApiScenarioStep(params) {
return post('/api/automation/get-scenario-step', params);
}
export function genPerformanceTestJmx(params) {
return post('/api/automation/gen-jmx', params);
}

View File

@ -91,6 +91,7 @@ import RelevanceDialog from '@/business/commons/RelevanceDialog';
import TestCaseRelevanceBase from '@/business/commons/TestCaseRelevanceBase';
import { hasLicense } from 'metersphere-frontend/src/utils/permission';
import TableSelectCountBar from '@/business/automation/scenario/api/TableSelectCountBar';
import { operationConfirm } from 'metersphere-frontend/src/utils';
export default {
name: 'ApiRelevance',
@ -156,38 +157,56 @@ export default {
api.projectId = this.projectId;
});
let params = this.$refs.apiList.getConditions();
this.result = apiListBatch(params).then(
(response) => {
let apis = response.data;
if (apis.length === 0) {
this.$warning('请选择接口');
this.buttonIsWorking = false;
this.result = apiListBatch(params).then((response) => {
let apis = response.data;
if (apis.length === 0) {
this.$warning(this.$t('automation.case_message'));
this.buttonIsWorking = false;
} else {
if (apis.length > 500) {
operationConfirm(
this,
this.$t('automation.scenario_step_ref_message', [apis.length]) + '',
() => {
this.$emit('save', apis, 'API', reference);
this.$refs.baseRelevance.close();
},
() => {
this.buttonIsWorking = false;
}
);
} else {
this.$emit('save', apis, 'API', reference);
this.$refs.baseRelevance.close();
}
},
(error) => {
this.buttonIsWorking = false;
}
);
});
} else {
let params = this.$refs.apiCaseList.getConditions();
this.result = getApiCaseWithBLOBs(params).then(
(response) => {
let apiCases = response.data;
if (apiCases.length === 0) {
this.$warning('请选择案例');
this.buttonIsWorking = false;
this.result = getApiCaseWithBLOBs(params).then((response) => {
let apiCases = response.data;
if (apiCases.length === 0) {
this.$warning(this.$t('automation.case_message'));
this.buttonIsWorking = false;
} else {
if (apiCases.length > 500) {
operationConfirm(
this,
this.$t('automation.scenario_step_ref_message', [apiCases.length]) + '',
() => {
this.$emit('save', apiCases, 'CASE', reference);
this.$refs.baseRelevance.close();
},
() => {
this.buttonIsWorking = false;
}
);
} else {
this.$emit('save', apiCases, 'CASE', reference);
this.$refs.baseRelevance.close();
}
},
(error) => {
this.buttonIsWorking = false;
}
);
});
}
},
close() {

View File

@ -43,19 +43,18 @@
<script>
import { getProjectVersions, versionEnableByProjectId } from '@/api/xpack';
import { apiScenarioAll, getApiScenarios } from '@/api/scenario';
import { apiScenarioAll, getApiScenarios, getApiScenarioStep } from '@/api/scenario';
import MsContainer from 'metersphere-frontend/src/components/MsContainer';
import MsAsideContainer from 'metersphere-frontend/src/components/MsAsideContainer';
import MsMainContainer from 'metersphere-frontend/src/components/MsMainContainer';
import MsApiScenarioModule from '../ApiScenarioModule';
import { getUUID } from 'metersphere-frontend/src/utils';
import { getUUID, operationConfirm } from 'metersphere-frontend/src/utils';
import { hasLicense } from 'metersphere-frontend/src/utils/permission';
import RelevanceDialog from '@/business/commons/RelevanceDialog';
import RelevanceScenarioList from './RelevanceScenarioList';
import TestCaseRelevanceBase from '../../../commons/TestCaseRelevanceBase';
import TableSelectCountBar from '@/business/automation/scenario/api/TableSelectCountBar';
import { getProjectConfig } from '@/api/project';
export default {
name: 'ScenarioRelevance',
props: {
@ -161,53 +160,69 @@ export default {
let params = {};
params.ids = this.currentScenarioIds;
params.condition = conditions;
apiScenarioAll(params).then(
(response) => {
this.currentScenarioIds = response.data;
if (!this.currentScenarioIds || this.currentScenarioIds.length < 1) {
this.$warning('请选择场景');
this.buttonIsWorking = false;
return;
}
this.result = getApiScenarios(this.currentScenarioIds).then(
(response) => {
if (response.data) {
this.createScenarioDefinition(scenarios, response.data, referenced);
this.$emit('save', scenarios);
this.$refs.baseRelevance.close();
apiScenarioAll(params).then((response) => {
this.currentScenarioIds = response.data;
if (!this.currentScenarioIds || this.currentScenarioIds.length < 1) {
this.$warning(this.$t('automation.scenario_message'));
this.buttonIsWorking = false;
return;
}
getApiScenarioStep(this.currentScenarioIds).then((response) => {
if (response.data > 500) {
operationConfirm(
this,
this.$t('automation.scenario_step_ref_message', [response.data]) + '',
() => {
this.pushApiScenario(scenarios, referenced);
},
() => {
this.buttonIsWorking = false;
}
},
(error) => {
this.buttonIsWorking = false;
}
);
},
(error) => {
this.buttonIsWorking = false;
}
);
);
} else {
this.pushApiScenario(scenarios, referenced);
}
});
});
} else {
if (!this.currentScenarioIds || this.currentScenarioIds.length < 1) {
this.$warning('请选择场景');
this.$warning(this.$t('automation.scenario_message'));
this.buttonIsWorking = false;
return;
}
this.result = getApiScenarios(this.currentScenarioIds).then(
(response) => {
if (response.data) {
this.currentScenarioIds = [];
this.createScenarioDefinition(scenarios, response.data, referenced);
this.$emit('save', scenarios);
this.$refs.baseRelevance.close();
this.buttonIsWorking = false;
}
},
(error) => {
getApiScenarioStep(this.currentScenarioIds).then((response) => {
if (response.data > 500) {
operationConfirm(
this,
this.$t('automation.scenario_step_ref_message', [response.data]) + '',
() => {
this.pushApiScenario(scenarios, referenced);
},
() => {
this.buttonIsWorking = false;
}
);
} else {
this.pushApiScenario(scenarios, referenced);
}
});
}
},
pushApiScenario(scenarios, referenced) {
this.result = getApiScenarios(this.currentScenarioIds).then(
(response) => {
if (response.data) {
this.currentScenarioIds = [];
this.createScenarioDefinition(scenarios, response.data, referenced);
this.$emit('save', scenarios);
this.$refs.baseRelevance.close();
this.buttonIsWorking = false;
}
);
}
},
() => {
this.buttonIsWorking = false;
}
);
},
reference() {
this.getScenarioDefinition('REF');

View File

@ -130,6 +130,10 @@ const message = {
automation: {
project_no_permission: 'The current person does not have the operation permission for this step',
document_validity_msg: 'The file has been modified, please re-upload',
scenario_step_ref_message:
'The current number of selection requests [{0}] may cause page loading exceptions, whether to continue?',
case_message: 'Please select a case',
scenario_message: 'Please select a scene',
},
};
export default {

View File

@ -126,6 +126,9 @@ const message = {
automation: {
project_no_permission: '当前操作人无此步骤的操作权限',
document_validity_msg: '文件已经被修改,请重新上传',
scenario_step_ref_message: '当前选择请求数 [{0}] 个可能导致页面加载异常,是否继续',
case_message: '请选择案例',
scenario_message: '请选择场景',
},
};

View File

@ -126,6 +126,9 @@ const message = {
automation: {
project_no_permission: '當前人操作無此步驟的操作權限',
document_validity_msg: '文件已經被修改,請重新上傳',
scenario_step_ref_message: '當前選擇請求數 [{0}] 个可能導致頁面加載異常,是否繼續',
case_message: '請選擇案例',
scenario_message: '請選擇場景',
},
};