fix: the test suite tree cannot be selected (#503)

Co-authored-by: rick <LinuxSuRen@users.noreply.github.com>
This commit is contained in:
Rick 2024-07-02 15:29:13 +08:00 committed by GitHub
parent b7926da2c0
commit d9724e8d2d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 14 additions and 11 deletions

View File

@ -26,7 +26,7 @@ interface Tree {
const testCaseName = ref('') const testCaseName = ref('')
const testSuite = ref('') const testSuite = ref('')
const testSuiteKind = ref('') const testSuiteKind = ref('')
const handleNodeClick = (data: Tree) => { const handleTreeClick = (data: Tree) => {
if (data.children) { if (data.children) {
Cache.SetCurrentStore(data.store) Cache.SetCurrentStore(data.store)
viewName.value = 'testsuite' viewName.value = 'testsuite'
@ -59,7 +59,7 @@ const handleNodeClick = (data: Tree) => {
} }
} }
const data = ref([] as Tree[]) const treeData = ref([] as Tree[])
const treeRef = ref<InstanceType<typeof ElTree>>() const treeRef = ref<InstanceType<typeof ElTree>>()
const currentNodekey = ref('') const currentNodekey = ref('')
@ -97,7 +97,7 @@ function loadTestSuites(storeName: string) {
parentID: suite.id parentID: suite.id
} as Tree) } as Tree)
}) })
data.value.push(suite) treeData.value.push(suite)
}) })
}) })
} }
@ -122,7 +122,7 @@ function loadStores() {
.then(API.DefaultResponseProcess) .then(API.DefaultResponseProcess)
.then(async (d) => { .then(async (d) => {
stores.value = d.data stores.value = d.data
data.value = [] as Tree[] treeData.value = [] as Tree[]
Cache.SetStores(d.data) Cache.SetStores(d.data)
for (const item of d.data) { for (const item of d.data) {
@ -131,14 +131,14 @@ function loadStores() {
} }
} }
if (data.value.length > 0) { if (treeData.value.length > 0) {
const key = Cache.GetLastTestCaseLocation() const key = Cache.GetLastTestCaseLocation()
let targetSuite = {} as Tree let targetSuite = {} as Tree
let targetChild = {} as Tree let targetChild = {} as Tree
if (key.suite !== '' && key.testcase !== '') { if (key.suite !== '' && key.testcase !== '') {
for (var i = 0; i < data.value.length; i++) { for (var i = 0; i < treeData.value.length; i++) {
const item = data.value[i] const item = treeData.value[i]
if (item.id === key.suite && item.children) { if (item.id === key.suite && item.children) {
for (var j = 0; j < item.children.length; j++) { for (var j = 0; j < item.children.length; j++) {
const child = item.children[j] const child = item.children[j]
@ -154,7 +154,7 @@ function loadStores() {
} }
if (!targetChild.id || targetChild.id === '') { if (!targetChild.id || targetChild.id === '') {
targetSuite = data.value[0] targetSuite = treeData.value[0]
if (targetSuite.children && targetSuite.children.length > 0) { if (targetSuite.children && targetSuite.children.length > 0) {
targetChild = targetSuite.children[0] targetChild = targetSuite.children[0]
} }
@ -162,8 +162,10 @@ function loadStores() {
viewName.value = 'testsuite' viewName.value = 'testsuite'
currentNodekey.value = targetChild.id currentNodekey.value = targetChild.id
treeRef.value!.setCurrentKey(targetChild.id) treeRef.value!.setCurrentKey(targetChild.id)
treeRef.value!.setCheckedKeys([targetChild.id], false) treeRef.value!.setCheckedKeys([targetChild.id], false)
testSuite.value = targetSuite.label testSuite.value = targetSuite.label
Cache.SetCurrentStore(targetSuite.store ) Cache.SetCurrentStore(targetSuite.store )
testSuiteKind.value = targetChild.kind testSuiteKind.value = targetChild.kind
@ -261,7 +263,7 @@ watch(filterText, (val) => {
}) })
const filterTestCases = (value: string, data: Tree) => { const filterTestCases = (value: string, data: Tree) => {
if (!value) return true if (!value) return true
return data.label.includes(value) return data.label.toLocaleLowerCase().includes(value.toLocaleLowerCase())
} }
const viewName = ref('') const viewName = ref('')
@ -315,7 +317,7 @@ const suiteKinds = [{
<el-tree <el-tree
v-loading="storesLoading" v-loading="storesLoading"
:data=data :data=treeData
highlight-current highlight-current
:check-on-click-node="true" :check-on-click-node="true"
:expand-on-click-node="false" :expand-on-click-node="false"
@ -323,7 +325,8 @@ const suiteKinds = [{
ref="treeRef" ref="treeRef"
node-key="id" node-key="id"
:filter-node-method="filterTestCases" :filter-node-method="filterTestCases"
@node-click="handleNodeClick" @node-click="handleTreeClick"
@current-change="handleTreeClick"
data-intro="This is the test suite tree. You can click the test suite to edit it." data-intro="This is the test suite tree. You can click the test suite to edit it."
/> />
<TemplateFunctions/> <TemplateFunctions/>