mirror of
https://github.com/logseq/logseq.git
synced 2026-04-24 22:25:01 +00:00
chore: convert more frontend tests to db graph
Removed file graph specific tests in outliner.core-test and export-test. Also fixed test for export-test as file graph exports didn't reference pages in blocks
This commit is contained in:
@@ -74,4 +74,4 @@ frontend.common.missionary/<!
|
|||||||
frontend.common.missionary/background-task-running?
|
frontend.common.missionary/background-task-running?
|
||||||
;; defonce
|
;; defonce
|
||||||
mobile.components.popup/native-sheet-listener
|
mobile.components.popup/native-sheet-listener
|
||||||
mobile.bottom-tabs/add-tab-listeners!
|
mobile.bottom-tabs/add-tab-listeners!
|
||||||
@@ -67,7 +67,7 @@
|
|||||||
(d/transact! conn [[:db/retract foo-id :logseq.property.linked-references/includes]
|
(d/transact! conn [[:db/retract foo-id :logseq.property.linked-references/includes]
|
||||||
[:db/retract foo-id :logseq.property.linked-references/excludes]]))
|
[:db/retract foo-id :logseq.property.linked-references/excludes]]))
|
||||||
|
|
||||||
(deftest ^:large-vars/cleanup-todo ^:focus get-linked-references
|
(deftest ^:large-vars/cleanup-todo get-linked-references
|
||||||
(let [conn (create-conn!)
|
(let [conn (create-conn!)
|
||||||
foo-id (:db/id (ldb/get-page @conn "foo"))
|
foo-id (:db/id (ldb/get-page @conn "foo"))
|
||||||
_ (retract-filters! conn foo-id)
|
_ (retract-filters! conn foo-id)
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
(use-fixtures :each
|
(use-fixtures :each
|
||||||
{:before (fn []
|
{:before (fn []
|
||||||
(async done
|
(async done
|
||||||
(test-helper/start-test-db!)
|
(test-helper/start-test-db! {:db-graph? true})
|
||||||
(done)))
|
(done)))
|
||||||
:after test-helper/destroy-test-db!})
|
:after test-helper/destroy-test-db!})
|
||||||
|
|
||||||
@@ -45,18 +45,19 @@
|
|||||||
{:id block-dom-id
|
{:id block-dom-id
|
||||||
:block-uuid (:block/uuid block)}]))]
|
:block-uuid (:block/uuid block)}]))]
|
||||||
(p/do!
|
(p/do!
|
||||||
(editor/delete-block! test-helper/test-db)
|
(editor/delete-block! test-helper/test-db-name-db-version)
|
||||||
(when (fn? on-delete)
|
(when (fn? on-delete)
|
||||||
(on-delete))))))
|
(on-delete))))))
|
||||||
|
|
||||||
(deftest-async delete-block-async!
|
(deftest-async delete-block-async!
|
||||||
(testing "backspace deletes empty block"
|
(testing "backspace deletes empty block"
|
||||||
(load-test-files [{:file/path "pages/page1.md"
|
(load-test-files
|
||||||
:file/content "\n
|
[{:page {:block/title "page1"}
|
||||||
- b1
|
:blocks
|
||||||
- b2
|
[{:block/title "b1"}
|
||||||
-"}])
|
{:block/title "b2"}
|
||||||
(p/let [conn (db/get-db test-helper/test-db false)
|
{:block/title ""}]}])
|
||||||
|
(p/let [conn (db/get-db test-helper/test-db-name-db-version false)
|
||||||
block (->> (d/q '[:find (pull ?b [*])
|
block (->> (d/q '[:find (pull ?b [*])
|
||||||
:where [?b :block/title ""]
|
:where [?b :block/title ""]
|
||||||
[?p :block/name "page1"]
|
[?p :block/name "page1"]
|
||||||
@@ -69,7 +70,7 @@
|
|||||||
:where
|
:where
|
||||||
[?b :block/parent]
|
[?b :block/parent]
|
||||||
[?b :block/title]
|
[?b :block/title]
|
||||||
[(missing? $ ?b :block/pre-block?)]]
|
[(missing? $ ?b :logseq.property/built-in?)]]
|
||||||
@conn)
|
@conn)
|
||||||
(map (comp :block/title first)))]
|
(map (comp :block/title first)))]
|
||||||
(is (= ["b1" "b2"] updated-blocks) "Block is deleted")))})))
|
(is (= ["b1" "b2"] updated-blocks) "Block is deleted")))})))
|
||||||
@@ -77,12 +78,7 @@
|
|||||||
(testing "backspace deletes empty block in embedded context"
|
(testing "backspace deletes empty block in embedded context"
|
||||||
;; testing embed at this layer doesn't require an embed block since
|
;; testing embed at this layer doesn't require an embed block since
|
||||||
;; delete-block handles all the embed setup
|
;; delete-block handles all the embed setup
|
||||||
(load-test-files [{:file/path "pages/page1.md"
|
(p/let [conn (db/get-db test-helper/test-db-name-db-version false)
|
||||||
:file/content "\n
|
|
||||||
- b1
|
|
||||||
- b2
|
|
||||||
-"}])
|
|
||||||
(p/let [conn (db/get-db test-helper/test-db false)
|
|
||||||
block (->> (d/q '[:find (pull ?b [*])
|
block (->> (d/q '[:find (pull ?b [*])
|
||||||
:where [?b :block/title ""]
|
:where [?b :block/title ""]
|
||||||
[?p :block/name "page1"]
|
[?p :block/name "page1"]
|
||||||
@@ -96,7 +92,7 @@
|
|||||||
:where
|
:where
|
||||||
[?b :block/parent]
|
[?b :block/parent]
|
||||||
[?b :block/title]
|
[?b :block/title]
|
||||||
[(missing? $ ?b :block/pre-block?)]]
|
[(missing? $ ?b :logseq.property/built-in?)]]
|
||||||
@conn)
|
@conn)
|
||||||
(map (comp :block/title first)))]
|
(map (comp :block/title first)))]
|
||||||
(is (= ["b1" "b2"] updated-blocks) "Block is deleted")))}))))
|
(is (= ["b1" "b2"] updated-blocks) "Block is deleted")))}))))
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
[frontend.test.helper :as test-helper]
|
[frontend.test.helper :as test-helper]
|
||||||
[frontend.util.cursor :as cursor]))
|
[frontend.util.cursor :as cursor]))
|
||||||
|
|
||||||
(use-fixtures :each test-helper/start-and-destroy-db)
|
(use-fixtures :each #(test-helper/start-and-destroy-db % {:db-graph? true}))
|
||||||
|
|
||||||
(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"
|
||||||
@@ -196,9 +196,10 @@
|
|||||||
|
|
||||||
(deftest save-block!
|
(deftest save-block!
|
||||||
(testing "Saving blocks with and without properties"
|
(testing "Saving blocks with and without properties"
|
||||||
(test-helper/load-test-files [{:file/path "foo.md"
|
(test-helper/load-test-files [{:page {:block/title "foo"}
|
||||||
:file/content "# foo"}])
|
:blocks [{:block/title "foo"
|
||||||
(let [repo test-helper/test-db
|
:build/properties {:logseq.property/heading 1}}]}])
|
||||||
|
(let [repo test-helper/test-db-name-db-version
|
||||||
page-uuid (:block/uuid (db/get-page "foo"))
|
page-uuid (:block/uuid (db/get-page "foo"))
|
||||||
block-uuid (:block/uuid (model/get-block-by-page-name-and-block-route-name repo (str page-uuid) "foo"))]
|
block-uuid (:block/uuid (model/get-block-by-page-name-and-block-route-name repo (str page-uuid) "foo"))]
|
||||||
(editor/save-block! repo block-uuid "# bar")
|
(editor/save-block! repo block-uuid "# bar")
|
||||||
|
|||||||
@@ -7,29 +7,41 @@
|
|||||||
[promesa.core :as p]))
|
[promesa.core :as p]))
|
||||||
|
|
||||||
(def test-files
|
(def test-files
|
||||||
[{:file/path "pages/page1.md"
|
(let [uuid-1 #uuid "61506710-484c-46d5-9983-3d1651ec02c8"
|
||||||
:file/content
|
uuid-2 #uuid "61506711-5638-4899-ad78-187bdc2eaffc"
|
||||||
(string/trim "
|
uuid-3 #uuid "61506712-3007-407e-b6d3-d008a8dfa88b"
|
||||||
- 1
|
uuid-4 #uuid "61506712-b8a7-491d-ad84-b71651c3fdab"
|
||||||
id:: 61506710-484c-46d5-9983-3d1651ec02c8
|
uuid-p2 #uuid "97a00e55-48c3-48d8-b9ca-417b16e3a616"]
|
||||||
- 2
|
[{:page {:block/title "page1"}
|
||||||
id:: 61506711-5638-4899-ad78-187bdc2eaffc
|
:blocks
|
||||||
- 3
|
[{:block/title "1"
|
||||||
id:: 61506712-3007-407e-b6d3-d008a8dfa88b
|
:build/keep-uuid? true
|
||||||
- ((61506712-3007-407e-b6d3-d008a8dfa88b))
|
:block/uuid uuid-1
|
||||||
- 4
|
:build/children
|
||||||
id:: 61506712-b8a7-491d-ad84-b71651c3fdab")}
|
[{:block/title "2"
|
||||||
{:file/path "pages/page2.md"
|
:build/keep-uuid? true
|
||||||
:file/content
|
:block/uuid uuid-2
|
||||||
(string/trim "
|
:build/children
|
||||||
- 3
|
[{:block/title "3"
|
||||||
id:: 97a00e55-48c3-48d8-b9ca-417b16e3a616
|
:build/keep-uuid? true
|
||||||
- {{embed [[page1]]}}")}])
|
:block/uuid uuid-3}
|
||||||
|
{:block/title (str "[[" uuid-3 "]]")}]}]}
|
||||||
|
|
||||||
|
{:block/title "4"
|
||||||
|
:build/keep-uuid? true
|
||||||
|
:block/uuid uuid-4}]}
|
||||||
|
{:page {:block/title "page2"}
|
||||||
|
:blocks
|
||||||
|
[{:block/title "3"
|
||||||
|
:build/keep-uuid? true
|
||||||
|
:block/uuid uuid-p2
|
||||||
|
:build/children
|
||||||
|
[{:block/title "{{embed [[page1]]}}"}]}]}]))
|
||||||
|
|
||||||
(use-fixtures :once
|
(use-fixtures :once
|
||||||
{:before (fn []
|
{:before (fn []
|
||||||
(async done
|
(async done
|
||||||
(test-helper/start-test-db!)
|
(test-helper/start-test-db! {:db-graph? true})
|
||||||
(p/let [_ (test-helper/load-test-files test-files)]
|
(p/let [_ (test-helper/load-test-files test-files)]
|
||||||
(done))))
|
(done))))
|
||||||
:after test-helper/destroy-test-db!})
|
:after test-helper/destroy-test-db!})
|
||||||
@@ -43,7 +55,7 @@
|
|||||||
- 1
|
- 1
|
||||||
- 2
|
- 2
|
||||||
- 3
|
- 3
|
||||||
- 3")
|
- [[3]]")
|
||||||
"61506710-484c-46d5-9983-3d1651ec02c8"
|
"61506710-484c-46d5-9983-3d1651ec02c8"
|
||||||
|
|
||||||
(string/trim "
|
(string/trim "
|
||||||
@@ -51,38 +63,10 @@
|
|||||||
- 1
|
- 1
|
||||||
- 2
|
- 2
|
||||||
- 3
|
- 3
|
||||||
- 3
|
- [[3]]
|
||||||
- 4")
|
- 4")
|
||||||
"97a00e55-48c3-48d8-b9ca-417b16e3a616"))
|
"97a00e55-48c3-48d8-b9ca-417b16e3a616"))
|
||||||
|
|
||||||
|
|
||||||
(deftest export-blocks-as-markdown-with-properties
|
|
||||||
(are [expect block-uuid-s]
|
|
||||||
(= expect (string/trim (export-text/export-blocks-as-markdown (state/get-current-repo) [(uuid block-uuid-s)] {})))
|
|
||||||
(string/trim "
|
|
||||||
- 1
|
|
||||||
id:: 61506710-484c-46d5-9983-3d1651ec02c8
|
|
||||||
- 2
|
|
||||||
id:: 61506711-5638-4899-ad78-187bdc2eaffc
|
|
||||||
- 3
|
|
||||||
id:: 61506712-3007-407e-b6d3-d008a8dfa88b
|
|
||||||
- 3")
|
|
||||||
"61506710-484c-46d5-9983-3d1651ec02c8"
|
|
||||||
|
|
||||||
(string/trim "
|
|
||||||
- 3
|
|
||||||
id:: 97a00e55-48c3-48d8-b9ca-417b16e3a616
|
|
||||||
- 1
|
|
||||||
id:: 61506710-484c-46d5-9983-3d1651ec02c8
|
|
||||||
- 2
|
|
||||||
id:: 61506711-5638-4899-ad78-187bdc2eaffc
|
|
||||||
- 3
|
|
||||||
id:: 61506712-3007-407e-b6d3-d008a8dfa88b
|
|
||||||
- 3
|
|
||||||
- 4
|
|
||||||
id:: 61506712-b8a7-491d-ad84-b71651c3fdab")
|
|
||||||
"97a00e55-48c3-48d8-b9ca-417b16e3a616"))
|
|
||||||
|
|
||||||
(deftest export-blocks-as-markdown-level<N
|
(deftest export-blocks-as-markdown-level<N
|
||||||
(are [expect block-uuid-s]
|
(are [expect block-uuid-s]
|
||||||
(= expect (string/trim (export-text/export-blocks-as-markdown (state/get-current-repo) [(uuid block-uuid-s)]
|
(= expect (string/trim (export-text/export-blocks-as-markdown (state/get-current-repo) [(uuid block-uuid-s)]
|
||||||
@@ -111,7 +95,7 @@
|
|||||||
|
|
||||||
- 3
|
- 3
|
||||||
|
|
||||||
- 3")
|
- [[3]]")
|
||||||
"61506710-484c-46d5-9983-3d1651ec02c8"
|
"61506710-484c-46d5-9983-3d1651ec02c8"
|
||||||
(string/trim "
|
(string/trim "
|
||||||
- 3
|
- 3
|
||||||
@@ -122,30 +106,18 @@
|
|||||||
|
|
||||||
- 3
|
- 3
|
||||||
|
|
||||||
- 3
|
- [[3]]
|
||||||
|
|
||||||
- 4")
|
- 4")
|
||||||
"97a00e55-48c3-48d8-b9ca-417b16e3a616"))
|
"97a00e55-48c3-48d8-b9ca-417b16e3a616"))
|
||||||
|
|
||||||
|
|
||||||
(deftest-async export-files-as-markdown
|
(deftest-async export-files-as-markdown
|
||||||
(p/do!
|
(p/do!
|
||||||
(are [expect files]
|
(are [expect files]
|
||||||
(= expect
|
(= expect
|
||||||
(@#'export-text/export-files-as-markdown files {:remove-options #{:property}}))
|
(@#'export-text/export-files-as-markdown files {:remove-options #{:property}}))
|
||||||
[["pages/page1.md" "- 1\n\t- 2\n\t\t- 3\n\t\t- 3\n- 4\n"]]
|
[["pages/page1.md" "- 1\n\t- 2\n\t\t- 3\n\t\t- 3\n- 4\n"]]
|
||||||
[{:path "pages/page1.md" :content (:file/content (nth test-files 0)) :names ["page1"] :format :markdown}]
|
[{:path "pages/page1.md" :content "- 1\n\t- 2\n\t\t- 3\n\t\t- 3\n- 4\n" :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\n"]]
|
[["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"]]
|
||||||
[{:path "pages/page2.md" :content (:file/content (nth test-files 1)) :names ["page2"] :format :markdown}])))
|
[{:path "pages/page2.md" :content "- 3\n\t- 1\n\t\t- 2\n\t\t\t- 3\n\t\t\t- 3\n\t- 4\n" :names ["page2"] :format :markdown}])))
|
||||||
|
|
||||||
;; Disabled because this requires db worker
|
|
||||||
#_(deftest-async export-repo-as-edn-str
|
|
||||||
(p/let [result (@#'export/<export-repo-as-edn-str (state/get-current-repo))
|
|
||||||
edn-output (edn/read-string result)]
|
|
||||||
(is (= #{:version :blocks} (set (keys edn-output)))
|
|
||||||
"Correct top-level keys")
|
|
||||||
(is (= (sort (concat (map :block/title gp-db/built-in-pages)
|
|
||||||
["page1" "page2"]))
|
|
||||||
(sort (map :block/page-name (:blocks edn-output))))
|
|
||||||
"Correct pages")))
|
|
||||||
@@ -4,23 +4,30 @@
|
|||||||
[frontend.db.utils :as db-utils]
|
[frontend.db.utils :as db-utils]
|
||||||
[clojure.test :refer [deftest is use-fixtures testing]]))
|
[clojure.test :refer [deftest is use-fixtures testing]]))
|
||||||
|
|
||||||
(use-fixtures :each {:before test-helper/start-test-db!
|
(use-fixtures :each {:before #(test-helper/start-test-db! {:db-graph? true})
|
||||||
:after test-helper/destroy-test-db!})
|
:after test-helper/destroy-test-db!})
|
||||||
|
|
||||||
(deftest default-page-route
|
(deftest default-page-route
|
||||||
(load-test-files [{:file/path "foo.md"
|
(let [journal-uuid (random-uuid)]
|
||||||
:file/content "foo:: bar
|
(load-test-files
|
||||||
- b1
|
[{:page {:block/title "foo"}
|
||||||
- ## B1
|
:blocks
|
||||||
- b2
|
[{:block/title "b1"}
|
||||||
- ### Header 2
|
{:block/title "B1"
|
||||||
foo:: bar
|
:build/properties {:logseq.property/heading 2}}
|
||||||
- ## Header 3 [[Dec 19th, 2022]]"}])
|
{:block/title "b2"}
|
||||||
|
{:block/title "Header 2"
|
||||||
|
:build/properties {:logseq.property/heading 3}}
|
||||||
|
{:block/title (str "Header 3 [[" journal-uuid "]]")
|
||||||
|
:build/properties {:logseq.property/heading 2}}]}
|
||||||
|
{:page {:build/journal 20221219
|
||||||
|
:build/keep-uuid? true
|
||||||
|
:block/uuid journal-uuid}}]))
|
||||||
|
|
||||||
(testing ":page-block route"
|
(testing ":page-block route"
|
||||||
(let [block (ffirst
|
(let [block (ffirst
|
||||||
(db-utils/q '[:find (pull ?b [:block/uuid])
|
(db-utils/q '[:find (pull ?b [:block/uuid])
|
||||||
:where [?b :block/title "## B1"]]))]
|
:where [?b :block/title "B1"]]))]
|
||||||
(is (= {:to :page-block
|
(is (= {:to :page-block
|
||||||
:path-params {:name "foo" :block-route-name "b1"}}
|
:path-params {:name "foo" :block-route-name "b1"}}
|
||||||
(#'route-handler/default-page-route (:block/uuid block)))
|
(#'route-handler/default-page-route (:block/uuid block)))
|
||||||
@@ -28,15 +35,13 @@ foo:: bar
|
|||||||
|
|
||||||
(let [block (ffirst
|
(let [block (ffirst
|
||||||
(db-utils/q '[:find (pull ?b [:block/uuid])
|
(db-utils/q '[:find (pull ?b [:block/uuid])
|
||||||
:where [?b :block/title "### Header 2\nfoo:: bar"]]))]
|
:where [?b :block/title "Header 2"]]))]
|
||||||
(is (= {:to :page-block
|
(is (= {:to :page-block
|
||||||
:path-params {:name "foo" :block-route-name "header 2"}}
|
:path-params {:name "foo" :block-route-name "header 2"}}
|
||||||
(#'route-handler/default-page-route (:block/uuid block)))
|
(#'route-handler/default-page-route (:block/uuid block)))
|
||||||
"Generates a page-block link for route-name with whitespace and properties is found")
|
"Generates a page-block link for route-name with whitespace and properties is found")
|
||||||
|
|
||||||
(let [block (ffirst
|
(let [block (test-helper/find-block-by-content #"Header 3")]
|
||||||
(db-utils/q '[:find (pull ?b [:block/uuid])
|
|
||||||
:where [?b :block/title "## Header 3 [[Dec 19th, 2022]]"]]))]
|
|
||||||
(is (= {:to :page-block
|
(is (= {:to :page-block
|
||||||
:path-params {:name "foo" :block-route-name "header 3 [[dec 19th, 2022]]"}}
|
:path-params {:name "foo" :block-route-name "header 3 [[dec 19th, 2022]]"}}
|
||||||
(#'route-handler/default-page-route (:block/uuid block)))
|
(#'route-handler/default-page-route (:block/uuid block)))
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
[frontend.modules.outliner.tree :as tree]
|
[frontend.modules.outliner.tree :as tree]
|
||||||
[frontend.state :as state]
|
[frontend.state :as state]
|
||||||
[frontend.test.fixtures :as fixtures]
|
[frontend.test.fixtures :as fixtures]
|
||||||
[frontend.test.helper :as test-helper :refer [load-test-files]]
|
[frontend.test.helper :as test-helper]
|
||||||
[frontend.worker.db-listener :as worker-db-listener]
|
[frontend.worker.db-listener :as worker-db-listener]
|
||||||
[logseq.db :as ldb]
|
[logseq.db :as ldb]
|
||||||
[logseq.graph-parser.block :as gp-block]
|
[logseq.graph-parser.block :as gp-block]
|
||||||
@@ -501,34 +501,6 @@
|
|||||||
'(16 17)
|
'(16 17)
|
||||||
(map :block/uuid (tree/get-sorted-block-and-children test-db (:db/id (get-block 16))))))))
|
(map :block/uuid (tree/get-sorted-block-and-children test-db (:db/id (get-block 16))))))))
|
||||||
|
|
||||||
(defn- save-block!
|
|
||||||
[block]
|
|
||||||
(outliner-tx/transact! (transact-opts)
|
|
||||||
(outliner-core/save-block! (db/get-db test-db false)
|
|
||||||
block)))
|
|
||||||
|
|
||||||
(deftest save-test
|
|
||||||
(load-test-files [{:file/path "pages/page1.md"
|
|
||||||
:file/content "alias:: foo, bar
|
|
||||||
tags:: tag1, tag2
|
|
||||||
- block #blarg #bar"}])
|
|
||||||
(testing "save deletes a page's tags"
|
|
||||||
(let [conn (db/get-db test-db false)
|
|
||||||
pre-block (->> (d/q '[:find (pull ?b [*])
|
|
||||||
:where [?b :block/pre-block? true]]
|
|
||||||
@conn)
|
|
||||||
ffirst)
|
|
||||||
_ (save-block! (-> pre-block
|
|
||||||
(update :block/properties dissoc :tags)
|
|
||||||
(update :block/properties-text-values dissoc :tags)))
|
|
||||||
updated-page (-> (d/q '[:find (pull ?bp [* {:block/alias [*]}])
|
|
||||||
:where [?b :block/pre-block? true]
|
|
||||||
[?b :block/page ?bp]]
|
|
||||||
@conn)
|
|
||||||
ffirst)]
|
|
||||||
(is (nil? (:block/tags updated-page))
|
|
||||||
"Page's tags are deleted"))))
|
|
||||||
|
|
||||||
;;; Fuzzy tests
|
;;; Fuzzy tests
|
||||||
|
|
||||||
(def init-id (atom 100))
|
(def init-id (atom 100))
|
||||||
|
|||||||
Reference in New Issue
Block a user