-
Notifications
You must be signed in to change notification settings - Fork 68
Expand file tree
/
Copy pathTestingHistoryPanel.vue
More file actions
269 lines (243 loc) · 7.77 KB
/
Copy pathTestingHistoryPanel.vue
File metadata and controls
269 lines (243 loc) · 7.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
<script setup lang="ts">
import TestCase from './TestCase.vue'
import TemplateFunctions from './TemplateFunctions.vue'
import { ref, watch } from 'vue'
import { API } from './net'
import { ElTree, ElMessage } from 'element-plus'
import { Refresh } from '@element-plus/icons-vue'
import { Cache } from './cache'
import { useI18n } from 'vue-i18n'
const { t } = useI18n()
interface Tree {
id: string
label: string
parent: string
parentID: string
store: string
kind: string
suiteLabel: string
children?: Tree[]
}
const props = defineProps({
ID: String,
})
const testCaseName = ref('')
const testSuite = ref('')
const testKind = ref('')
const historySuiteName = ref('')
const historyCaseID = ref('')
const handleNodeClick = (data: Tree) => {
if (data.children) {
Cache.SetCurrentStore(data.store)
viewName.value = 'testsuite'
historySuiteName.value = data.label
Cache.SetCurrentStore(data.store)
API.ListTestCase(data.label, data.store, (d) => {
if (d.items && d.items.length > 0) {
data.children = []
d.items.forEach((item: any) => {
data.children?.push({
id: data.label,
label: item.name,
kind: data.kind,
store: data.store,
parent: data.label,
parentID: data.id
} as Tree)
})
}
})
} else {
Cache.SetCurrentStore(data.store)
Cache.SetLastTestCaseLocation(data.parentID, data.id)
historySuiteName.value = data.parent
testSuite.value = data.suiteLabel
testCaseName.value = data.label
historyCaseID.value = data.id
testKind.value = data.kind
viewName.value = 'testcase'
}
}
const treeData = ref([] as Tree[])
const treeRef = ref<InstanceType<typeof ElTree>>()
const currentNodekey = ref('')
function loadHistoryTestSuites(storeName: string) {
const requestOptions = {
method: 'POST',
headers: {
'X-Store-Name': storeName,
'X-Auth': API.getToken()
},
}
return async () => {
await fetch('/api/v1/historySuites', requestOptions)
.then((response) => response.json())
.then((d) => {
if (!d.data) {
return
}
const sortedKeys = Object.keys(d.data).sort((a, b) => new Date(a) - new Date(b));
sortedKeys.map((k) => {
let suite = {
id: k,
label: k,
store: storeName,
children: [] as Tree[]
} as Tree
d.data[k].data.forEach((item: any) => {
suite.children?.push({
id: item.ID,
label: item.testcase,
suiteLabel: item.suite,
store: storeName,
kind: item.kind,
parent: k,
parentID: suite.id
} as Tree)
})
treeData.value.push(suite)
})
})
}
}
function generateTestCaseID(suiteName: string, caseName: string) {
return suiteName + caseName
}
interface Store {
name: string,
description: string,
}
const loginDialogVisible = ref(false)
const stores = ref([] as Store[])
const storesLoading = ref(false)
function loadStores(lastSuitName?: string, lastCaseName?: string) {
if (lastSuitName && lastCaseName && lastSuitName !== '' && lastCaseName !== '') {
// get data from emit event
Cache.SetLastTestCaseLocation(lastSuitName, generateTestCaseID(lastSuitName, lastCaseName))
}
storesLoading.value = true
const requestOptions = {
headers: {
'X-Auth': API.getToken()
}
}
fetch('/api/v1/stores', requestOptions)
.then(API.DefaultResponseProcess)
.then(async (d) => {
stores.value = d.data
treeData.value = [] as Tree[]
Cache.SetStores(d.data)
for (const item of d.data) {
if (item.ready && !item.disabled) {
await loadHistoryTestSuites(item.name)()
}
}
if (treeData.value.length > 0) {
const key = Cache.GetLastTestCaseLocation()
let targetSuite = {} as Tree
let targetChild = {} as Tree
const targetID = props.ID
if (targetID && targetID !== '') {
for (const suite of treeData.value) {
if (suite.children) {
const foundChild = suite.children.find(child => child.id === targetID)
if (foundChild) {
targetSuite = suite
targetChild = foundChild
handleNodeClick(targetChild)
updateTreeSelection(targetSuite, targetChild)
return
}
}
}
} else {
if (key.suite !== '' && key.testcase !== '') {
for (var i = 0; i < treeData.value.length; i++) {
const item = treeData.value[i]
if (item.id === key.suite && item.children) {
for (var j = 0; j < item.children.length; j++) {
const child = item.children[j]
if (child.id === key.testcase) {
targetSuite = item
targetChild = child
break
}
}
break
}
}
}
}
if (!targetChild.id || targetChild.id === '') {
targetSuite = treeData.value[0]
if (targetSuite.children && targetSuite.children.length > 0) {
targetChild = targetSuite.children[0]
}
}
viewName.value = 'testsuite'
updateTreeSelection(targetSuite, targetChild)
} else {
viewName.value = ""
}
}).catch((e) => {
if (e.message === "Unauthenticated") {
loginDialogVisible.value = true
} else {
ElMessage.error('Oops, ' + e)
}
}).finally(() => {
storesLoading.value = false
})
}
loadStores()
function updateTreeSelection(targetSuite: Tree, targetChild: Tree) {
currentNodekey.value = targetChild.id
treeRef.value!.setCurrentKey(targetChild.id)
treeRef.value!.setCheckedKeys([targetChild.id], false)
testSuite.value = targetSuite.label
Cache.SetCurrentStore(targetSuite.store)
testKind.value = targetChild.kind
}
const filterText = ref('')
watch(filterText, (val) => {
treeRef.value!.filter(val)
})
const filterTestCases = (value: string, data: Tree) => {
if (!value) return true
return data.label.includes(value)
}
const viewName = ref('')
</script>
<template>
<div class="h-full" data-title="Welcome!" data-intro="Welcome to use api-testing! 👋">
<el-container class="h-[100%]">
<el-main class="pt-[5px] pb-[5px]">
<el-container class="h-[100%]">
<el-aside>
<el-button type="primary" @click="loadStores" :icon="Refresh">{{ t('button.refresh') }}</el-button>
<el-input v-model="filterText" :placeholder="t('tip.filter')" test-id="search" class="p-[5px]" />
<el-tree
v-loading="storesLoading"
:data=treeData
highlight-current
:check-on-click-node="true"
:expand-on-click-node="false"
:current-node-key="currentNodekey"
ref="treeRef"
node-key="id"
:filter-node-method="filterTestCases"
@node-click="handleNodeClick"
data-intro="This is the test history tree. You can click the history test to browse it."
/>
<TemplateFunctions />
</el-aside>
<el-main class="pt-[0px] pr-[0px] pb-[0px]">
<TestCase v-if="viewName === 'testcase'" :suite="testSuite" :kindName="testKind" :name="testCaseName"
:historySuiteName="historySuiteName" :historyCaseID="historyCaseID" @updated="loadStores" class="h-[100%]"
data-intro="This is the test case editor. You can edit the test case here." />
</el-main>
</el-container>
</el-main>
</el-container>
</div>
</template>