Skip to content

feat: support cache the test case response #194

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions console/atest-ui/src/views/TestCase.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { Edit, Delete } from '@element-plus/icons-vue'
import JsonViewer from 'vue-json-viewer'
import type { Pair, TestResult, TestCaseWithSuite } from './types'
import { NewSuggestedAPIsQuery, CreateFilter, GetHTTPMethods, FlattenObject } from './types'
import { GetTestCaseResponseCache, SetTestCaseResponseCache } from './cache'
import type { TestCaseResponse } from './cache'
import { useI18n } from 'vue-i18n'

const { t } = useI18n()
Expand Down Expand Up @@ -59,6 +61,11 @@ const sendRequest = async () => {
if (e.body !== '') {
testResult.value.bodyObject = JSON.parse(e.body)
}

SetTestCaseResponseCache(suite + '-' + name, {
body: testResult.value.bodyObject,
output: e.output
} as TestCaseResponse)
})
.catch((e) => {
requestLoading.value = false
Expand Down Expand Up @@ -151,6 +158,17 @@ function load() {
return
}

// load cache
console.log('load cache')
const cache = GetTestCaseResponseCache(suite + '-' + name)
if (cache.body) {
testResult.value.bodyObject = cache.body
testResult.value.output = cache.output
} else {
testResult.value.bodyObject = {}
testResult.value.output = ''
}

const requestOptions = {
method: 'POST',
headers: {
Expand Down
17 changes: 17 additions & 0 deletions console/atest-ui/src/views/cache.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export interface TestCaseResponse {
output: string
body: {}
}

export function GetTestCaseResponseCache(id: string) {
const val = sessionStorage.getItem(id)
if (val && val !== '') {
return JSON.parse(val)
} else {
return {} as TestCaseResponse
}
}

export function SetTestCaseResponseCache(id: string, resp: TestCaseResponse) {
sessionStorage.setItem(id, JSON.stringify(resp))
}