TestResult.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <template>
  2. <AppSection :label="`${$t('test.results')}`">
  3. <div
  4. v-if="
  5. testResults &&
  6. (testResults.expectResults.length || testResults.tests.length)
  7. "
  8. >
  9. <div
  10. class="
  11. bg-primary
  12. border-dividerLight border-b
  13. flex flex-1
  14. top-lowerSecondaryStickyFold
  15. pl-4
  16. z-10
  17. sticky
  18. items-center
  19. justify-between
  20. "
  21. >
  22. <label class="font-semibold text-secondaryLight">
  23. {{ $t("test.report") }}
  24. </label>
  25. <ButtonSecondary
  26. v-tippy="{ theme: 'tooltip' }"
  27. :title="$t('action.clear')"
  28. svg="trash-2"
  29. @click.native="clearContent()"
  30. />
  31. </div>
  32. <div class="divide-dividerLight border-dividerLight border-b divide-y-4">
  33. <div v-if="testResults.tests" class="divide-dividerLight divide-y-4">
  34. <HttpTestResultEntry
  35. v-for="(result, index) in testResults.tests"
  36. :key="`result-${index}`"
  37. :test-results="result"
  38. />
  39. </div>
  40. <div
  41. v-if="testResults.expectResults"
  42. class="divide-dividerLight divide-y"
  43. >
  44. <HttpTestResultReport
  45. v-if="testResults.expectResults.length"
  46. :test-results="testResults"
  47. />
  48. <div
  49. v-for="(result, index) in testResults.expectResults"
  50. :key="`result-${index}`"
  51. class="flex py-2 px-4 items-center"
  52. >
  53. <i
  54. class="mr-4 material-icons"
  55. :class="
  56. result.status === 'pass' ? 'text-green-500' : 'text-red-500'
  57. "
  58. >
  59. {{ result.status === "pass" ? "check" : "close" }}
  60. </i>
  61. <span v-if="result.message" class="text-secondaryDark">
  62. {{ result.message }}
  63. </span>
  64. <span class="text-secondaryLight">
  65. {{
  66. ` \xA0 — \xA0 ${
  67. result.status === "pass"
  68. ? $t("test.passed")
  69. : $t("test.failed")
  70. }`
  71. }}
  72. </span>
  73. </div>
  74. </div>
  75. </div>
  76. </div>
  77. <div
  78. v-else
  79. class="flex flex-col text-secondaryLight p-4 items-center justify-center"
  80. >
  81. <img
  82. :src="`/images/states/${$colorMode.value}/validation.svg`"
  83. loading="lazy"
  84. class="flex-col my-4 object-contain object-center h-16 w-16 inline-flex"
  85. :alt="$t('empty.tests')"
  86. />
  87. <span class="text-center pb-2">
  88. {{ $t("empty.tests") }}
  89. </span>
  90. <span class="text-center pb-4">
  91. {{ $t("helpers.tests") }}
  92. </span>
  93. <ButtonSecondary
  94. outline
  95. :label="`${$t('action.learn_more')}`"
  96. to="https://docs.hoppscotch.io"
  97. blank
  98. svg="external-link"
  99. reverse
  100. class="my-4"
  101. />
  102. </div>
  103. </AppSection>
  104. </template>
  105. <script setup lang="ts">
  106. import { useReadonlyStream } from "~/helpers/utils/composables"
  107. import { restTestResults$, setRESTTestResults } from "~/newstore/RESTSession"
  108. const testResults = useReadonlyStream(restTestResults$, null)
  109. const clearContent = () => setRESTTestResults(null)
  110. </script>