export_test.cljs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. (ns frontend.handler.export-test
  2. (:require [cljs.test :refer [are async deftest use-fixtures]]
  3. [clojure.string :as string]
  4. [frontend.handler.export.text :as export-text]
  5. [frontend.state :as state]
  6. [frontend.test.helper :as test-helper :include-macros true :refer [deftest-async]]
  7. [promesa.core :as p]))
  8. (def test-files
  9. [{:file/path "pages/page1.md"
  10. :file/content
  11. (string/trim "
  12. - 1
  13. id:: 61506710-484c-46d5-9983-3d1651ec02c8
  14. - 2
  15. id:: 61506711-5638-4899-ad78-187bdc2eaffc
  16. - 3
  17. id:: 61506712-3007-407e-b6d3-d008a8dfa88b
  18. - ((61506712-3007-407e-b6d3-d008a8dfa88b))
  19. - 4
  20. id:: 61506712-b8a7-491d-ad84-b71651c3fdab")}
  21. {:file/path "pages/page2.md"
  22. :file/content
  23. (string/trim "
  24. - 3
  25. id:: 97a00e55-48c3-48d8-b9ca-417b16e3a616
  26. - {{embed [[page1]]}}")}])
  27. (use-fixtures :once
  28. {:before (fn []
  29. (async done
  30. (test-helper/start-test-db!)
  31. (p/let [_ (test-helper/load-test-files test-files)]
  32. (done))))
  33. :after test-helper/destroy-test-db!})
  34. (deftest export-blocks-as-markdown-without-properties
  35. (are [expect block-uuid-s]
  36. (= expect
  37. (string/trim (export-text/export-blocks-as-markdown (state/get-current-repo) [(uuid block-uuid-s)]
  38. {:remove-options #{:property}})))
  39. (string/trim "
  40. - 1
  41. - 2
  42. - 3
  43. - 3")
  44. "61506710-484c-46d5-9983-3d1651ec02c8"
  45. (string/trim "
  46. - 3
  47. - 1
  48. - 2
  49. - 3
  50. - 3
  51. - 4")
  52. "97a00e55-48c3-48d8-b9ca-417b16e3a616"))
  53. (deftest export-blocks-as-markdown-with-properties
  54. (are [expect block-uuid-s]
  55. (= expect (string/trim (export-text/export-blocks-as-markdown (state/get-current-repo) [(uuid block-uuid-s)] {})))
  56. (string/trim "
  57. - 1
  58. id:: 61506710-484c-46d5-9983-3d1651ec02c8
  59. - 2
  60. id:: 61506711-5638-4899-ad78-187bdc2eaffc
  61. - 3
  62. id:: 61506712-3007-407e-b6d3-d008a8dfa88b
  63. - 3")
  64. "61506710-484c-46d5-9983-3d1651ec02c8"
  65. (string/trim "
  66. - 3
  67. id:: 97a00e55-48c3-48d8-b9ca-417b16e3a616
  68. - 1
  69. id:: 61506710-484c-46d5-9983-3d1651ec02c8
  70. - 2
  71. id:: 61506711-5638-4899-ad78-187bdc2eaffc
  72. - 3
  73. id:: 61506712-3007-407e-b6d3-d008a8dfa88b
  74. - 3
  75. - 4
  76. id:: 61506712-b8a7-491d-ad84-b71651c3fdab")
  77. "97a00e55-48c3-48d8-b9ca-417b16e3a616"))
  78. (deftest export-blocks-as-markdown-level<N
  79. (are [expect block-uuid-s]
  80. (= expect (string/trim (export-text/export-blocks-as-markdown (state/get-current-repo) [(uuid block-uuid-s)]
  81. {:remove-options #{:property}
  82. :other-options {:keep-only-level<=N 2}})))
  83. (string/trim "
  84. - 1
  85. - 2")
  86. "61506710-484c-46d5-9983-3d1651ec02c8"
  87. (string/trim "
  88. - 3
  89. - 1
  90. - 4")
  91. "97a00e55-48c3-48d8-b9ca-417b16e3a616"))
  92. (deftest export-blocks-as-markdown-newline-after-block
  93. (are [expect block-uuid-s]
  94. (= expect (string/trim (export-text/export-blocks-as-markdown (state/get-current-repo) [(uuid block-uuid-s)]
  95. {:remove-options #{:property}
  96. :other-options {:newline-after-block true}})))
  97. (string/trim "
  98. - 1
  99. - 2
  100. - 3
  101. - 3")
  102. "61506710-484c-46d5-9983-3d1651ec02c8"
  103. (string/trim "
  104. - 3
  105. - 1
  106. - 2
  107. - 3
  108. - 3
  109. - 4")
  110. "97a00e55-48c3-48d8-b9ca-417b16e3a616"))
  111. (deftest-async export-files-as-markdown
  112. (p/do!
  113. (are [expect files]
  114. (= expect
  115. (@#'export-text/export-files-as-markdown files {:remove-options #{:property}}))
  116. [["pages/page1.md" "- 1\n\t- 2\n\t\t- 3\n\t\t- 3\n- 4\n"]]
  117. [{:path "pages/page1.md" :content (:file/content (nth test-files 0)) :names ["page1"] :format :markdown}]
  118. [["pages/page2.md" "- 3\n\t- 1\n\t\t- 2\n\t\t\t- 3\n\t\t\t- 3\n\t- 4\n"]]
  119. [{:path "pages/page2.md" :content (:file/content (nth test-files 1)) :names ["page2"] :format :markdown}])))
  120. ;; Disabled because this requires db worker
  121. #_(deftest-async export-repo-as-edn-str
  122. (p/let [result (@#'export/<export-repo-as-edn-str (state/get-current-repo))
  123. edn-output (edn/read-string result)]
  124. (is (= #{:version :blocks} (set (keys edn-output)))
  125. "Correct top-level keys")
  126. (is (= (sort (concat (map :block/original-name gp-db/built-in-pages)
  127. ["page1" "page2"]))
  128. (sort (map :block/page-name (:blocks edn-output))))
  129. "Correct pages")))