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

View File

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

View File

@ -106,3 +106,19 @@ export function saveScenario(url, scenario, scenarioDefinition, _this, success)
export function editApiScenarioCaseOrder(request, callback) { export function editApiScenarioCaseOrder(request, callback) {
return basePost('/api/automation/edit/order', 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"; } from "@/common/js/utils";
import "@/common/css/material-icons.css" import "@/common/css/material-icons.css"
import OutsideClick from "@/common/js/outside-click"; 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 MsComponentConfig from "./component/ComponentConfig";
import {ENV_TYPE} from "@/common/js/constants"; import {ENV_TYPE} from "@/common/js/constants";
@ -1315,9 +1315,9 @@ export default {
} }
return new Promise((resolve) => { return new Promise((resolve) => {
document.getElementById("inputDelay").focus(); // input document.getElementById("inputDelay").focus(); // input
this.$refs['currentScenario'].validate((valid) => { this.$refs['currentScenario'].validate(async (valid) => {
if (valid) { if (valid) {
this.setParameter(); await this.setParameter();
saveScenario(this.path, this.currentScenario, this.scenarioDefinition, this, (response) => { saveScenario(this.path, this.currentScenario, this.scenarioDefinition, this, (response) => {
this.$success(this.$t('commons.save_success')); this.$success(this.$t('commons.save_success'));
this.$store.state.scenarioMap.delete(this.currentScenario.id); this.$store.state.scenarioMap.delete(this.currentScenario.id);
@ -1458,7 +1458,7 @@ export default {
} }
} }
}, },
setParameter() { async setParameter() {
this.currentScenario.stepTotal = this.scenarioDefinition.length; this.currentScenario.stepTotal = this.scenarioDefinition.length;
if (!this.currentScenario.projectId) { if (!this.currentScenario.projectId) {
this.currentScenario.projectId = this.projectId; this.currentScenario.projectId = this.projectId;
@ -1483,6 +1483,11 @@ export default {
this.formatData(scenario.hashTree); this.formatData(scenario.hashTree);
} }
this.currentScenario.environmentType = this.environmentType; 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.environmentJson = JSON.stringify(strMapToObj(this.projectEnvMap));
this.currentScenario.environmentGroupId = this.envGroupId; this.currentScenario.environmentGroupId = this.envGroupId;
this.currentScenario.scenarioDefinition = scenario; this.currentScenario.scenarioDefinition = scenario;