-
- {{ index + 1 }}
- {{ item.name }}
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+ {{ index + 1 }}
+ {{ item.name }}
+
+
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -133,11 +148,50 @@
const valueKey = computed(() => {
return activeKey.value && assertions.value.find((item) => item.id === activeKey.value)?.assertionType;
});
+ const defaultResBodyItem = {
+ jsonPathAssertion: {
+ assertions: [],
+ },
+ xpathAssertion: { responseFormat: 'XML', assertions: [] },
+ assertionBodyType: '',
+ regexAssertion: {
+ assertions: [],
+ },
+ // TODO文档暂时不做
+ // documentAssertion: {
+ // jsonAssertion: [
+ // {
+ // id: rootId,
+ // paramsName: 'root',
+ // mustInclude: false,
+ // typeChecking: false,
+ // paramType: 'object',
+ // matchCondition: '',
+ // matchValue: '',
+ // },
+ // ],
+ // responseFormat: 'JSON',
+ // followApi: false,
+ // },
+ };
// 计算当前页面的存储的状态
const getCurrentItemState = computed({
get: () => {
- return assertions.value.find((item) => item.id === activeKey.value);
+ const currentResItem =
+ assertions.value.find((item: any) => item.id === activeKey.value) || assertions.value[0] || {};
+ if (currentResItem && currentResItem?.assertionType === ResponseAssertionType.RESPONSE_BODY) {
+ const { jsonPathAssertion, xpathAssertion, regexAssertion } = currentResItem;
+ return {
+ ...currentResItem,
+ jsonPathAssertion: jsonPathAssertion || defaultResBodyItem.jsonPathAssertion,
+ xpathAssertion: xpathAssertion || defaultResBodyItem.xpathAssertion,
+ assertionBodyType: '',
+ regexAssertion: regexAssertion || defaultResBodyItem.regexAssertion,
+ bodyAssertionDataByType: {},
+ };
+ }
+ return currentResItem;
},
set: (val: ExecuteAssertion) => {
const currentIndex = assertions.value.findIndex((item) => item.id === activeKey.value);
@@ -223,11 +277,12 @@
assertions: [],
},
xpathAssertion: {
+ responseFormat: 'XML',
assertions: [],
},
- regexAssertion: {
- assertions: [],
- },
+ // regexAssertion: {
+ // assertions: [],
+ // },
bodyAssertionDataByType: {},
});
break;
@@ -284,6 +339,7 @@
getCurrentItemState.value = { ...val };
break;
case ResponseAssertionType.RESPONSE_BODY:
+ getCurrentItemState.value = { ...val };
break;
case ResponseAssertionType.RESPONSE_TIME:
getCurrentItemState.value = { ...val };
@@ -300,7 +356,9 @@
};
watchEffect(() => {
- console.log(getCurrentItemState.value);
+ getCurrentItemState.value =
+ assertions.value.find((item: any) => item.id === activeKey.value) || assertions.value[0] || {};
+ activeKey.value = getCurrentItemState.value.id;
});
@@ -317,7 +375,6 @@
padding: 12px;
width: 216px;
min-width: 216px;
- height: calc(100vh - 394px);
background-color: var(--color-text-n9);
flex-direction: column;
gap: 4px;
diff --git a/frontend/src/components/pure/ms-code-editor/types.ts b/frontend/src/components/pure/ms-code-editor/types.ts
index de69624e48..cbc07de905 100644
--- a/frontend/src/components/pure/ms-code-editor/types.ts
+++ b/frontend/src/components/pure/ms-code-editor/types.ts
@@ -119,4 +119,8 @@ export const editorProps = {
type: Boolean as PropType