Tests.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <template>
  2. <AppSection id="script" :label="$t('test.script')">
  3. <div
  4. class="
  5. bg-primary
  6. border-b border-dividerLight
  7. flex flex-1
  8. top-upperSecondaryStickyFold
  9. pl-4
  10. z-10
  11. sticky
  12. items-center
  13. justify-between
  14. "
  15. >
  16. <label class="font-semibold text-secondaryLight">
  17. {{ $t("test.javascript_code") }}
  18. </label>
  19. <div class="flex">
  20. <ButtonSecondary
  21. v-tippy="{ theme: 'tooltip' }"
  22. to="https://docs.hoppscotch.io/features/tests"
  23. blank
  24. :title="$t('app.wiki')"
  25. svg="help-circle"
  26. />
  27. <ButtonSecondary
  28. v-tippy="{ theme: 'tooltip' }"
  29. :title="$t('action.clear')"
  30. svg="trash-2"
  31. @click.native="clearContent"
  32. />
  33. </div>
  34. </div>
  35. <div class="border-b border-dividerLight flex">
  36. <div class="border-r border-dividerLight w-2/3">
  37. <SmartJsEditor
  38. v-model="testScript"
  39. :options="{
  40. maxLines: Infinity,
  41. minLines: 16,
  42. autoScrollEditorIntoView: true,
  43. showPrintMargin: false,
  44. useWorker: false,
  45. }"
  46. complete-mode="test"
  47. />
  48. </div>
  49. <div
  50. class="
  51. bg-primary
  52. h-full
  53. top-upperTertiaryStickyFold
  54. min-w-46
  55. max-w-1/3
  56. p-4
  57. z-9
  58. sticky
  59. overflow-auto
  60. "
  61. >
  62. <div class="text-secondaryLight pb-2">
  63. {{ $t("helpers.post_request_tests") }}
  64. </div>
  65. <SmartAnchor
  66. :label="$t('test.learn')"
  67. to="https://docs.hoppscotch.io/features/tests"
  68. blank
  69. />
  70. <h4 class="font-bold text-secondaryLight pt-6">
  71. {{ $t("test.snippets") }}
  72. </h4>
  73. <div class="flex flex-col pt-4">
  74. <TabSecondary
  75. v-for="(snippet, index) in testSnippets"
  76. :key="`snippet-${index}`"
  77. :label="snippet.name"
  78. active
  79. @click.native="useSnippet(snippet.script)"
  80. />
  81. </div>
  82. </div>
  83. </div>
  84. </AppSection>
  85. </template>
  86. <script setup lang="ts">
  87. import { useTestScript } from "~/newstore/RESTSession"
  88. import testSnippets from "~/helpers/testSnippets"
  89. const testScript = useTestScript()
  90. const useSnippet = (script: string) => {
  91. testScript.value += script
  92. }
  93. const clearContent = () => {
  94. testScript.value = ""
  95. }
  96. </script>