Skip to content

Commit 02b8640

Browse files
committed
feat: add history delete and run api
1 parent 6c36229 commit 02b8640

File tree

20 files changed

+1312
-515
lines changed

20 files changed

+1312
-515
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@
5050
"filter": "Filter Keyword",
5151
"noParameter": "No Parameter",
5252
"testsuite": "Test Suite:",
53-
"apiAddress": "API Address:"
53+
"apiAddress": "API Address:",
54+
"runningAt": "Running At:"
5455
},
5556
"field": {
5657
"name": "Name",

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@
4545
"filter": "过滤",
4646
"noParameter": "无参数",
4747
"testsuite": "测试集:",
48-
"apiAddress": "API 地址:"
48+
"apiAddress": "API 地址:",
49+
"runningAt": "运行于:"
4950
},
5051
"field": {
5152
"name": "名称",

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

Lines changed: 103 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -50,20 +50,28 @@ const runTestCase = () => {
5050
requestLoading.value = true
5151
const name = props.name
5252
const suite = props.suite
53+
historyCaseID = props.historyCaseID
5354
55+
if (isHistoryTestCase.value == true){
56+
RunHistoryTestCase(historyCaseID)
57+
} else{
58+
RunTestCase(name, suite)
59+
}
60+
}
61+
62+
function RunTestCase(name, suite){
5463
API.RunTestCase({
5564
suiteName: suite,
5665
name: name,
5766
parameters: parameters.value
58-
}, (e) => {
59-
handleTestResult(e)
60-
requestLoading.value = false
61-
}, (e) => {
62-
parameters.value = []
67+
}, (e) => {
68+
handleTestResult(e)
69+
requestLoading.value = false
70+
}, (e) => {
71+
parameters.value = []
6372
6473
requestLoading.value = false
6574
UIAPI.ErrorTip(e)
66-
6775
parseResponseBody(e.body)
6876
})
6977
}
@@ -81,29 +89,55 @@ const parseResponseBody = (body) => {
8189
}
8290
}
8391
92+
function RunHistoryTestCase(historyCaseID : string){
93+
API.RunHistoryTestCase({
94+
historyCaseID : historyCaseID
95+
}, (e) => {
96+
handleTestResultError(e)
97+
handleTestResult(e)
98+
requestLoading.value = false
99+
}, (e) => {
100+
parameters.value = []
101+
requestLoading.value = false
102+
UIAPI.ErrorTip(e)
103+
testResult.value.bodyObject = JSON.parse(e.body)
104+
testResult.value.originBodyObject = JSON.parse(e.body)
105+
})
106+
}
107+
84108
const handleTestResult = (e) => {
85109
testResult.value = e;
86110
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)
111+
if (!isHistoryTestCase.value) {
112+
handleTestResultError(e)
113+
}
114+
115+
if (e.body !== '') {
116+
testResult.value.bodyObject = JSON.parse(e.body);
117+
testResult.value.originBodyObject = JSON.parse(e.body);
118+
}
99119
100120
Cache.SetTestCaseResponseCache(suite + '-' + name, {
101121
body: testResult.value.bodyObject,
102122
output: e.output,
103123
statusCode: testResult.value.statusCode
104124
} as TestCaseResponse)
105125
106-
parameters.value = []
126+
parameters.value = [];
127+
}
128+
129+
const handleTestResultError = (e) => {
130+
if (e.error !== '') {
131+
ElMessage({
132+
message: e.error,
133+
type: 'error'
134+
});
135+
} else {
136+
ElMessage({
137+
message: 'Pass!',
138+
type: 'success'
139+
});
140+
}
107141
}
108142
109143
const responseBodyFilterText = ref('')
@@ -213,6 +247,7 @@ let suite
213247
let historySuiteName
214248
let historyCaseID
215249
const isHistoryTestCase = ref(false)
250+
const HistoryTestCaseCreateTime = ref('')
216251
217252
function load() {
218253
name = props.name
@@ -238,11 +273,12 @@ function load() {
238273
239274
if (historySuiteName != '' && historySuiteName != undefined) {
240275
isHistoryTestCase.value = true
241-
API.GetHistoryTestCase({
276+
API.GetHistoryTestCaseWithResult({
242277
historyCaseID : historyCaseID
243278
}, (e) => {
244279
processResponse(e.data)
245280
handleTestResult(e.testCaseResult[0])
281+
formatDate(e.createTime)
246282
})
247283
} else {
248284
API.GetTestCase({
@@ -254,6 +290,22 @@ function load() {
254290
}
255291
}
256292
293+
function formatDate(createTimeStr : string){
294+
let parts = createTimeStr.split(/[T.Z]/);
295+
let datePart = parts[0].split("-");
296+
let timePart = parts[1].split(":");
297+
298+
let year = datePart[0];
299+
let month = datePart[1];
300+
let day = datePart[2];
301+
let hours = timePart[0];
302+
let minutes = timePart[1];
303+
let seconds = timePart[2].split(".")[0];
304+
305+
let formattedDate = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
306+
HistoryTestCaseCreateTime.value = formattedDate
307+
}
308+
257309
function processResponse(e) {
258310
if (e.request.method === '') {
259311
e.request.method = 'GET'
@@ -334,28 +386,40 @@ function saveTestCase(tip: boolean = true, callback: (c: any) => void) {
334386
}, UIAPI.ErrorTip, saveLoading)
335387
}
336388
337-
function deleteTestCase() {
389+
function deleteCase() {
338390
const name = props.name
339391
const suite = props.suite
392+
const historyCaseID = props.historyCaseID
393+
394+
if (isHistoryTestCase.value == true){
395+
deleteHistoryTestCase(historyCaseID)
396+
} else {
397+
deleteTestCase(name, suite)
398+
}
399+
}
340400
341-
API.DeleteTestCase({
342-
suiteName: suite,
343-
name: name
344-
}, (e) => {
345-
if (e.ok) {
346-
emit('updated', 'hello from child')
401+
function deleteHistoryTestCase(historyCaseID : string){
402+
API.DeleteHistoryTestCase({ historyCaseID }, handleDeleteResponse);
403+
}
347404
348-
ElMessage({
349-
message: 'Delete.',
350-
type: 'success'
351-
})
405+
function deleteTestCase(name : string, suite : string){
406+
API.DeleteTestCase({ suiteName: suite, name }, handleDeleteResponse);
407+
}
352408
353-
// clean all the values
354-
testCaseWithSuite.value = emptyTestCaseWithSuite
355-
} else {
356-
UIAPI.ErrorTip(e)
357-
}
358-
})
409+
function handleDeleteResponse(e) {
410+
if (e.ok) {
411+
emit('updated', 'hello from child');
412+
413+
ElMessage({
414+
message: 'Delete.',
415+
type: 'success'
416+
});
417+
418+
// Clean all the values
419+
testCaseWithSuite.value = emptyTestCaseWithSuite;
420+
} else {
421+
UIAPI.ErrorTip(e);
422+
}
359423
}
360424
361425
const codeDialogOpened = ref(false)
@@ -593,9 +657,10 @@ Magic.Keys(() => {
593657
<el-button type="primary" @click="saveTestCase" :icon="Edit" :loading="saveLoading"
594658
v-if="!Cache.GetCurrentStore().readOnly && !isHistoryTestCase"
595659
>{{ t('button.save') }}</el-button>
596-
<el-button type="danger" @click="deleteTestCase" :icon="Delete">{{ t('button.delete') }}</el-button>
660+
<el-button type="danger" @click="deleteCase" :icon="Delete">{{ t('button.delete') }}</el-button>
597661
<el-button type="primary" @click="openDuplicateTestCaseDialog" :icon="CopyDocument">{{ t('button.duplicate') }}</el-button>
598662
<el-button type="primary" @click="openCodeDialog">{{ t('button.generateCode') }}</el-button>
663+
<span v-if="isHistoryTestCase" style="margin-left: 15px;">{{ t('tip.runningAt') }}{{ HistoryTestCaseCreateTime }}</span>
599664
</div>
600665
<div style="display: flex;">
601666
<el-select

console/atest-ui/src/views/net.ts

Lines changed: 64 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,23 @@ const GetTestSuiteYaml = (suite: string, callback: (d: any) => void, errHandle?:
559559
.catch(errHandle)
560560
}
561561

562+
function GetHistoryTestCaseWithResult(req: HistoryTestCase,
563+
callback: (d: any) => void, errHandle?: (e: any) => void | null) {
564+
const requestOptions = {
565+
method: 'POST',
566+
headers: {
567+
'X-Store-Name': Cache.GetCurrentStore().name,
568+
'X-Auth': getToken()
569+
},
570+
body: JSON.stringify({
571+
ID : req.historyCaseID
572+
})
573+
}
574+
fetch('/server.Runner/GetHistoryTestCaseWithResult', requestOptions)
575+
.then(DefaultResponseProcess)
576+
.then(callback).catch(errHandle)
577+
}
578+
562579
function GetHistoryTestCase(req: HistoryTestCase,
563580
callback: (d: any) => void, errHandle?: (e: any) => void | null) {
564581
const requestOptions = {
@@ -576,19 +593,52 @@ function GetHistoryTestCase(req: HistoryTestCase,
576593
.then(callback).catch(errHandle)
577594
}
578595

596+
function DeleteHistoryTestCase(req: HistoryTestCase,
597+
callback: (d: any) => void, errHandle?: (e: any) => void | null) {
598+
const requestOptions = {
599+
method: 'POST',
600+
headers: {
601+
'X-Store-Name': Cache.GetCurrentStore().name,
602+
'X-Auth': getToken()
603+
},
604+
body: JSON.stringify({
605+
ID : req.historyCaseID
606+
})
607+
}
608+
fetch('/server.Runner/DeleteHistoryTestCase', requestOptions)
609+
.then(callback).catch(errHandle)
610+
}
611+
612+
function RunHistoryTestCase(req: HistoryTestCase,
613+
callback: (d: any) => void, errHandle?: (e: any) => void | null) {
614+
const requestOptions = {
615+
method: 'POST',
616+
headers: {
617+
'X-Store-Name': Cache.GetCurrentStore().name,
618+
'X-Auth': getToken()
619+
},
620+
body: JSON.stringify({
621+
ID : req.historyCaseID
622+
})
623+
}
624+
fetch('/server.Runner/RunHistoryTestCase', requestOptions)
625+
.then(DefaultResponseProcess)
626+
.then(callback).catch(errHandle)
627+
}
628+
629+
579630
export const API = {
580-
DefaultResponseProcess,
581-
GetVersion,
582-
CreateTestSuite, UpdateTestSuite, ImportTestSuite, GetTestSuite, DeleteTestSuite, ConvertTestSuite, GetTestSuiteYaml,
583-
DuplicateTestSuite,
584-
CreateTestCase, UpdateTestCase, GetTestCase, ListTestCase, DeleteTestCase, RunTestCase, DuplicateTestCase,
585-
GetHistoryTestCase,
586-
GenerateCode, ListCodeGenerator,
587-
PopularHeaders,
588-
CreateOrUpdateStore, GetStores, DeleteStore, VerifyStore,
589-
FunctionsQuery,
590-
GetSecrets, DeleteSecret, CreateOrUpdateSecret,
591-
GetSuggestedAPIs,
592-
ReloadMockServer, GetMockConfig,
593-
getToken
631+
DefaultResponseProcess,
632+
GetVersion,
633+
CreateTestSuite, UpdateTestSuite, ImportTestSuite, GetTestSuite, DeleteTestSuite, ConvertTestSuite,GetTestSuiteYaml,
634+
CreateTestCase, UpdateTestCase, GetTestCase, ListTestCase, DeleteTestCase, RunTestCase,
635+
GetHistoryTestCaseWithResult, DeleteHistoryTestCase,GetHistoryTestCase, RunHistoryTestCase,
636+
GenerateCode, ListCodeGenerator,
637+
PopularHeaders,
638+
CreateOrUpdateStore, GetStores, DeleteStore, VerifyStore,
639+
FunctionsQuery,
640+
GetSecrets, DeleteSecret, CreateOrUpdateSecret,
641+
GetSuggestedAPIs,
642+
ReloadMockServer, GetMockConfig,
643+
getToken
594644
}

pkg/server/convert.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,37 @@ func ToNormalStore(store *Store) (result testing.Store) {
6565
return
6666
}
6767

68+
func ConvertToGRPCHistoryTestCase(historyTestcase testing.HistoryTestCase) (result *HistoryTestCase) {
69+
req := historyTestcase.Data.Request
70+
res := historyTestcase.Data.Expect
71+
result = &HistoryTestCase{
72+
CaseName: historyTestcase.CaseName,
73+
SuiteName: historyTestcase.SuiteName,
74+
SuiteApi: historyTestcase.SuiteAPI,
75+
SuiteParam: mapToPair(historyTestcase.SuiteParam),
76+
77+
Request: &Request{
78+
Api: req.API,
79+
Method: req.Method,
80+
Body: req.Body.String(),
81+
Header: mapToPair(req.Header),
82+
Query: mapInterToPair(req.Query),
83+
Form: mapToPair(req.Form),
84+
},
85+
86+
Response: &Response{
87+
Body: res.Body,
88+
StatusCode: int32(res.StatusCode),
89+
Schema: res.Schema,
90+
Verify: res.Verify,
91+
Header: mapToPair(res.Header),
92+
BodyFieldsExpect: mapInterToPair(res.BodyFieldsExpect),
93+
},
94+
}
95+
result.SuiteSpec = ToGRPCTestSuiteSpec(historyTestcase.SuiteSpec)
96+
return
97+
}
98+
6899
func ToGRPCSuite(suite *testing.TestSuite) (result *TestSuite) {
69100
result = &TestSuite{
70101
Name: suite.Name,

0 commit comments

Comments
 (0)