Skip to content

Commit 7d9a97f

Browse files
authored
feat: support to rename test suite and case (#550)
* feat: support to rename test suite and case * try to make the e2e be more stable --------- Co-authored-by: rick <[email protected]>
1 parent 908fbfe commit 7d9a97f

23 files changed

+1215
-550
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<script setup lang="ts">
2+
import { nextTick, ref } from 'vue'
3+
import { ElInput } from 'element-plus'
4+
import type { InputInstance } from 'element-plus'
5+
6+
const props = defineProps({
7+
value: String,
8+
})
9+
10+
const emit = defineEmits(['changed'])
11+
const inputVisible = ref(false)
12+
const inputValue = ref('')
13+
const InputRef = ref<InputInstance>()
14+
15+
const showInput = () => {
16+
inputVisible.value = true
17+
inputValue.value = props.value ?? ''
18+
nextTick(() => {
19+
InputRef.value!.input!.focus()
20+
})
21+
}
22+
23+
const handleInputConfirm = () => {
24+
if (inputValue.value && props.value !== inputValue.value) {
25+
emit('changed', inputValue.value)
26+
}
27+
inputVisible.value = false
28+
inputValue.value = ''
29+
}
30+
</script>
31+
32+
<template>
33+
<span class="flex gap-2">
34+
<el-input
35+
v-if="inputVisible"
36+
ref="InputRef"
37+
v-model="inputValue"
38+
class="w-20"
39+
style="width: 200px"
40+
@keyup.enter="handleInputConfirm"
41+
@blur="handleInputConfirm"
42+
/>
43+
<el-button v-else class="button-new-tag" size="small" @click="showInput">
44+
{{ value }}
45+
</el-button>
46+
</span>
47+
</template>

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

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import type { Pair, TestResult, TestCaseWithSuite, TestCase } from './types'
77
import { NewSuggestedAPIsQuery, CreateFilter, GetHTTPMethods, FlattenObject } from './types'
88
import { Cache } from './cache'
99
import { API } from './net'
10+
import EditButton from '../components/EditButton.vue'
1011
import type { RunTestCaseRequest } from './net'
1112
import { UIAPI } from './net-vue'
1213
import type { TestCaseResponse } from './cache'
@@ -23,7 +24,6 @@ import 'codemirror/addon/merge/merge.css'
2324
2425
import DiffMatchPatch from 'diff-match-patch';
2526
26-
2727
window.diff_match_patch = DiffMatchPatch;
2828
window.DIFF_DELETE = -1;
2929
window.DIFF_INSERT = 1;
@@ -380,25 +380,25 @@ function downloadResponseFile(){
380380
API.DownloadResponseFile({
381381
body: testResult.value.body
382382
}, (e) => {
383-
if (e && e.data) {
384-
try {
385-
const bytes = atob(e.data);
386-
const blob = new Blob([bytes], { type: 'mimeType' });
387-
const link = document.createElement('a');
388-
link.href = window.URL.createObjectURL(blob);
389-
link.download = e.filename.substring("isFilePath-".length);
390-
391-
document.body.appendChild(link);
392-
link.click();
393-
394-
window.URL.revokeObjectURL(link.href);
395-
document.body.removeChild(link);
396-
} catch (error) {
397-
console.error('Error during file download:', error);
383+
if (e && e.data) {
384+
try {
385+
const bytes = atob(e.data);
386+
const blob = new Blob([bytes], { type: 'mimeType' });
387+
const link = document.createElement('a');
388+
link.href = window.URL.createObjectURL(blob);
389+
link.download = e.filename.substring("isFilePath-".length);
390+
391+
document.body.appendChild(link);
392+
link.click();
393+
394+
window.URL.revokeObjectURL(link.href);
395+
document.body.removeChild(link);
396+
} catch (error) {
397+
console.error('Error during file download:', error);
398+
}
399+
} else {
400+
console.error('No data to download.');
398401
}
399-
} else {
400-
console.error('No data to download.');
401-
}
402402
})
403403
}
404404
@@ -877,6 +877,13 @@ Magic.Keys(() => {
877877
duplicateTestCase()
878878
}
879879
}, ['Alt+KeyO'])
880+
881+
const renameTestCase = (name: string) => {
882+
const suiteName = props.suite
883+
API.RenameTestCase(suiteName, suiteName, props.name, name, (d) => {
884+
emit('updated', suiteName, name)
885+
})
886+
}
880887
</script>
881888

882889
<template>
@@ -894,6 +901,7 @@ Magic.Keys(() => {
894901
<el-button type="primary" @click="openCodeDialog">{{ t('button.generateCode') }}</el-button>
895902
<el-button type="primary" v-if="!isHistoryTestCase && Cache.GetCurrentStore().kind.name == 'atest-store-orm'" @click="openHistoryDialog">{{ t('button.viewHistory') }}</el-button>
896903
<span v-if="isHistoryTestCase" style="margin-left: 15px;">{{ t('tip.runningAt') }}{{ HistoryTestCaseCreateTime }}</span>
904+
<EditButton :value="props.name" @changed="renameTestCase"/>
897905
</div>
898906
<div>
899907
<el-row>

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { Edit, CopyDocument, Delete } from '@element-plus/icons-vue'
55
import type { FormInstance, FormRules } from 'element-plus'
66
import type { Suite, TestCase, Pair } from './types'
77
import { NewSuggestedAPIsQuery, GetHTTPMethods } from './types'
8+
import EditButton from '../components/EditButton.vue'
89
import { Cache } from './cache'
910
import { useI18n } from 'vue-i18n'
1011
import { API } from './net'
@@ -252,11 +253,17 @@ const duplicateTestSuite = () => {
252253
}
253254
const testSuiteDuplicateDialog = ref(false)
254255
const targetSuiteDuplicateName = ref('')
256+
257+
const renameTestSuite = (name: string) => {
258+
API.RenameTestSuite(props.name, name, (d) => {
259+
emit('updated', name)
260+
})
261+
}
255262
</script>
256263

257264
<template>
258265
<div class="common-layout">
259-
{{ t('tip.testsuite') }}<el-text class="mx-1" type="primary">{{ suite.name }}</el-text>
266+
{{ t('tip.testsuite') }}<EditButton :value="suite.name" @changed="renameTestSuite"/>
260267

261268
<table style="width: 100%">
262269
<tr>

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

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,24 @@ function DuplicateTestSuite(sourceSuiteName: string, targetSuiteName: string,
163163
.then(callback).catch(errHandle)
164164
}
165165

166+
const RenameTestSuite = (sourceSuiteName: string, targetSuiteName: string,
167+
callback: (d: any) => void, errHandle?: (e: any) => void | null) => {
168+
const requestOptions = {
169+
method: 'POST',
170+
headers: {
171+
'X-Store-Name': Cache.GetCurrentStore().name,
172+
'X-Auth': getToken()
173+
},
174+
body: JSON.stringify({
175+
sourceSuiteName: sourceSuiteName,
176+
targetSuiteName: targetSuiteName,
177+
})
178+
}
179+
fetch(`/api/v1/suites/${sourceSuiteName}/rename`, requestOptions)
180+
.then(DefaultResponseProcess)
181+
.then(callback).catch(errHandle)
182+
}
183+
166184
function ImportTestSuite(source: ImportSource, callback: (d: any) => void,
167185
errHandle?: (e: any) => void | null) {
168186
const requestOptions = {
@@ -367,6 +385,27 @@ function DuplicateTestCase(sourceSuiteName: string, targetSuiteName: string,
367385
.then(callback).catch(errHandle)
368386
}
369387

388+
function RenameTestCase(sourceSuiteName: string, targetSuiteName: string,
389+
sourceTestCaseName: string, targetTestCaseName: string,
390+
callback: (d: any) => void, errHandle?: ((reason: any) => PromiseLike<never>) | undefined | null ) {
391+
const requestOptions = {
392+
method: 'POST',
393+
headers: {
394+
'X-Store-Name': Cache.GetCurrentStore().name,
395+
'X-Auth': getToken()
396+
},
397+
body: JSON.stringify({
398+
sourceSuiteName: sourceSuiteName,
399+
targetSuiteName: targetSuiteName,
400+
sourceCaseName: sourceTestCaseName,
401+
targetCaseName: targetTestCaseName,
402+
})
403+
}
404+
fetch(`/api/v1/suites/${sourceSuiteName}/cases/${sourceTestCaseName}/rename`, requestOptions)
405+
.then(DefaultResponseProcess)
406+
.then(callback).catch(errHandle)
407+
}
408+
370409
interface GenerateRequest {
371410
suiteName: string
372411
name: string
@@ -734,8 +773,8 @@ function DownloadResponseFile(testcase,
734773
export const API = {
735774
DefaultResponseProcess,
736775
GetVersion,
737-
CreateTestSuite, UpdateTestSuite, ImportTestSuite, GetTestSuite, DeleteTestSuite, ConvertTestSuite, DuplicateTestSuite, GetTestSuiteYaml,
738-
CreateTestCase, UpdateTestCase, GetTestCase, ListTestCase, DeleteTestCase, RunTestCase, BatchRunTestCase,
776+
CreateTestSuite, UpdateTestSuite, ImportTestSuite, GetTestSuite, DeleteTestSuite, ConvertTestSuite, DuplicateTestSuite, RenameTestSuite, GetTestSuiteYaml,
777+
CreateTestCase, UpdateTestCase, GetTestCase, ListTestCase, DeleteTestCase, DuplicateTestCase, RenameTestCase, RunTestCase, BatchRunTestCase,
739778
GetHistoryTestCaseWithResult, DeleteHistoryTestCase,GetHistoryTestCase, GetTestCaseAllHistory, DeleteAllHistoryTestCase, DownloadResponseFile,
740779
GenerateCode, ListCodeGenerator, HistoryGenerateCode,
741780
PopularHeaders,

e2e/entrypoint.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ atest extension --output /usr/local/bin --registry ghcr.io mongodb
3232

3333
echo "start to run server"
3434
nohup atest server --tls-grpc --cert-file test.pem --key-file test.key&
35-
cmd="atest run -p test-suite-common.yaml"
35+
cmd="atest run -p test-suite-common.yaml --request-ignore-error"
3636

3737
echo "start to run testing: $cmd"
3838
kind=orm target=mysql:3306 driver=mysql $cmd

e2e/test-suite-common.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ param:
88
caseName: "{{randAlpha 6}}"
99
gRPCSuiteName: "{{randAlpha 6}}"
1010
gRPCCaseName: "{{randAlpha 6}}"
11-
store: "{{randAlpha 3}}"
11+
store: |
12+
{{randAlpha 6}}-{{env "kind"}}
1213
server: |
1314
{{default "http://localhost:8080" (env "SERVER")}}
1415
items:

pkg/runner/http.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,6 @@ func ammendHeaders(headers http.Header, body []byte) {
237237
if val := headers.Get(util.ContentLength); val == "" {
238238
headers.Add(util.ContentLength, strconv.Itoa(len(body)))
239239
fmt.Printf("add content-length: %d\n", len(body))
240-
} else {
241-
fmt.Printf("content-length already exist: %s\n", val)
242240
}
243241
}
244242

pkg/server/remote_server.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,14 @@ func (s *server) DuplicateTestSuite(ctx context.Context, in *TestSuiteDuplicate)
626626
return
627627
}
628628

629+
func (s *server) RenameTestSuite(ctx context.Context, in *TestSuiteDuplicate) (reply *HelloReply, err error) {
630+
reply = &HelloReply{}
631+
loader := s.getLoader(ctx)
632+
defer loader.Close()
633+
err = loader.RenameTestSuite(in.SourceSuiteName, in.TargetSuiteName)
634+
return
635+
}
636+
629637
func (s *server) ListTestCase(ctx context.Context, in *TestSuiteIdentity) (result *Suite, err error) {
630638
var items []testing.TestCase
631639
loader := s.getLoader(ctx)
@@ -914,6 +922,14 @@ func (s *server) DuplicateTestCase(ctx context.Context, in *TestCaseDuplicate) (
914922
return
915923
}
916924

925+
func (s *server) RenameTestCase(ctx context.Context, in *TestCaseDuplicate) (result *HelloReply, err error) {
926+
result = &HelloReply{}
927+
loader := s.getLoader(ctx)
928+
defer loader.Close()
929+
err = loader.RenameTestCase(in.SourceSuiteName, in.SourceCaseName, in.TargetCaseName)
930+
return
931+
}
932+
917933
// code generator
918934
func (s *server) ListCodeGenerator(ctx context.Context, in *Empty) (reply *SimpleList, err error) {
919935
reply = &SimpleList{}

pkg/server/remote_server_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,20 @@ func TestUpdateTestCase(t *testing.T) {
397397
testCase, err = server.GetTestCase(ctx, &TestCaseIdentity{Suite: "simple", Testcase: "get"})
398398
assert.Nil(t, testCase)
399399
assert.Error(t, err)
400+
401+
_, err = server.RenameTestCase(ctx, &TestCaseDuplicate{
402+
SourceCaseName: "get",
403+
SourceSuiteName: "simple",
404+
TargetCaseName: "get2",
405+
})
406+
assert.Error(t, err)
407+
408+
// rename test suite
409+
_, err = server.RenameTestSuite(ctx, &TestSuiteDuplicate{
410+
SourceSuiteName: "simple",
411+
TargetSuiteName: "simple2",
412+
})
413+
assert.NoError(t, err)
400414
})
401415
}
402416

0 commit comments

Comments
 (0)