Skip to content

Commit 6c36229

Browse files
committed
feat: add history ui and api
1 parent 0998b2f commit 6c36229

22 files changed

+2530
-1274
lines changed

console/atest-ui/src/App.vue

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import {
33
Document,
44
Menu as IconMenu,
5+
Histogram,
56
Location,
67
Share,
78
ArrowDown
@@ -10,6 +11,7 @@ import { ref, watch } from 'vue'
1011
import { API } from './views/net'
1112
import { Cache } from './views/cache'
1213
import TestingPanel from './views/TestingPanel.vue'
14+
import TestingHistoryPanel from './views/TestingHistoryPanel.vue'
1315
import MockManager from './views/MockManager.vue'
1416
import StoreManager from './views/StoreManager.vue'
1517
import SecretManager from './views/SecretManager.vue'
@@ -104,6 +106,10 @@ const handleChangeLan = (command: string) => {
104106
<el-icon><icon-menu /></el-icon>
105107
<template #title>{{ t('title.testing' )}}</template>
106108
</el-menu-item>
109+
<el-menu-item index="history" test-id="history-menu">
110+
<el-icon><histogram /></el-icon>
111+
<template #title>{{ t('title.history' )}}</template>
112+
</el-menu-item>
107113
<el-menu-item index="mock" test-id="mock-menu">
108114
<el-icon><icon-menu /></el-icon>
109115
<template #title>{{ t('title.mock' )}}</template>
@@ -135,6 +141,7 @@ const handleChangeLan = (command: string) => {
135141
</el-col>
136142
</div>
137143
<TestingPanel v-if="panelName === 'testing'" />
144+
<TestingHistoryPanel v-else-if="panelName === 'history'" />
138145
<MockManager v-else-if="panelName === 'mock'" />
139146
<StoreManager v-else-if="panelName === 'store'" />
140147
<SecretManager v-else-if="panelName === 'secret'" />

console/atest-ui/src/locales/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"apiRequestParameter": "API Request Parameter",
3939
"codeGenerator": "Code Generator",
4040
"testing": "Testing",
41+
"history": "Testing History",
4142
"mock": "Mock",
4243
"welcome": "Welcome",
4344
"secrets": "Secrets",

console/atest-ui/src/locales/zh.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"apiRequestParameter": "API 请求参数",
3434
"codeGenerator": "代码生成",
3535
"testing": "测试",
36+
"history": "测试历史",
3637
"welcome": "欢迎",
3738
"secrets": "凭据",
3839
"stores": "存储",

console/atest-ui/src/views/TestCase.vue

Lines changed: 128 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ const props = defineProps({
2121
name: String,
2222
suite: String,
2323
kindName: String,
24+
historySuiteName: String,
25+
historyCaseID: String
2426
})
2527
const emit = defineEmits(['updated'])
2628
@@ -52,31 +54,10 @@ const runTestCase = () => {
5254
API.RunTestCase({
5355
suiteName: suite,
5456
name: name,
55-
parameters: parameters.value
57+
parameters: parameters.value
5658
}, (e) => {
57-
testResult.value = e
59+
handleTestResult(e)
5860
requestLoading.value = false
59-
60-
if (e.error !== '') {
61-
ElMessage({
62-
message: e.error,
63-
type: 'error'
64-
})
65-
} else {
66-
ElMessage({
67-
message: 'Pass!',
68-
type: 'success'
69-
})
70-
}
71-
parseResponseBody(e.body)
72-
73-
Cache.SetTestCaseResponseCache(suite + '-' + name, {
74-
body: testResult.value.bodyObject,
75-
output: e.output,
76-
statusCode: testResult.value.statusCode
77-
} as TestCaseResponse)
78-
79-
parameters.value = []
8061
}, (e) => {
8162
parameters.value = []
8263
@@ -100,6 +81,31 @@ const parseResponseBody = (body) => {
10081
}
10182
}
10283
84+
const handleTestResult = (e) => {
85+
testResult.value = e;
86+
87+
if (e.error !== '') {
88+
ElMessage({
89+
message: e.error,
90+
type: 'error'
91+
})
92+
} else {
93+
ElMessage({
94+
message: 'Pass!',
95+
type: 'success'
96+
})
97+
}
98+
parseResponseBody(e.body)
99+
100+
Cache.SetTestCaseResponseCache(suite + '-' + name, {
101+
body: testResult.value.bodyObject,
102+
output: e.output,
103+
statusCode: testResult.value.statusCode
104+
} as TestCaseResponse)
105+
106+
parameters.value = []
107+
}
108+
103109
const responseBodyFilterText = ref('')
104110
function responseBodyFilter() {
105111
if (responseBodyFilterText.value === '') {
@@ -117,8 +123,8 @@ function responseBodyFilter() {
117123
const parameterDialogOpened = ref(false)
118124
function openParameterDialog() {
119125
API.GetTestSuite(props.suite, (e) => {
120-
parameters.value = e.param
121-
parameterDialogOpened.value = true
126+
parameters.value = e.param
127+
parameterDialogOpened.value = true
122128
}, UIAPI.ErrorTip)
123129
}
124130
@@ -136,16 +142,16 @@ function generateCode() {
136142
name: name,
137143
generator: currentCodeGenerator.value
138144
}, (e) => {
139-
ElMessage({
140-
message: 'Code generated!',
141-
type: 'success'
142-
})
143-
if (currentCodeGenerator.value === "gRPCPayload") {
144-
currentCodeContent.value = JSON.stringify(JSON.parse(e.message), null, 4)
145-
} else {
146-
currentCodeContent.value = e.message
147-
}
148-
}, UIAPI.ErrorTip)
145+
ElMessage({
146+
message: 'Code generated!',
147+
type: 'success'
148+
})
149+
if (currentCodeGenerator.value === "gRPCPayload") {
150+
currentCodeContent.value = JSON.stringify(JSON.parse(e.message), null, 4)
151+
} else {
152+
currentCodeContent.value = e.message
153+
}
154+
}, UIAPI.ErrorTip)
149155
}
150156
151157
function copyCode() {
@@ -202,9 +208,17 @@ const emptyTestCaseWithSuite: TestCaseWithSuite = {
202208
203209
const testCaseWithSuite = ref(emptyTestCaseWithSuite)
204210
211+
let name
212+
let suite
213+
let historySuiteName
214+
let historyCaseID
215+
const isHistoryTestCase = ref(false)
216+
205217
function load() {
206-
const name = props.name
207-
const suite = props.suite
218+
name = props.name
219+
suite = props.suite
220+
historySuiteName = props.historySuiteName
221+
historyCaseID = props.historyCaseID
208222
if (name === '' || suite === '') {
209223
return
210224
}
@@ -222,61 +236,75 @@ function load() {
222236
}
223237
testResult.value.originBodyObject = testResult.value.bodyObject
224238
225-
API.GetTestCase({
226-
suiteName: suite,
227-
name: name
228-
}, (e) => {
229-
if (e.request.method === '') {
230-
e.request.method = 'GET'
231-
}
239+
if (historySuiteName != '' && historySuiteName != undefined) {
240+
isHistoryTestCase.value = true
241+
API.GetHistoryTestCase({
242+
historyCaseID : historyCaseID
243+
}, (e) => {
244+
processResponse(e.data)
245+
handleTestResult(e.testCaseResult[0])
246+
})
247+
} else {
248+
API.GetTestCase({
249+
suiteName: suite,
250+
name: name
251+
}, (e) => {
252+
processResponse(e)
253+
})
254+
}
255+
}
232256
233-
e.request.header.push({
234-
key: '',
235-
value: ''
236-
})
237-
e.request.cookie.push({
238-
key: '',
239-
value: ''
240-
})
241-
e.request.query.push({
242-
key: '',
243-
value: ''
244-
})
245-
e.request.form.push({
246-
key: '',
247-
value: ''
248-
})
249-
e.response.header.push({
250-
key: '',
251-
value: ''
252-
})
253-
e.response.bodyFieldsExpect.push({
254-
key: '',
255-
value: ''
256-
})
257-
e.response.verify.push('')
258-
if (e.response.statusCode === 0) {
259-
e.response.statusCode = 200
257+
function processResponse(e) {
258+
if (e.request.method === '') {
259+
e.request.method = 'GET'
260+
}
261+
262+
e.request.header.push({
263+
key: '',
264+
value: ''
265+
})
266+
e.request.cookie.push({
267+
key: '',
268+
value: ''
269+
})
270+
e.request.query.push({
271+
key: '',
272+
value: ''
273+
})
274+
e.request.form.push({
275+
key: '',
276+
value: ''
277+
})
278+
e.response.header.push({
279+
key: '',
280+
value: ''
281+
})
282+
e.response.bodyFieldsExpect.push({
283+
key: '',
284+
value: ''
285+
})
286+
e.response.verify.push('')
287+
if (e.response.statusCode === 0) {
288+
e.response.statusCode = 200
289+
}
290+
291+
e.request.header.forEach(item => {
292+
if (item.key === "Content-Type") {
293+
switch (item.value) {
294+
case 'application/x-www-form-urlencoded':
295+
bodyType.value = 4
296+
break
297+
case 'application/json':
298+
bodyType.value = 5
299+
break
260300
}
301+
}
302+
});
261303
262-
e.request.header.forEach(item => {
263-
if (item.key === "Content-Type") {
264-
switch (item.value) {
265-
case 'application/x-www-form-urlencoded':
266-
bodyType.value = 4
267-
break
268-
case 'application/json':
269-
bodyType.value = 5
270-
break
271-
}
272-
}
273-
});
274-
275-
testCaseWithSuite.value = {
276-
suiteName: suite,
277-
data: e
278-
} as TestCaseWithSuite
279-
})
304+
testCaseWithSuite.value = {
305+
suiteName: suite,
306+
data: e
307+
} as TestCaseWithSuite
280308
}
281309
load()
282310
watch(props, () => {
@@ -451,9 +479,9 @@ function bodyTypeChange(e: number) {
451479
452480
if (contentType !== "") {
453481
testCaseWithSuite.value.data.request.header = insertOrUpdateIntoMap({
454-
key: 'Content-Type',
455-
value: contentType
456-
} as Pair, testCaseWithSuite.value.data.request.header)
482+
key: 'Content-Type',
483+
value: contentType
484+
} as Pair, testCaseWithSuite.value.data.request.header)
457485
}
458486
}
459487
@@ -560,10 +588,10 @@ Magic.Keys(() => {
560588
<el-header style="padding-left: 5px;">
561589
<div style="margin-bottom: 5px">
562590
<el-button type="primary" @click="saveTestCase" :icon="Edit" :loading="saveLoading"
563-
disabled v-if="Cache.GetCurrentStore().readOnly"
591+
disabled v-if="Cache.GetCurrentStore().readOnly || isHistoryTestCase"
564592
>{{ t('button.save') }}</el-button>
565593
<el-button type="primary" @click="saveTestCase" :icon="Edit" :loading="saveLoading"
566-
v-if="!Cache.GetCurrentStore().readOnly"
594+
v-if="!Cache.GetCurrentStore().readOnly && !isHistoryTestCase"
567595
>{{ t('button.save') }}</el-button>
568596
<el-button type="danger" @click="deleteTestCase" :icon="Delete">{{ t('button.delete') }}</el-button>
569597
<el-button type="primary" @click="openDuplicateTestCaseDialog" :icon="CopyDocument">{{ t('button.duplicate') }}</el-button>
@@ -599,11 +627,11 @@ Magic.Keys(() => {
599627

600628
<el-dropdown split-button type="primary" @click="sendRequest" :loading="requestLoading">
601629
{{ t('button.send') }}
602-
<template #dropdown>
603-
<el-dropdown-menu>
604-
<el-dropdown-item @click="openParameterDialog">{{ t('button.sendWithParam') }}</el-dropdown-item>
605-
</el-dropdown-menu>
606-
</template>
630+
<template #dropdown>
631+
<el-dropdown-menu>
632+
<el-dropdown-item @click="openParameterDialog">{{ t('button.sendWithParam') }}</el-dropdown-item>
633+
</el-dropdown-menu>
634+
</template>
607635
</el-dropdown>
608636
</div>
609637
</el-header>
@@ -682,7 +710,7 @@ Magic.Keys(() => {
682710
<el-table-column label="Value">
683711
<template #default="scope">
684712
<div style="display: flex; align-items: center">
685-
<el-input v-model="scope.row.value" placeholder="value"/>
713+
<el-input v-model="scope.row.value" placeholder="value" />
686714
</div>
687715
</template>
688716
</el-table-column>

0 commit comments

Comments
 (0)