Skip to content

Commit 3477034

Browse files
authored
chore: avoid menu duplicated (#803)
* chore: avoid menu duplicated * fix the issue that extesion js cannot be loaded * support to verify the template funcs * add unit tests * get extension list from API * using api calling to replace extension define in vue * fix some small issues * fix the unit test fail * remove unit tests of store from ts * move data-manager page into the extension --------- Co-authored-by: rick <[email protected]>
1 parent 4ac2eaa commit 3477034

24 files changed

+1549
-1675
lines changed

cmd/function.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package cmd
1818

1919
import (
2020
"context"
21+
"errors"
2122
"fmt"
2223
"go/ast"
2324
"go/doc"
@@ -44,14 +45,27 @@ func createFunctionCmd() (c *cobra.Command) {
4445
}
4546
flags := c.Flags()
4647
flags.StringVarP(&opt.feature, "feature", "", "", "The feature query")
48+
flags.StringVarP(&opt.extensionFile, "extension-file", "", "", "The extension file")
4749
return
4850
}
4951

5052
type funcPrinterOption struct {
51-
feature string
53+
feature string
54+
extensionFile string
5255
}
5356

5457
func (o *funcPrinterOption) runE(cmd *cobra.Command, args []string) (err error) {
58+
if o.extensionFile != "" {
59+
var tpl *render.UserDefinedTemplates
60+
if tpl, err = render.ParseUserDefinedTemplatesFromFile(o.extensionFile); err != nil {
61+
return
62+
}
63+
64+
if err = errors.Join(err, tpl.Validate(), tpl.ConflictWith(render.FuncMap())); err != nil {
65+
return
66+
}
67+
}
68+
5569
if len(args) > 0 {
5670
name := args[0]
5771
filterAndPrint(cmd, name)

cmd/function_test.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ func TestCreateFunctionCommand(t *testing.T) {
2929
tests := []struct {
3030
name string
3131
args []string
32+
hasErr bool
3233
verify func(t *testing.T, output string)
3334
}{{
3435
name: "normal",
@@ -61,6 +62,13 @@ func TestCreateFunctionCommand(t *testing.T) {
6162
assert.Equal(t, `{{generateJSONString "name"}}
6263
`, output)
6364
},
65+
}, {
66+
name: "verify template functions with error",
67+
args: []string{"func", "--extension-file", "testdata/function-with-conflicts.yaml"},
68+
hasErr: true,
69+
verify: func(t *testing.T, output string) {
70+
assert.Contains(t, output, "conflict with existing function")
71+
},
6472
}}
6573
for _, tt := range tests {
6674
t.Run(tt.name, func(t *testing.T) {
@@ -69,10 +77,15 @@ func TestCreateFunctionCommand(t *testing.T) {
6977

7078
buf := new(bytes.Buffer)
7179
c.SetOut(buf)
80+
c.SetErr(buf)
7281
c.SetArgs(tt.args)
7382

7483
err := c.Execute()
75-
assert.NoError(t, err)
84+
if tt.hasErr {
85+
assert.Error(t, err)
86+
} else {
87+
assert.NoError(t, err)
88+
}
7689

7790
if tt.verify != nil {
7891
tt.verify(t, buf.String())
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
items:
2+
- name: randEnum
3+
render: |
4+
{{ randInt 18 60 }}

console/atest-ui/src/App.vue

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
Guide,
99
DataAnalysis, Help, Setting
1010
} from '@element-plus/icons-vue'
11+
import * as ElementPlusIcons from '@element-plus/icons-vue'
1112
import { ref, watch, getCurrentInstance} from 'vue'
1213
import { API } from './views/net'
1314
import { Cache } from './views/cache'
@@ -16,7 +17,6 @@ import TestingHistoryPanel from './views/TestingHistoryPanel.vue'
1617
import MockManager from './views/MockManager.vue'
1718
import StoreManager from './views/StoreManager.vue'
1819
import WelcomePage from './views/WelcomePage.vue'
19-
import DataManager from './views/DataManager.vue'
2020
import MagicKey from './components/MagicKey.vue'
2121
import Extension from './views/Extension.vue'
2222
import { useI18n } from 'vue-i18n'
@@ -152,17 +152,13 @@ API.GetMenus((menus) => {
152152
<el-icon><Guide /></el-icon>
153153
<template #title>{{ t('title.mock' )}}</template>
154154
</el-menu-item>
155-
<el-menu-item index="data" test-id="data-menu">
156-
<el-icon><DataAnalysis /></el-icon>
157-
<template #title>{{ t('title.data' )}}</template>
158-
</el-menu-item>
159155
<el-menu-item index="store">
160156
<el-icon><location /></el-icon>
161157
<template #title>{{ t('title.stores') }}</template>
162158
</el-menu-item>
163159
<span v-for="menu in extensionMenus" :key="menu.index" :index="menu.index">
164160
<el-menu-item :index="menu.index">
165-
<el-icon><IconMenu /></el-icon>
161+
<el-icon><component :is="ElementPlusIcons[menu.icon]" /></el-icon>
166162
<template #title>{{ menu.name }}</template>
167163
</el-menu-item>
168164
</span>
@@ -177,7 +173,6 @@ API.GetMenus((menus) => {
177173
</div>
178174
<TestingPanel v-if="panelName === 'testing'" @toHistoryPanel="toHistoryPanel"/>
179175
<TestingHistoryPanel v-else-if="panelName === 'history'" :ID="ID"/>
180-
<DataManager v-else-if="panelName === 'data'" />
181176
<MockManager v-else-if="panelName === 'mock'" />
182177
<StoreManager v-else-if="panelName === 'store'" />
183178
<WelcomePage v-else-if="panelName === 'welcome' || panelName === ''" />

0 commit comments

Comments
 (0)