Skip to content

Commit 2b98b95

Browse files
authored
feat: support test case nav via shortcut (#510)
Co-authored-by: rick <[email protected]>
1 parent 491ebdf commit 2b98b95

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

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

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import type { Suite } from './types'
1010
import { API } from './net'
1111
import { Cache } from './cache'
1212
import { useI18n } from 'vue-i18n'
13+
import { Magic } from './magicKeys'
1314
1415
const { t } = useI18n()
1516
@@ -61,6 +62,39 @@ const handleTreeClick = (data: Tree) => {
6162
}
6263
}
6364
65+
Magic.Keys((k) => {
66+
const currentKey = currentNodekey.value
67+
68+
if (treeRef.value) {
69+
treeRef.value.data.forEach((n) => {
70+
if (n.children) {
71+
n.children.forEach((c, index) => {
72+
if (c.id === currentKey) {
73+
var nextIndex = -1
74+
if (k.endsWith('Up')) {
75+
if (index > 0) {
76+
nextIndex = index - 1
77+
}
78+
} else {
79+
if (index < n.children.length - 1) {
80+
nextIndex = index + 1
81+
}
82+
}
83+
84+
if (nextIndex >= 0 < n.children.length) {
85+
const next = n.children[nextIndex]
86+
currentNodekey.value = next.id
87+
treeRef.value!.setCurrentKey(next.id)
88+
treeRef.value!.setCheckedKeys([next.id], false)
89+
}
90+
return
91+
}
92+
})
93+
}
94+
})
95+
}
96+
}, ['Alt+ArrowUp', 'Alt+ArrowDown'])
97+
6498
const treeData = ref([] as Tree[])
6599
const treeRef = ref<InstanceType<typeof ElTree>>()
66100
const currentNodekey = ref('')
@@ -327,7 +361,6 @@ const suiteKinds = [{
327361
ref="treeRef"
328362
node-key="id"
329363
:filter-node-method="filterTestCases"
330-
@node-click="handleTreeClick"
331364
@current-change="handleTreeClick"
332365
data-intro="This is the test suite tree. You can click the test suite to edit it."
333366
>

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ limitations under the License.
1717
import { watch } from 'vue'
1818
import { useMagicKeys } from '@vueuse/core'
1919

20-
function Keys(func: () => void, keys: string[]) {
20+
function Keys(func: (() => void) | ((k: string) => void), keys: string[]) {
2121
const magicKeys = useMagicKeys()
2222
keys.forEach(k => {
2323
watch(magicKeys[k], (v) => {
24-
if (v) func()
24+
if (v) func(k)
2525
})
2626
})
2727
}

0 commit comments

Comments
 (0)