Skip to content

Commit 8da83f3

Browse files
authored
feat: support update and delete testsuite on UI (#119)
1 parent 9bdef10 commit 8da83f3

12 files changed

+962
-321
lines changed

console/atest-ui/src/App.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ function loadTestSuites() {
6767
treeRef.value!.setCurrentKey(child)
6868
treeRef.value!.setCheckedKeys([child], false)
6969
}
70+
71+
viewName.value = "testsuite"
72+
testSuite.value = firstItem.label
7073
}
7174
});
7275
}
@@ -138,7 +141,7 @@ const viewName = ref('testcase')
138141

139142
<el-main>
140143
<TestCase v-if="viewName === 'testcase'" :suite="testSuite" :name="testCaseName" @updated="loadTestSuites"/>
141-
<TestSuite v-else-if="viewName === 'testsuite'" :name="testSuite"/>
144+
<TestSuite v-else-if="viewName === 'testsuite'" :name="testSuite" @updated="loadTestSuites"/>
142145
</el-main>
143146
</el-container>
144147
</div>

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,13 @@ const emptyTestCaseWithSuite: TestCaseWithSuite = {
9191
9292
const testCaseWithSuite = ref(emptyTestCaseWithSuite)
9393
94-
watch(props, (p) => {
95-
const name = p.name
96-
const suite = p.suite
94+
function load() {
95+
const name = props.name
96+
const suite = props.suite
97+
if (name === "" || suite === "") {
98+
return
99+
}
100+
97101
const requestOptions = {
98102
method: 'POST',
99103
body: JSON.stringify({
@@ -136,8 +140,12 @@ watch(props, (p) => {
136140
testCaseWithSuite.value = {
137141
suiteName: suite,
138142
data: e
139-
}
143+
} as TestCaseWithSuite;
140144
});
145+
}
146+
load()
147+
watch(props, () => {
148+
load()
141149
})
142150
143151
interface TestCaseWithSuite{
Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,85 @@
11
<script setup lang="ts">
2+
import { ref, watch } from 'vue'
3+
import { ElMessage } from 'element-plus'
4+
25
const props = defineProps({
36
name: String,
47
})
8+
const emit = defineEmits(['updated'])
9+
10+
interface Suite {
11+
name: string;
12+
api: string;
13+
}
14+
15+
const suite = ref({} as Suite)
16+
function load() {
17+
const requestOptions = {
18+
method: 'POST',
19+
body: JSON.stringify({
20+
name: props.name,
21+
})
22+
};
23+
fetch('/server.Runner/GetTestSuite', requestOptions)
24+
.then(response => response.json())
25+
.then(e => {
26+
suite.value = {
27+
name: e.name,
28+
api: e.api,
29+
} as Suite
30+
}).catch(e => {
31+
ElMessage.error('Oops, ' + e)
32+
});
33+
}
34+
load()
35+
watch(props, () => {
36+
load()
37+
})
38+
39+
function save() {
40+
const requestOptions = {
41+
method: 'POST',
42+
body: JSON.stringify(suite.value),
43+
};
44+
fetch('/server.Runner/UpdateTestSuite', requestOptions)
45+
.then(response => response.json())
46+
.then(e => {
47+
ElMessage({
48+
message: 'Updated.',
49+
type: 'success',
50+
})
51+
}).catch(e => {
52+
ElMessage.error('Oops, ' + e)
53+
});
54+
}
55+
56+
function del() {
57+
const requestOptions = {
58+
method: 'POST',
59+
body: JSON.stringify({
60+
name: props.name,
61+
})
62+
};
63+
fetch('/server.Runner/DeleteTestSuite', requestOptions)
64+
.then(response => response.json())
65+
.then(e => {
66+
ElMessage({
67+
message: 'Deleted.',
68+
type: 'success',
69+
})
70+
emit('updated')
71+
}).catch(e => {
72+
ElMessage.error('Oops, ' + e)
73+
});
74+
}
575
</script>
676

777
<template>
878
<div class="common-layout">
9-
<el-text class="mx-1" type="primary">{{props.name}}</el-text>
79+
<el-text class="mx-1" type="primary">{{suite.name}}</el-text>
80+
<el-input class="mx-1" v-model="suite.api" placeholder="API"></el-input>
81+
82+
<el-button type="primary" @click="save">Save</el-button>
83+
<el-button type="primary" @click="del">Delete</el-button>
1084
</div>
1185
</template>

pkg/server/remote_server.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,29 @@ func (s *server) CreateTestSuite(ctx context.Context, in *TestSuiteIdentity) (re
449449
return
450450
}
451451

452+
func (s *server) GetTestSuite(ctx context.Context, in *TestSuiteIdentity) (result *TestSuite, err error) {
453+
var suite *testing.TestSuite
454+
if suite, _, err = s.loader.GetSuite(in.Name); err == nil && suite != nil {
455+
result = &TestSuite{
456+
Name: suite.Name,
457+
Api: suite.API,
458+
}
459+
}
460+
return
461+
}
462+
463+
func (s *server) UpdateTestSuite(ctx context.Context, in *TestSuite) (reply *HelloReply, err error) {
464+
reply = &HelloReply{}
465+
err = s.loader.UpdateSuite(in.Name, in.Api)
466+
return
467+
}
468+
469+
func (s *server) DeleteTestSuite(ctx context.Context, in *TestSuiteIdentity) (reply *HelloReply, err error) {
470+
reply = &HelloReply{}
471+
err = s.loader.DeleteSuite(in.Name)
472+
return
473+
}
474+
452475
func (s *server) DeleteTestCase(ctx context.Context, in *TestCaseIdentity) (reply *HelloReply, err error) {
453476
err = s.loader.DeleteTestCase(in.Suite, in.Testcase)
454477
return

pkg/server/remote_server_test.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,53 @@ func TestUpdateTestCase(t *testing.T) {
333333
grpcRequestToRaw(nil) // avoid panic
334334
}
335335

336+
func TestRemoteServerSuite(t *testing.T) {
337+
t.Run("Get suite not found", func(t *testing.T) {
338+
writer := atesting.NewFileWriter("")
339+
ctx := context.Background()
340+
server := NewRemoteServer(writer)
341+
342+
suite, err := server.GetTestSuite(ctx, &TestSuiteIdentity{Name: "fake"})
343+
assert.NoError(t, err)
344+
assert.Nil(t, suite)
345+
})
346+
347+
t.Run("Get existing suite", func(t *testing.T) {
348+
writer := atesting.NewFileWriter(os.TempDir())
349+
ctx := context.Background()
350+
server := NewRemoteServer(writer)
351+
352+
// create a new suite
353+
_, err := server.CreateTestSuite(ctx, &TestSuiteIdentity{Name: "fake"})
354+
assert.NoError(t, err)
355+
356+
suite, err := server.GetTestSuite(ctx, &TestSuiteIdentity{Name: "fake"})
357+
assert.NoError(t, err)
358+
if assert.NotNil(t, suite) {
359+
assert.Equal(t, "fake", suite.Name)
360+
}
361+
362+
_, err = server.UpdateTestSuite(ctx, &TestSuite{Name: "fake", Api: "http://foo"})
363+
assert.NoError(t, err)
364+
365+
// check if the value was updated successfully
366+
suite, err = server.GetTestSuite(ctx, &TestSuiteIdentity{Name: "fake"})
367+
assert.NoError(t, err)
368+
if assert.NotNil(t, suite) {
369+
assert.Equal(t, "http://foo", suite.Api)
370+
}
371+
})
372+
373+
t.Run("Delete non-exist suite", func(t *testing.T) {
374+
writer := atesting.NewFileWriter(os.TempDir())
375+
ctx := context.Background()
376+
server := NewRemoteServer(writer)
377+
378+
_, err := server.DeleteTestSuite(ctx, &TestSuiteIdentity{Name: "fake"})
379+
assert.Error(t, err)
380+
})
381+
}
382+
336383
//go:embed testdata/simple.yaml
337384
var simpleSuite string
338385

0 commit comments

Comments
 (0)