Skip to content

Commit 5b990d4

Browse files
committed
feat: add history delete
1 parent 6c36229 commit 5b990d4

File tree

19 files changed

+1150
-470
lines changed

19 files changed

+1150
-470
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: 74 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ const runTestCase = () => {
5050
requestLoading.value = true
5151
const name = props.name
5252
const suite = props.suite
53-
5453
API.RunTestCase({
5554
suiteName: suite,
5655
name: name,
@@ -63,7 +62,6 @@ const runTestCase = () => {
6362
6463
requestLoading.value = false
6564
UIAPI.ErrorTip(e)
66-
6765
parseResponseBody(e.body)
6866
})
6967
}
@@ -84,26 +82,36 @@ const parseResponseBody = (body) => {
8482
const handleTestResult = (e) => {
8583
testResult.value = e;
8684
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)
85+
if (!isHistoryTestCase.value) {
86+
handleTestResultError(e)
87+
}
88+
89+
if (e.body !== '') {
90+
testResult.value.bodyObject = JSON.parse(e.body);
91+
testResult.value.originBodyObject = JSON.parse(e.body);
92+
}
9993
10094
Cache.SetTestCaseResponseCache(suite + '-' + name, {
10195
body: testResult.value.bodyObject,
10296
output: e.output,
10397
statusCode: testResult.value.statusCode
10498
} as TestCaseResponse)
10599
106-
parameters.value = []
100+
parameters.value = [];
101+
}
102+
103+
const handleTestResultError = (e) => {
104+
if (e.error !== '') {
105+
ElMessage({
106+
message: e.error,
107+
type: 'error'
108+
});
109+
} else {
110+
ElMessage({
111+
message: 'Pass!',
112+
type: 'success'
113+
});
114+
}
107115
}
108116
109117
const responseBodyFilterText = ref('')
@@ -213,6 +221,7 @@ let suite
213221
let historySuiteName
214222
let historyCaseID
215223
const isHistoryTestCase = ref(false)
224+
const HistoryTestCaseCreateTime = ref('')
216225
217226
function load() {
218227
name = props.name
@@ -238,11 +247,12 @@ function load() {
238247
239248
if (historySuiteName != '' && historySuiteName != undefined) {
240249
isHistoryTestCase.value = true
241-
API.GetHistoryTestCase({
250+
API.GetHistoryTestCaseWithResult({
242251
historyCaseID : historyCaseID
243252
}, (e) => {
244253
processResponse(e.data)
245254
handleTestResult(e.testCaseResult[0])
255+
formatDate(e.createTime)
246256
})
247257
} else {
248258
API.GetTestCase({
@@ -254,6 +264,22 @@ function load() {
254264
}
255265
}
256266
267+
function formatDate(createTimeStr : string){
268+
let parts = createTimeStr.split(/[T.Z]/);
269+
let datePart = parts[0].split("-");
270+
let timePart = parts[1].split(":");
271+
272+
let year = datePart[0];
273+
let month = datePart[1];
274+
let day = datePart[2];
275+
let hours = timePart[0];
276+
let minutes = timePart[1];
277+
let seconds = timePart[2].split(".")[0];
278+
279+
let formattedDate = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
280+
HistoryTestCaseCreateTime.value = formattedDate
281+
}
282+
257283
function processResponse(e) {
258284
if (e.request.method === '') {
259285
e.request.method = 'GET'
@@ -334,28 +360,40 @@ function saveTestCase(tip: boolean = true, callback: (c: any) => void) {
334360
}, UIAPI.ErrorTip, saveLoading)
335361
}
336362
337-
function deleteTestCase() {
363+
function deleteCase() {
338364
const name = props.name
339365
const suite = props.suite
366+
const historyCaseID = props.historyCaseID
340367
341-
API.DeleteTestCase({
342-
suiteName: suite,
343-
name: name
344-
}, (e) => {
345-
if (e.ok) {
346-
emit('updated', 'hello from child')
368+
if (isHistoryTestCase.value == true){
369+
deleteHistoryTestCase(historyCaseID)
370+
} else {
371+
deleteTestCase(name, suite)
372+
}
373+
}
347374
348-
ElMessage({
349-
message: 'Delete.',
350-
type: 'success'
351-
})
375+
function deleteHistoryTestCase(historyCaseID : string){
376+
API.DeleteHistoryTestCase({ historyCaseID }, handleDeleteResponse);
377+
}
352378
353-
// clean all the values
354-
testCaseWithSuite.value = emptyTestCaseWithSuite
355-
} else {
356-
UIAPI.ErrorTip(e)
357-
}
358-
})
379+
function deleteTestCase(name : string, suite : string){
380+
API.DeleteTestCase({ suiteName: suite, name }, handleDeleteResponse);
381+
}
382+
383+
function handleDeleteResponse(e) {
384+
if (e.ok) {
385+
emit('updated', 'hello from child');
386+
387+
ElMessage({
388+
message: 'Delete.',
389+
type: 'success'
390+
});
391+
392+
// Clean all the values
393+
testCaseWithSuite.value = emptyTestCaseWithSuite;
394+
} else {
395+
UIAPI.ErrorTip(e);
396+
}
359397
}
360398
361399
const codeDialogOpened = ref(false)
@@ -593,9 +631,10 @@ Magic.Keys(() => {
593631
<el-button type="primary" @click="saveTestCase" :icon="Edit" :loading="saveLoading"
594632
v-if="!Cache.GetCurrentStore().readOnly && !isHistoryTestCase"
595633
>{{ t('button.save') }}</el-button>
596-
<el-button type="danger" @click="deleteTestCase" :icon="Delete">{{ t('button.delete') }}</el-button>
634+
<el-button type="danger" @click="deleteCase" :icon="Delete">{{ t('button.delete') }}</el-button>
597635
<el-button type="primary" @click="openDuplicateTestCaseDialog" :icon="CopyDocument">{{ t('button.duplicate') }}</el-button>
598636
<el-button type="primary" @click="openCodeDialog">{{ t('button.generateCode') }}</el-button>
637+
<span v-if="isHistoryTestCase" style="margin-left: 15px;">{{ t('tip.runningAt') }}{{ HistoryTestCaseCreateTime }}</span>
599638
</div>
600639
<div style="display: flex;">
601640
<el-select
@@ -703,7 +742,7 @@ Magic.Keys(() => {
703742
<el-table-column label="Key">
704743
<template #default="scope">
705744
<el-input v-model="scope.row.key" placeholder="Key"
706-
@change="cookieChange"
745+
@change="cookieChange"
707746
/>
708747
</template>
709748
</el-table-column>

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

Lines changed: 46 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,34 @@ 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+
579612
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
613+
DefaultResponseProcess,
614+
GetVersion,
615+
CreateTestSuite, UpdateTestSuite, ImportTestSuite, GetTestSuite, DeleteTestSuite, ConvertTestSuite,GetTestSuiteYaml,
616+
CreateTestCase, UpdateTestCase, GetTestCase, ListTestCase, DeleteTestCase, RunTestCase,
617+
GetHistoryTestCaseWithResult, DeleteHistoryTestCase,GetHistoryTestCase,
618+
GenerateCode, ListCodeGenerator,
619+
PopularHeaders,
620+
CreateOrUpdateStore, GetStores, DeleteStore, VerifyStore,
621+
FunctionsQuery,
622+
GetSecrets, DeleteSecret, CreateOrUpdateSecret,
623+
GetSuggestedAPIs,
624+
ReloadMockServer, GetMockConfig,
625+
getToken
594626
}

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,

pkg/server/remote_server.go

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -528,16 +528,26 @@ func (s *server) GetTestCase(ctx context.Context, in *TestCaseIdentity) (reply *
528528
return
529529
}
530530

531-
func (s *server) GetHistoryTestCase(ctx context.Context, in *HistoryTestCase) (reply *HistoryTestResult, err error) {
531+
func (s *server) GetHistoryTestCaseWithResult(ctx context.Context, in *HistoryTestCase) (reply *HistoryTestResult, err error) {
532532
var result testing.HistoryTestResult
533533
loader := s.getLoader(ctx)
534534
defer loader.Close()
535-
if result, err = loader.GetHistoryTestCase(in.ID); err == nil {
535+
if result, err = loader.GetHistoryTestCaseWithResult(in.ID); err == nil {
536536
reply = ToGRPCHistoryTestCaseResult(result)
537537
}
538538
return
539539
}
540540

541+
func (s *server) GetHistoryTestCase(ctx context.Context, in *HistoryTestCase) (reply *HistoryTestCase, err error) {
542+
var result testing.HistoryTestCase
543+
loader := s.getLoader(ctx)
544+
defer loader.Close()
545+
if result, err = loader.GetHistoryTestCase(in.ID); err == nil {
546+
reply = ConvertToGRPCHistoryTestCase(result)
547+
}
548+
return
549+
}
550+
541551
var ExecutionCountNum = promauto.NewCounter(prometheus.CounterOpts{
542552
Name: "atest_execution_count",
543553
Help: "The total number of request execution",
@@ -599,7 +609,7 @@ func (s *server) RunTestCase(ctx context.Context, in *TestCaseIdentity) (result
599609
}
600610
return
601611
}
602-
612+
603613
result = &TestCaseResult{
604614
Output: reply.Message,
605615
Error: reply.Error,
@@ -625,7 +635,7 @@ func (s *server) RunTestCase(ctx context.Context, in *TestCaseIdentity) (result
625635
result.Header = lastItem.Header
626636
result.StatusCode = lastItem.StatusCode
627637
}
628-
638+
629639
normalResult := ToNormalTestCaseResult(result)
630640
var testSuite *testing.TestSuite
631641
if testSuite, err = s.getSuiteFromTestTask(task); err != nil {
@@ -733,6 +743,14 @@ func (s *server) DeleteTestCase(ctx context.Context, in *TestCaseIdentity) (repl
733743
return
734744
}
735745

746+
func (s *server) DeleteHistoryTestCase(ctx context.Context, in *HistoryTestCase) (reply *HelloReply, err error) {
747+
loader := s.getLoader(ctx)
748+
defer loader.Close()
749+
reply = &HelloReply{}
750+
err = loader.DeleteHistoryTestCase(in.ID)
751+
return
752+
}
753+
736754
func (s *server) DuplicateTestCase(ctx context.Context, in *TestCaseDuplicate) (reply *HelloReply, err error) {
737755
loader := s.getLoader(ctx)
738756
defer loader.Close()

0 commit comments

Comments
 (0)