mirror of
https://github.com/hoppscotch/hoppscotch
synced 2024-11-21 22:50:51 +00:00
feat: add button to export test results as json (#4419)
Co-authored-by: nivedin <nivedinp@gmail.com>
This commit is contained in:
parent
20c4767dce
commit
936c97b53a
@ -20,6 +20,7 @@
|
|||||||
"dismiss": "Dismiss",
|
"dismiss": "Dismiss",
|
||||||
"dont_save": "Don't save",
|
"dont_save": "Don't save",
|
||||||
"download_file": "Download file",
|
"download_file": "Download file",
|
||||||
|
"download_test_report": "Download test report",
|
||||||
"drag_to_reorder": "Drag to reorder",
|
"drag_to_reorder": "Drag to reorder",
|
||||||
"duplicate": "Duplicate",
|
"duplicate": "Duplicate",
|
||||||
"edit": "Edit",
|
"edit": "Edit",
|
||||||
|
@ -14,12 +14,20 @@
|
|||||||
<label class="truncate font-semibold text-secondaryLight">
|
<label class="truncate font-semibold text-secondaryLight">
|
||||||
{{ t("test.report") }}
|
{{ t("test.report") }}
|
||||||
</label>
|
</label>
|
||||||
<HoppButtonSecondary
|
<div>
|
||||||
v-tippy="{ theme: 'tooltip' }"
|
<HoppButtonSecondary
|
||||||
:title="t('action.clear')"
|
v-tippy="{ theme: 'tooltip' }"
|
||||||
:icon="IconTrash2"
|
:title="t('action.download_test_report')"
|
||||||
@click="clearContent()"
|
:icon="IconDownload"
|
||||||
/>
|
@click="downloadTestResult"
|
||||||
|
/>
|
||||||
|
<HoppButtonSecondary
|
||||||
|
v-tippy="{ theme: 'tooltip' }"
|
||||||
|
:title="t('action.clear')"
|
||||||
|
:icon="IconTrash2"
|
||||||
|
@click="clearContent()"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="divide-y-4 divide-dividerLight border-b border-dividerLight">
|
<div class="divide-y-4 divide-dividerLight border-b border-dividerLight">
|
||||||
<div v-if="haveEnvVariables" class="flex flex-col">
|
<div v-if="haveEnvVariables" class="flex flex-col">
|
||||||
@ -214,11 +222,13 @@ import {
|
|||||||
selectedEnvironmentIndex$,
|
selectedEnvironmentIndex$,
|
||||||
setSelectedEnvironmentIndex,
|
setSelectedEnvironmentIndex,
|
||||||
} from "~/newstore/environments"
|
} from "~/newstore/environments"
|
||||||
|
import { exportTestResults } from "~/helpers/import-export/export/testResults"
|
||||||
|
|
||||||
import IconCheck from "~icons/lucide/check"
|
import IconCheck from "~icons/lucide/check"
|
||||||
import IconExternalLink from "~icons/lucide/external-link"
|
import IconExternalLink from "~icons/lucide/external-link"
|
||||||
import IconTrash2 from "~icons/lucide/trash-2"
|
import IconTrash2 from "~icons/lucide/trash-2"
|
||||||
import IconClose from "~icons/lucide/x"
|
import IconClose from "~icons/lucide/x"
|
||||||
|
import IconDownload from "~icons/lucide/download"
|
||||||
|
|
||||||
import { GlobalEnvironment } from "@hoppscotch/data"
|
import { GlobalEnvironment } from "@hoppscotch/data"
|
||||||
import { useVModel } from "@vueuse/core"
|
import { useVModel } from "@vueuse/core"
|
||||||
@ -307,4 +317,9 @@ const addEnvToGlobal = () => {
|
|||||||
isSecret: false,
|
isSecret: false,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const downloadTestResult = () => {
|
||||||
|
if (!testResults.value) return
|
||||||
|
exportTestResults(testResults.value)
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
@ -0,0 +1,29 @@
|
|||||||
|
import { HoppTestResult } from "~/helpers/types/HoppTestResult"
|
||||||
|
import { platform } from "~/platform"
|
||||||
|
import * as E from "fp-ts/Either"
|
||||||
|
|
||||||
|
export const exportTestResults = async (testResults: HoppTestResult) => {
|
||||||
|
const contentsJSON = JSON.stringify(testResults, null, 2)
|
||||||
|
const file = new Blob([contentsJSON], { type: "application/json" })
|
||||||
|
const url = URL.createObjectURL(file)
|
||||||
|
|
||||||
|
const fileName = url.split("/").pop()!.split("#")[0].split("?")[0]
|
||||||
|
|
||||||
|
const result = await platform.io.saveFileWithDialog({
|
||||||
|
data: contentsJSON,
|
||||||
|
contentType: "application/json",
|
||||||
|
suggestedFilename: `${fileName}.json`,
|
||||||
|
filters: [
|
||||||
|
{
|
||||||
|
name: "Hoppscotch Test Results JSON file",
|
||||||
|
extensions: ["json"],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
})
|
||||||
|
|
||||||
|
if (result.type === "unknown" || result.type === "saved") {
|
||||||
|
return E.right("state.download_started")
|
||||||
|
}
|
||||||
|
|
||||||
|
return E.left("state.download_failed")
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user