api-client/components/http/Tests.vue

127 lines
3.2 KiB
Vue
Raw Normal View History

<template>
<AppSection label="postRequestTests">
<div
class="
bg-primary
border-b border-dividerLight
flex flex-1
pl-4
2021-07-26 03:38:06 +00:00
top-24
z-10
sticky
items-center
justify-between
"
>
<label class="font-semibold">
{{ $t("javascript_code") }}
</label>
<ButtonSecondary
v-tippy="{ theme: 'tooltip' }"
to="https://github.com/hoppscotch/hoppscotch/wiki/Post-Request-Tests"
blank
:title="$t('wiki')"
icon="help_outline"
/>
</div>
<SmartJsEditor
v-model="testScript"
:options="{
maxLines: 16,
minLines: 8,
fontSize: '12px',
autoScrollEditorIntoView: true,
showPrintMargin: false,
useWorker: false,
}"
complete-mode="test"
/>
2021-07-22 18:37:39 +00:00
<div v-if="testResults">
<div
class="
bg-primary
border-b border-dividerLight
flex flex-1
pl-4
2021-07-26 03:38:06 +00:00
top-24
z-10
sticky
items-center
justify-between
"
>
2021-07-22 18:37:39 +00:00
<div>
<label class="font-semibold"> Test Report </label>
2021-07-24 08:40:28 +00:00
</div>
<ButtonSecondary
v-tippy="{ theme: 'tooltip' }"
:title="$t('clear')"
icon="clear_all"
@click.native="clearContent()"
/>
</div>
<div class="flex my-4 items-center">
<div class="ml-4">
<span class="font-semibold text-red-500">
2021-07-22 18:37:39 +00:00
{{ failedTests }} failing,
</span>
<span class="font-semibold text-green-500">
2021-07-22 18:37:39 +00:00
{{ passedTests }} successful,
</span>
<span class="font-semibold"> out of {{ totalTests }} tests. </span>
2021-07-22 18:37:39 +00:00
</div>
2021-07-24 08:40:28 +00:00
<div class="bg-primaryDark flex space-x-2 flex-1 h-1 mx-4 relative">
<div
class="rounded h-full bg-green-500"
:style="`width: ${(passedTests / totalTests) * 100 + '%'}`"
></div>
<div
class="rounded h-full bg-red-500"
:style="`width: ${(failedTests / totalTests) * 100 + '%'}`"
></div>
</div>
</div>
2021-07-24 08:40:28 +00:00
<HttpTestResult :results="testResults" />
</div>
</AppSection>
</template>
<script lang="ts">
import { defineComponent } from "@nuxtjs/composition-api"
2021-07-22 18:37:39 +00:00
import {
useTestScript,
restTestResults$,
setRESTTestResults,
} from "~/newstore/RESTSession"
import { useReadonlyStream } from "~/helpers/utils/composables"
export default defineComponent({
setup() {
return {
testScript: useTestScript(),
testResults: useReadonlyStream(restTestResults$, null),
}
},
2021-07-22 18:37:39 +00:00
computed: {
2021-07-24 21:45:48 +00:00
totalTests(): number | undefined {
return this.testResults?.expectResults.length
2021-07-22 18:37:39 +00:00
},
2021-07-24 21:45:48 +00:00
failedTests(): number | undefined {
return this.testResults?.expectResults.filter(
2021-07-24 10:58:32 +00:00
(result: { status: string }) => result.status === "fail"
2021-07-22 18:37:39 +00:00
).length
},
2021-07-24 21:45:48 +00:00
passedTests(): number | undefined {
return this.testResults?.expectResults.filter(
2021-07-24 10:58:32 +00:00
(result: { status: string }) => result.status === "pass"
2021-07-22 18:37:39 +00:00
).length
},
},
methods: {
clearContent() {
setRESTTestResults(null)
},
},
})
</script>