From b1c4479cf3daffe6319e34b5f262d342c0987405 Mon Sep 17 00:00:00 2001
From: Rick <1450685+LinuxSuRen@users.noreply.github.com>
Date: Mon, 17 Jul 2023 16:48:12 +0800
Subject: [PATCH] feat: support the form body on UI (#130)
---
console/atest-ui/src/App.vue | 4 +-
console/atest-ui/src/views/TestCase.vue | 82 +++++++++++++++++++++++--
console/atest-ui/src/views/types.ts | 4 +-
pkg/server/data/headers.yaml | 2 +
pkg/server/remote_server_test.go | 2 +-
5 files changed, 83 insertions(+), 11 deletions(-)
diff --git a/console/atest-ui/src/App.vue b/console/atest-ui/src/App.vue
index 9212e12..3a95ee4 100644
--- a/console/atest-ui/src/App.vue
+++ b/console/atest-ui/src/App.vue
@@ -2,7 +2,7 @@
import TestCase from './views/TestCase.vue'
import TestSuite from './views/TestSuite.vue'
import { reactive, ref, watch } from 'vue'
-import ElTree from 'element-plus'
+import { ElTree } from 'element-plus'
import type { FormInstance } from 'element-plus'
import { Edit } from '@element-plus/icons-vue'
@@ -150,7 +150,7 @@ const viewName = ref('testcase')
{
+ if (item.key === "Content-Type") {
+ switch (item.value) {
+ case 'application/x-www-form-urlencoded':
+ bodyType.value = 4
+ break
+ case 'application/json':
+ bodyType.value = 5
+ break
+ }
+ }
+ });
+
testCaseWithSuite.value = {
suiteName: suite,
data: e
@@ -243,7 +256,7 @@ function bodyFiledExpectChange() {
data.push({
key: '',
value: ''
- })
+ } as Pair)
}
}
@@ -254,7 +267,7 @@ function headerChange() {
testCaseWithSuite.value.data.request.header.push({
key: '',
value: ''
- })
+ } as Pair)
}
}
function expectedHeaderChange() {
@@ -264,11 +277,52 @@ function expectedHeaderChange() {
testCaseWithSuite.value.data.response.header.push({
key: '',
value: ''
- })
+ } as Pair)
+ }
+}
+function formChange() {
+ const form = testCaseWithSuite.value.data.request.form
+ let lastItem = form[form.length - 1]
+ if (lastItem.key !== '') {
+ testCaseWithSuite.value.data.request.form.push({
+ key: '',
+ value: ''
+ } as Pair)
}
}
-const radio1 = ref('1')
+const bodyType = ref(1)
+function bodyTypeChange(e: number) {
+ let contentType = ""
+ switch (e) {
+ case 4:
+ contentType = 'application/x-www-form-urlencoded'
+ break;
+ case 5:
+ contentType = 'application/json'
+ break;
+ }
+
+ if (contentType !== "") {
+ testCaseWithSuite.value.data.request.header = insertOrUpdateIntoMap({
+ key: 'Content-Type',
+ value: contentType
+ } as Pair, testCaseWithSuite.value.data.request.header)
+ }
+}
+
+function insertOrUpdateIntoMap(pair: Pair, pairs: Pair[]) {
+ const index = pairs.findIndex((e) => e.key === pair.key)
+ if (index === -1) {
+ const oldPairs = pairs
+ pairs = [pair]
+ pairs = pairs.concat(oldPairs)
+ } else {
+ pairs[index] = pair
+ }
+ return pairs
+}
+
const pupularHeaders = ref([] as Pair[])
const requestOptions = {
method: 'POST'
@@ -347,7 +401,7 @@ function flattenObject(obj: any): any {
@@ -391,19 +445,35 @@ function flattenObject(obj: any): any {
-
+
none
form-data
raw
x-www-form-urlencoded
+ JSON
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/console/atest-ui/src/views/types.ts b/console/atest-ui/src/views/types.ts
index d518dd7..60a01ad 100644
--- a/console/atest-ui/src/views/types.ts
+++ b/console/atest-ui/src/views/types.ts
@@ -106,8 +106,8 @@ export function GetHTTPMethods() {
key: 'GET'
},
{
- key: 'POST',
- label: 'POST'
+ value: 'POST',
+ key: 'POST'
},
{
value: 'DELETE',
diff --git a/pkg/server/data/headers.yaml b/pkg/server/data/headers.yaml
index 62a7a85..d4c57a9 100644
--- a/pkg/server/data/headers.yaml
+++ b/pkg/server/data/headers.yaml
@@ -2,6 +2,8 @@
value: ""
- key: Content-Type
value: application/json
+- key: Content-Type
+ value: application/x-www-form-urlencoded
- key: Accept-Language
value: en-US,en;q=0.5
- key: Authorization
diff --git a/pkg/server/remote_server_test.go b/pkg/server/remote_server_test.go
index 4ef1f1d..096bc9c 100644
--- a/pkg/server/remote_server_test.go
+++ b/pkg/server/remote_server_test.go
@@ -434,7 +434,7 @@ func TestPopularHeaders(t *testing.T) {
pairs, err := server.PopularHeaders(ctx, &Empty{})
if assert.NoError(t, err) {
- assert.Equal(t, 4, len(pairs.Data))
+ assert.Equal(t, 5, len(pairs.Data))
}
}