fix(测试计划): 批量执行场景用例环境列表显示错误

--bug=1008243 --user=lyh 【环境组】-测试计划中批量执行场景用例环境列表显示错误
https://www.tapd.cn/55049933/s/1078465
This commit is contained in:
shiziyuan9527 2021-12-06 17:52:10 +08:00 committed by shiziyuan9527
parent ebd0f2de8d
commit 8e0e0234b0
4 changed files with 33 additions and 24 deletions

View File

@ -2029,12 +2029,8 @@ public class ApiAutomationService {
Long nextOrder = ServiceUtils.getNextOrder(request.getPlanId(), extTestPlanScenarioCaseMapper::getLastOrder);
for (String id : set) {
Map<String, String> newEnvMap = new HashMap<>(16);
if (envMap != null && !envMap.isEmpty()) {
List<String> list = mapping.get(id);
list.forEach(l -> {
newEnvMap.put(l, envMap.get(l));
});
}
List<String> list = mapping.get(id);
list.forEach(l -> newEnvMap.put(l, envMap == null ? "" : envMap.getOrDefault(l, "")));
TestPlanApiScenario testPlanApiScenario = new TestPlanApiScenario();
testPlanApiScenario.setId(UUID.randomUUID().toString());
testPlanApiScenario.setCreateUser(SessionUtils.getUserId());
@ -2042,12 +2038,15 @@ public class ApiAutomationService {
testPlanApiScenario.setTestPlanId(request.getPlanId());
testPlanApiScenario.setCreateTime(System.currentTimeMillis());
testPlanApiScenario.setUpdateTime(System.currentTimeMillis());
String environmentJson = JSON.toJSONString(newEnvMap);
if (StringUtils.equals(envType, EnvironmentType.JSON.name())) {
testPlanApiScenario.setEnvironment(JSON.toJSONString(newEnvMap));
testPlanApiScenario.setEnvironment(environmentJson);
testPlanApiScenario.setEnvironmentType(EnvironmentType.JSON.name());
} else if (StringUtils.equals(envType, EnvironmentType.GROUP.name())) {
testPlanApiScenario.setEnvironmentType(EnvironmentType.GROUP.name());
testPlanApiScenario.setEnvironmentGroupId(envGroupId);
// JSON类型环境中也保存最新值
testPlanApiScenario.setEnvironment(environmentJson);
}
testPlanApiScenario.setOrder(nextOrder);
nextOrder += 5000;

View File

@ -1500,21 +1500,10 @@ public class TestPlanService {
for (TestPlanApiScenario testPlanApiScenario : testPlanApiScenarios) {
String env = testPlanApiScenario.getEnvironment();
String envType = testPlanApiScenario.getEnvironmentType();
String envGroupId = testPlanApiScenario.getEnvironmentGroupId();
if (StringUtils.isBlank(envType)) {
if (StringUtils.isBlank(env)) {
continue;
}
if ((StringUtils.equals(envType, EnvironmentType.JSON.name()) && StringUtils.isBlank(env))
|| StringUtils.equals(envType, EnvironmentType.GROUP.name()) && StringUtils.isBlank(envGroupId)) {
continue;
}
Map<String, String> map = new HashMap<>();
if (StringUtils.equals(envType, EnvironmentType.JSON.name())) {
map = JSON.parseObject(env, Map.class);
} else if (StringUtils.equals(envType, EnvironmentType.GROUP.name())) {
map = environmentGroupProjectService.getEnvMap(envGroupId);
}
Map<String, String> map = JSON.parseObject(env, Map.class);
if (!map.isEmpty()) {
Set<String> set = map.keySet();
for (String s : set) {

View File

@ -106,3 +106,19 @@ export function saveScenario(url, scenario, scenarioDefinition, _this, success)
export function editApiScenarioCaseOrder(request, callback) {
return basePost('/api/automation/edit/order', request, callback);
}
export function savePreciseEnvProjectIds(projectIds, envMap) {
if (envMap != null && projectIds != null) {
let keys = envMap.keys();
for (let key of keys) {
if (!projectIds.has(key)) {
envMap.delete(key);
}
}
for (let id of projectIds) {
if (!envMap.get(id)) {
envMap.set(id, "");
}
}
}
}

View File

@ -344,7 +344,7 @@ import {
} from "@/common/js/utils";
import "@/common/css/material-icons.css"
import OutsideClick from "@/common/js/outside-click";
import {saveScenario} from "@/business/components/api/automation/api-automation";
import {savePreciseEnvProjectIds, saveScenario} from "@/business/components/api/automation/api-automation";
import MsComponentConfig from "./component/ComponentConfig";
import {ENV_TYPE} from "@/common/js/constants";
@ -1315,9 +1315,9 @@ export default {
}
return new Promise((resolve) => {
document.getElementById("inputDelay").focus(); // input
this.$refs['currentScenario'].validate((valid) => {
this.$refs['currentScenario'].validate(async (valid) => {
if (valid) {
this.setParameter();
await this.setParameter();
saveScenario(this.path, this.currentScenario, this.scenarioDefinition, this, (response) => {
this.$success(this.$t('commons.save_success'));
this.$store.state.scenarioMap.delete(this.currentScenario.id);
@ -1458,7 +1458,7 @@ export default {
}
}
},
setParameter() {
async setParameter() {
this.currentScenario.stepTotal = this.scenarioDefinition.length;
if (!this.currentScenario.projectId) {
this.currentScenario.projectId = this.projectId;
@ -1483,6 +1483,11 @@ export default {
this.formatData(scenario.hashTree);
}
this.currentScenario.environmentType = this.environmentType;
let definition = JSON.parse(JSON.stringify(this.currentScenario));
definition.hashTree = this.scenarioDefinition;
await this.getEnv(JSON.stringify(definition));
//
savePreciseEnvProjectIds(this.projectIds, this.projectEnvMap);
this.currentScenario.environmentJson = JSON.stringify(strMapToObj(this.projectEnvMap));
this.currentScenario.environmentGroupId = this.envGroupId;
this.currentScenario.scenarioDefinition = scenario;