|  | @@ -1,9 +1,14 @@
 | 
	
		
			
				|  |  |  (ns frontend.handler.editor-test
 | 
	
		
			
				|  |  |    (:require [frontend.handler.editor :as editor]
 | 
	
		
			
				|  |  | -            [clojure.test :refer [deftest is testing are]]
 | 
	
		
			
				|  |  | +            [frontend.db :as db]
 | 
	
		
			
				|  |  | +            [clojure.test :refer [deftest is testing are use-fixtures]]
 | 
	
		
			
				|  |  | +            [datascript.core :as d]
 | 
	
		
			
				|  |  | +            [frontend.test.helper :as test-helper :refer [load-test-files]]
 | 
	
		
			
				|  |  |              [frontend.state :as state]
 | 
	
		
			
				|  |  |              [frontend.util.cursor :as cursor]))
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +(use-fixtures :each test-helper/start-and-destroy-db)
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  (deftest extract-nearest-link-from-text-test
 | 
	
		
			
				|  |  |    (testing "Page, block and tag links"
 | 
	
		
			
				|  |  |      (is (= "page1"
 | 
	
	
		
			
				|  | @@ -213,3 +218,24 @@
 | 
	
		
			
				|  |  |          "No page search within backticks"))
 | 
	
		
			
				|  |  |    ;; Reset state
 | 
	
		
			
				|  |  |    (state/set-editor-action! nil))
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +(deftest save-block-aux!
 | 
	
		
			
				|  |  | +  (load-test-files [{:file/path "pages/page1.md"
 | 
	
		
			
				|  |  | +                     :file/content "\n
 | 
	
		
			
				|  |  | +- b1 #foo"}])
 | 
	
		
			
				|  |  | +  (testing "updating block's content changes content and preserves path-refs"
 | 
	
		
			
				|  |  | +   (let [conn (db/get-db test-helper/test-db false)
 | 
	
		
			
				|  |  | +         block (->> (d/q '[:find (pull ?b [* {:block/path-refs [:block/name]}])
 | 
	
		
			
				|  |  | +                           :where [?b :block/content "b1 #foo"]]
 | 
	
		
			
				|  |  | +                         @conn)
 | 
	
		
			
				|  |  | +                    ffirst)
 | 
	
		
			
				|  |  | +         prev-path-refs (set (map :block/name (:block/path-refs block)))
 | 
	
		
			
				|  |  | +         _ (assert (= #{"page1" "foo"} prev-path-refs)
 | 
	
		
			
				|  |  | +                   "block has expected :block/path-refs")
 | 
	
		
			
				|  |  | +         ;; Use same options as edit-box-on-change!
 | 
	
		
			
				|  |  | +         _ (editor/save-block-aux! block "b12 #foo" {:skip-properties? true})
 | 
	
		
			
				|  |  | +         updated-block (d/pull @conn '[* {:block/path-refs [:block/name]}] [:block/uuid (:block/uuid block)])]
 | 
	
		
			
				|  |  | +     (is (= "b12 #foo" (:block/content updated-block)) "Content updated correctly")
 | 
	
		
			
				|  |  | +     (is (= prev-path-refs
 | 
	
		
			
				|  |  | +            (set (map :block/name (:block/path-refs updated-block))))
 | 
	
		
			
				|  |  | +         "Path-refs remain the same"))))
 |