From 72c9595a967f67a29bc2f9542eea2626c01c0b95 Mon Sep 17 00:00:00 2001 From: song-tianyang Date: Tue, 22 Feb 2022 14:06:33 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=8E=A5=E5=8F=A3=E6=A1=88=E4=BE=8B=E5=85=A8?= =?UTF-8?q?=E5=B1=8F=E4=BC=98=E5=8C=96=E9=81=97=E6=BC=8F=E7=9A=84=E9=83=A8?= =?UTF-8?q?=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1010475 --user=宋天阳 【接口测试】case全屏优化遗漏部分 https://www.tapd.cn/55049933/s/1107408 --- .../api/mock/utils/MockApiUtils.java | 148 +++++++++--------- .../components/case/ApiCaseList.vue | 15 ++ .../mock/Components/MockApiScriptEditor.vue | 14 ++ .../components/mock/MockConfigHeader.vue | 1 + .../definition/components/mock/MockTab.vue | 2 +- 5 files changed, 106 insertions(+), 74 deletions(-) diff --git a/backend/src/main/java/io/metersphere/api/mock/utils/MockApiUtils.java b/backend/src/main/java/io/metersphere/api/mock/utils/MockApiUtils.java index 90d5dfa45f..7315478908 100644 --- a/backend/src/main/java/io/metersphere/api/mock/utils/MockApiUtils.java +++ b/backend/src/main/java/io/metersphere/api/mock/utils/MockApiUtils.java @@ -235,94 +235,96 @@ public class MockApiUtils { if (StringUtils.isNotEmpty(response)) { try { JSONObject respObj = JSONObject.parseObject(response); - if (respObj.containsKey("body")) { - String returnStr = ""; - JSONObject bodyObj = respObj.getJSONObject("body"); - if (bodyObj.containsKey("type")) { - String type = bodyObj.getString("type"); - if (StringUtils.equals(type, "JSON")) { - //判断是否是JsonSchema - boolean isJsonSchema = false; - if (bodyObj.containsKey("format")) { - String foramtValue = String.valueOf(bodyObj.get("format")); - if (StringUtils.equals("JSON-SCHEMA", foramtValue)) { - isJsonSchema = true; + if(respObj != null){ + if (respObj.containsKey("body")) { + String returnStr = ""; + JSONObject bodyObj = respObj.getJSONObject("body"); + if (bodyObj.containsKey("type")) { + String type = bodyObj.getString("type"); + if (StringUtils.equals(type, "JSON")) { + //判断是否是JsonSchema + boolean isJsonSchema = false; + if (bodyObj.containsKey("format")) { + String foramtValue = String.valueOf(bodyObj.get("format")); + if (StringUtils.equals("JSON-SCHEMA", foramtValue)) { + isJsonSchema = true; + } } - } - if (isJsonSchema) { - if (bodyObj.containsKey("jsonSchema") && bodyObj.getJSONObject("jsonSchema").containsKey("properties")) { - String bodyRetunStr = bodyObj.getJSONObject("jsonSchema").getJSONObject("properties").toJSONString(); - JSONObject bodyReturnObj = JSONObject.parseObject(bodyRetunStr); - JSONObject returnObj = MockApiUtils.parseJsonSchema(bodyReturnObj); - returnStr = returnObj.toJSONString(); + if (isJsonSchema) { + if (bodyObj.containsKey("jsonSchema") && bodyObj.getJSONObject("jsonSchema").containsKey("properties")) { + String bodyRetunStr = bodyObj.getJSONObject("jsonSchema").getJSONObject("properties").toJSONString(); + JSONObject bodyReturnObj = JSONObject.parseObject(bodyRetunStr); + JSONObject returnObj = MockApiUtils.parseJsonSchema(bodyReturnObj); + returnStr = returnObj.toJSONString(); + } + } else { + if (bodyObj.containsKey("raw")) { + returnStr = bodyObj.getString("raw"); + } } - } else { + } else if (StringUtils.equalsAny(type, "XML", "Raw")) { if (bodyObj.containsKey("raw")) { - returnStr = bodyObj.getString("raw"); + String raw = bodyObj.getString("raw"); + returnStr = raw; } - } - } else if (StringUtils.equalsAny(type, "XML", "Raw")) { - if (bodyObj.containsKey("raw")) { - String raw = bodyObj.getString("raw"); - returnStr = raw; - } - } else if (StringUtils.equalsAny(type, "Form Data", "WWW_FORM")) { - Map paramMap = new LinkedHashMap<>(); - if (bodyObj.containsKey("kvs")) { - JSONArray bodyParamArr = new JSONArray(); - JSONArray kvsArr = bodyObj.getJSONArray("kvs"); - for (int i = 0; i < kvsArr.size(); i++) { - JSONObject kv = kvsArr.getJSONObject(i); - if (kv.containsKey("name")) { - String values = kv.getString("value"); - if (StringUtils.isEmpty(values)) { - values = ""; - } else { - try { - values = values.startsWith("@") ? ScriptEngineUtils.buildFunctionCallString(values) : values; - } catch (Exception e) { + } else if (StringUtils.equalsAny(type, "Form Data", "WWW_FORM")) { + Map paramMap = new LinkedHashMap<>(); + if (bodyObj.containsKey("kvs")) { + JSONArray bodyParamArr = new JSONArray(); + JSONArray kvsArr = bodyObj.getJSONArray("kvs"); + for (int i = 0; i < kvsArr.size(); i++) { + JSONObject kv = kvsArr.getJSONObject(i); + if (kv.containsKey("name")) { + String values = kv.getString("value"); + if (StringUtils.isEmpty(values)) { + values = ""; + } else { + try { + values = values.startsWith("@") ? ScriptEngineUtils.buildFunctionCallString(values) : values; + } catch (Exception e) { + } } + paramMap.put(kv.getString("name"), values); } - paramMap.put(kv.getString("name"), values); + } + } + returnStr = JSONObject.toJSONString(paramMap); + } + } + responseDTO.setReturnData(returnStr); + } + if (respObj.containsKey("statusCode")) { + JSONArray statusCodeArray = respObj.getJSONArray("statusCode"); + int code = 200; + if (statusCodeArray != null) { + for (int i = 0; i < statusCodeArray.size(); i++) { + JSONObject object = statusCodeArray.getJSONObject(i); + if (object.containsKey("name")) { + try { + code = Integer.parseInt(object.getString("name")); + break; + } catch (Exception e) { + LogUtil.error(e); } } } - returnStr = JSONObject.toJSONString(paramMap); } + responseDTO.setReturnCode(code); } - responseDTO.setReturnData(returnStr); - } - if (respObj.containsKey("statusCode")) { - JSONArray statusCodeArray = respObj.getJSONArray("statusCode"); - int code = 200; - if (statusCodeArray != null) { - for (int i = 0; i < statusCodeArray.size(); i++) { - JSONObject object = statusCodeArray.getJSONObject(i); - if (object.containsKey("name")) { - try { - code = Integer.parseInt(object.getString("name")); - break; - } catch (Exception e) { - LogUtil.error(e); + if(respObj.containsKey("headers")){ + JSONArray jsonArray = respObj.getJSONArray("headers"); + Map headMap = new HashMap<>(); + for(int i = 0; i < jsonArray.size(); i ++){ + JSONObject headObj = jsonArray.getJSONObject(i); + if(headObj.containsKey("name") && headObj.containsKey("value") && headObj.containsKey("enable")){ + boolean enable = headObj.getBoolean("enable"); + if(enable){ + headMap.put(headObj.getString("name"),headObj.getString("value")); } } } + responseDTO.setHeaders(headMap); } - responseDTO.setReturnCode(code); - } - if(respObj.containsKey("headers")){ - JSONArray jsonArray = respObj.getJSONArray("headers"); - Map headMap = new HashMap<>(); - for(int i = 0; i < jsonArray.size(); i ++){ - JSONObject headObj = jsonArray.getJSONObject(i); - if(headObj.containsKey("name") && headObj.containsKey("value") && headObj.containsKey("enable")){ - boolean enable = headObj.getBoolean("enable"); - if(enable){ - headMap.put(headObj.getString("name"),headObj.getString("value")); - } - } - } - responseDTO.setHeaders(headMap); } } catch (Exception e) { MSException.throwException(e); diff --git a/frontend/src/business/components/api/definition/components/case/ApiCaseList.vue b/frontend/src/business/components/api/definition/components/case/ApiCaseList.vue index 851c91fe38..31e8694336 100644 --- a/frontend/src/business/components/api/definition/components/case/ApiCaseList.vue +++ b/frontend/src/business/components/api/definition/components/case/ApiCaseList.vue @@ -140,6 +140,11 @@ export default { this.getApiTest(true); this.visible = true; this.$store.state.currentApiCase = undefined; + + //默认最大化 + this.$nextTick(() => { + this.$refs.testCaseDrawer.setfullScreen(); + }); }, add(api) { this.api = api; @@ -169,6 +174,11 @@ export default { this.condition = {components: API_CASE_CONFIGS}; this.sysAddition(apiCase); this.visible = true; + + //默认最大化 + this.$nextTick(() => { + this.$refs.testCaseDrawer.setfullScreen(); + }); }, runTestCase(api, testCaseId) { if (api && testCaseId) { @@ -195,6 +205,11 @@ export default { this.api = api; this.currentApi = api; this.addCase(); + + //默认最大化 + this.$nextTick(() => { + this.$refs.testCaseDrawer.setfullScreen(); + }); }, setEnvironment(environment) { this.environment = environment; diff --git a/frontend/src/business/components/api/definition/components/mock/Components/MockApiScriptEditor.vue b/frontend/src/business/components/api/definition/components/mock/Components/MockApiScriptEditor.vue index f1ac3e428e..6b9d3b7b50 100644 --- a/frontend/src/business/components/api/definition/components/mock/Components/MockApiScriptEditor.vue +++ b/frontend/src/business/components/api/definition/components/mock/Components/MockApiScriptEditor.vue @@ -34,6 +34,7 @@ import MsDropdown from "@/business/components/common/components/MsDropdown"; import CustomFunctionRelate from "@/business/components/project/menu/function/CustomFunctionRelate"; import ApiFuncRelevance from "@/business/components/project/menu/function/ApiFuncRelevance"; import MockScriptNavMenu from "@/business/components/api/definition/components/mock/Components/MockScriptNavMenu"; +import i18n from "@/i18n/i18n"; export default { name: "MockApiScriptEditor", @@ -112,6 +113,19 @@ export default { ] }, + { + title: i18n.t('project.code_segment.custom_value'), + children: [ + { + title: i18n.t('api_test.request.processor.code_template_get_variable'), + value: 'vars.get("variable_name");', + }, + { + title: i18n.t('api_test.request.processor.code_template_set_variable'), + value: 'vars.put("variable_name", "variable_value");', + }, + ] + }, { title: this.$t('project.code_segment.code_segment'), children: [ diff --git a/frontend/src/business/components/api/definition/components/mock/MockConfigHeader.vue b/frontend/src/business/components/api/definition/components/mock/MockConfigHeader.vue index c87d715eb1..672c1c5df9 100644 --- a/frontend/src/business/components/api/definition/components/mock/MockConfigHeader.vue +++ b/frontend/src/business/components/api/definition/components/mock/MockConfigHeader.vue @@ -3,6 +3,7 @@ + * {{ $t('commons.name') }} diff --git a/frontend/src/business/components/api/definition/components/mock/MockTab.vue b/frontend/src/business/components/api/definition/components/mock/MockTab.vue index d7b8595cbb..e89356d775 100644 --- a/frontend/src/business/components/api/definition/components/mock/MockTab.vue +++ b/frontend/src/business/components/api/definition/components/mock/MockTab.vue @@ -20,7 +20,7 @@ :screen-height="screenHeight" @row-click="clickRow" row-key="id" - operator-width="120px" + operator-width="170px" ref="table" >