Ver Fonte

feat: add test for save-block

clstb há 2 anos atrás
pai
commit
7461d2bc4e
1 ficheiros alterados com 25 adições e 2 exclusões
  1. 25 2
      src/test/frontend/handler/editor_test.cljs

+ 25 - 2
src/test/frontend/handler/editor_test.cljs

@@ -4,10 +4,17 @@
             [clojure.test :refer [deftest is testing are use-fixtures]]
             [clojure.test :refer [deftest is testing are use-fixtures]]
             [datascript.core :as d]
             [datascript.core :as d]
             [frontend.test.helper :as test-helper :refer [load-test-files]]
             [frontend.test.helper :as test-helper :refer [load-test-files]]
+            [frontend.db.model :as model]
             [frontend.state :as state]
             [frontend.state :as state]
             [frontend.util.cursor :as cursor]))
             [frontend.util.cursor :as cursor]))
 
 
-(use-fixtures :each test-helper/start-and-destroy-db)
+(use-fixtures :each {:before (fn []
+                               ;; Set current-repo explicitly since it's not the default
+                               (state/set-current-repo! test-helper/test-db)
+                               (test-helper/start-test-db!))
+                     :after (fn []
+                              (state/set-current-repo! nil)
+                              (test-helper/destroy-test-db!))})
 
 
 (deftest extract-nearest-link-from-text-test
 (deftest extract-nearest-link-from-text-test
   (testing "Page, block and tag links"
   (testing "Page, block and tag links"
@@ -238,4 +245,20 @@
      (is (= "b12 #foo" (:block/content updated-block)) "Content updated correctly")
      (is (= "b12 #foo" (:block/content updated-block)) "Content updated correctly")
      (is (= prev-path-refs
      (is (= prev-path-refs
             (set (map :block/name (:block/path-refs updated-block))))
             (set (map :block/name (:block/path-refs updated-block))))
-         "Path-refs remain the same"))))
+         "Path-refs remain the same"))))
+
+(deftest save-block
+  (testing "Saving blocks"
+    (test-helper/load-test-files [{:file/path "foo.md"
+                                   :file/content "# foo"}])
+    (let [repo test-helper/test-db
+          block-uuid (:block/uuid (model/get-block-by-page-name-and-block-route-name repo "foo" "foo"))
+          _ (let [_ (editor/save-block! repo block-uuid "# bar")
+                  block (model/query-block-by-uuid block-uuid)
+                  _ (is (= "# bar" (:block/content block)))])
+          _ (let [_ (editor/save-block! repo block-uuid "# foo" {:properties {:foo "bar"}})
+                  block (model/query-block-by-uuid block-uuid)
+                  _ (is (= "# foo\nfoo:: bar" (:block/content block)))])
+          _ (let [_ (editor/save-block! repo block-uuid "# bar")
+                  block (model/query-block-by-uuid block-uuid)
+                  _ (is (= "# bar" (:block/content block)))])])))