Add unit tests for create-if-not-exists and misc test improvements

- Added unit test as it is used by several handlers
- Fixed test suite failing from last commit now that a test fs is used
- Fixed test stat implementation
- Extracted out Plugin schema to make usage of it less impl dependent
- Made test.helper alias consistent
- Made async testing consistent for export-test
This commit is contained in:
Gabriel Horner
2022-10-07 11:01:34 -04:00
parent c8cda90373
commit 784ad7cce3
12 changed files with 145 additions and 76 deletions

View File

@@ -1,9 +1,8 @@
(ns frontend.handler.export-test
(:require [cljs.test :refer [async deftest use-fixtures are is]]
(:require [cljs.test :refer [async use-fixtures are is]]
[frontend.test.helper :as test-helper :include-macros true :refer [deftest-async]]
[clojure.edn :as edn]
[frontend.handler.export :as export]
[frontend.test.helper :as test-helper]
[frontend.handler.repo :as repo-handler]
[frontend.state :as state]
[promesa.core :as p]))
@@ -18,50 +17,48 @@
id:: 61506712-3007-407e-b6d3-d008a8dfa88b
- ((61506712-3007-407e-b6d3-d008a8dfa88b))
- 4
id:: 61506712-b8a7-491d-ad84-b71651c3fdab"
}
id:: 61506712-b8a7-491d-ad84-b71651c3fdab"}
{:file/path "pages/page2.md"
:file/content
"- 3
id:: 97a00e55-48c3-48d8-b9ca-417b16e3a616
- {{embed [[page1]]}}"}])
(defn- import-test-data!
[]
(repo-handler/parse-files-and-load-to-db! (state/get-current-repo) test-files {:re-render? false}))
(use-fixtures :once
{:before (fn []
(async done
(test-helper/clear-current-repo)
(p/let [_ (import-test-data!)]
(test-helper/start-test-db!)
(p/let [_ (test-helper/load-test-files test-files)]
(done))))
:after test-helper/destroy-test-db!})
(deftest export-blocks-as-markdown
(are [expect block-uuid-s]
(= expect
(export/export-blocks-as-markdown (state/get-current-repo) [(uuid block-uuid-s)] "dashes" []))
"- 1 \n\t- 2 \n\t\t- 3 \n\t\t- 3 "
"61506710-484c-46d5-9983-3d1651ec02c8"
(deftest-async export-blocks-as-markdown
(p/do!
(are [expect block-uuid-s]
(= expect
(export/export-blocks-as-markdown (state/get-current-repo) [(uuid block-uuid-s)] "dashes" []))
"- 1 \n\t- 2 \n\t\t- 3 \n\t\t- 3 "
"61506710-484c-46d5-9983-3d1651ec02c8"
"- 3 \n\t- 1 \n\t\t- 2 \n\t\t\t- 3 \n\t\t\t- 3 \n\t- 4 "
"97a00e55-48c3-48d8-b9ca-417b16e3a616"))
"- 3 \n\t- 1 \n\t\t- 2 \n\t\t\t- 3 \n\t\t\t- 3 \n\t- 4 "
"97a00e55-48c3-48d8-b9ca-417b16e3a616")))
(deftest export-files-as-markdown
(are [expect files]
(= expect
(@#'export/export-files-as-markdown (state/get-current-repo) files true))
[["pages/page1.md" "- 1 \n\t- 2 \n\t\t- 3 \n\t\t- 3 \n- 4 "]]
[{:path "pages/page1.md" :content (:file/content (nth test-files 0)) :names ["page1"] :format :markdown}]
(deftest-async export-files-as-markdown
(p/do!
(are [expect files]
(= expect
(@#'export/export-files-as-markdown (state/get-current-repo) files true))
[["pages/page1.md" "- 1 \n\t- 2 \n\t\t- 3 \n\t\t- 3 \n- 4 "]]
[{:path "pages/page1.md" :content (:file/content (nth test-files 0)) :names ["page1"] :format :markdown}]
[["pages/page2.md" "- 3 \n\t- 1 \n\t\t- 2 \n\t\t\t- 3 \n\t\t\t- 3 \n\t- 4 "]]
[{:path "pages/page2.md" :content (:file/content (nth test-files 1)) :names ["page2"] :format :markdown}]))
[["pages/page2.md" "- 3 \n\t- 1 \n\t\t- 2 \n\t\t\t- 3 \n\t\t\t- 3 \n\t- 4 "]]
[{:path "pages/page2.md" :content (:file/content (nth test-files 1)) :names ["page2"] :format :markdown}])))
(deftest export-repo-as-edn-str
(let [edn-output (edn/read-string
(@#'export/export-repo-as-edn-str (state/get-current-repo)))]
(is (= #{:version :blocks} (set (keys edn-output)))
"Correct top-level keys")
(is (= ["page1" "page2"] (map :block/page-name (:blocks edn-output)))
"Correct pages")))
(deftest-async export-repo-as-edn-str
(p/do!
(let [edn-output (edn/read-string
(@#'export/export-repo-as-edn-str (state/get-current-repo)))]
(is (= #{:version :blocks} (set (keys edn-output)))
"Correct top-level keys")
(is (= ["page1" "page2"] (map :block/page-name (:blocks edn-output)))
"Correct pages"))))