Skip to content

Commit c585439

Browse files
authored
feat: support the auto-complete of header values (#337)
Co-authored-by: rick <LinuxSuRen@users.noreply.github.com>
1 parent 96f2d29 commit c585439

3 files changed

Lines changed: 52 additions & 4 deletions

File tree

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

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,19 @@ function headerChange() {
354354
} as Pair)
355355
}
356356
}
357+
358+
const headerValues = ref([] as Pair[])
359+
const headerSelect = (item: Record<string, any>) => {
360+
headerValues.value = []
361+
pupularHeaderPairs.value.filter((v) => {
362+
if (v.key === item.value) {
363+
headerValues.value.push({
364+
key: v.value,
365+
value: v.value
366+
} as Pair)
367+
}
368+
})
369+
}
357370
function expectedHeaderChange() {
358371
const header = testCaseWithSuite.value.data.response.header
359372
let lastItem = header[header.length - 1]
@@ -420,8 +433,26 @@ function insertOrUpdateIntoMap(pair: Pair, pairs: Pair[]) {
420433
}
421434
422435
const pupularHeaders = ref([] as Pair[])
436+
const pupularHeaderPairs = ref([] as Pair[])
423437
API.PopularHeaders((e) => {
424-
pupularHeaders.value = e.data
438+
const headerCache = new Map<string, string>();
439+
for (var i = 0; i < e.data.length; i++) {
440+
const pair = {
441+
key: e.data[i].key,
442+
value: e.data[i].value
443+
} as Pair
444+
445+
pupularHeaderPairs.value.push(pair)
446+
447+
if (!headerCache.get(pair.key)) {
448+
headerCache.set(pair.key, "index")
449+
450+
pupularHeaders.value.push({
451+
key: e.data[i].key,
452+
value: e.data[i].value
453+
} as Pair)
454+
}
455+
}
425456
})
426457
427458
const queryPupularHeaders = (queryString: string, cb: (arg: any) => void) => {
@@ -434,6 +465,16 @@ const queryPupularHeaders = (queryString: string, cb: (arg: any) => void) => {
434465
})
435466
cb(results)
436467
}
468+
const queryHeaderValues = (queryString: string, cb: (arg: any) => void) => {
469+
const results = queryString
470+
? headerValues.value.filter(CreateFilter(queryString))
471+
: headerValues.value
472+
473+
results.forEach((e) => {
474+
e.value = e.key
475+
})
476+
cb(results)
477+
}
437478
</script>
438479

439480
<template>
@@ -520,13 +561,18 @@ const queryPupularHeaders = (queryString: string, cb: (arg: any) => void) => {
520561
:fetch-suggestions="queryPupularHeaders"
521562
placeholder="Key"
522563
@change="headerChange"
564+
@select="headerSelect"
523565
/>
524566
</template>
525567
</el-table-column>
526568
<el-table-column label="Value">
527569
<template #default="scope">
528570
<div style="display: flex; align-items: center">
529-
<el-input v-model="scope.row.value" placeholder="Value" />
571+
<el-autocomplete
572+
v-model="scope.row.value"
573+
:fetch-suggestions="queryHeaderValues"
574+
style="width: 100%;"
575+
/>
530576
</div>
531577
</template>
532578
</el-table-column>

pkg/server/data/headers.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@
77
- key: Accept-Language
88
value: en-US,en;q=0.5
99
- key: Authorization
10-
value: "Bearer token"
10+
value: "Bearer token"
11+
- key: Authorization
12+
value: Basic {{ base64 "admin:123456" }}

pkg/server/remote_server_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ func TestPopularHeaders(t *testing.T) {
487487

488488
pairs, err := server.PopularHeaders(ctx, &Empty{})
489489
if assert.NoError(t, err) {
490-
assert.Equal(t, 5, len(pairs.Data))
490+
assert.Equal(t, 6, len(pairs.Data))
491491
}
492492
}
493493

0 commit comments

Comments
 (0)