Skip to content

Commit

Permalink
feat: support test case nav via shortcut
Browse files Browse the repository at this point in the history
  • Loading branch information
LinuxSuRen committed Jul 10, 2024
1 parent 491ebdf commit 7bd817e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
35 changes: 34 additions & 1 deletion console/atest-ui/src/views/TestingPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type { Suite } from './types'
import { API } from './net'
import { Cache } from './cache'
import { useI18n } from 'vue-i18n'
import { Magic } from './magicKeys'
const { t } = useI18n()
Expand Down Expand Up @@ -61,6 +62,39 @@ const handleTreeClick = (data: Tree) => {
}
}
Magic.Keys((k) => {
const currentKey = currentNodekey.value
if (treeRef.value) {
treeRef.value.data.forEach((n) => {
if (n.children) {
n.children.forEach((c, index) => {
if (c.id === currentKey) {
var nextIndex = -1
if (k.endsWith('Up')) {
if (index > 0) {
nextIndex = index - 1
}
} else {
if (index < n.children.length - 1) {
nextIndex = index + 1
}
}
if (nextIndex >= 0 < n.children.length) {
const next = n.children[nextIndex]
currentNodekey.value = next.id
treeRef.value!.setCurrentKey(next.id)
treeRef.value!.setCheckedKeys([next.id], false)
}
return
}
})
}
})
}
}, ['Alt+ArrowUp', 'Alt+ArrowDown'])
const treeData = ref([] as Tree[])
const treeRef = ref<InstanceType<typeof ElTree>>()
const currentNodekey = ref('')
Expand Down Expand Up @@ -327,7 +361,6 @@ const suiteKinds = [{
ref="treeRef"
node-key="id"
:filter-node-method="filterTestCases"
@node-click="handleTreeClick"
@current-change="handleTreeClick"
data-intro="This is the test suite tree. You can click the test suite to edit it."
>
Expand Down
4 changes: 2 additions & 2 deletions console/atest-ui/src/views/magicKeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ limitations under the License.
import { watch } from 'vue'
import { useMagicKeys } from '@vueuse/core'

function Keys(func: () => void, keys: string[]) {
function Keys(func: (() => void) | ((k: string) => void), keys: string[]) {
const magicKeys = useMagicKeys()
keys.forEach(k => {
watch(magicKeys[k], (v) => {
if (v) func()
if (v) func(k)
})
})
}
Expand Down

0 comments on commit 7bd817e

Please sign in to comment.