mirror of
https://github.com/logseq/logseq.git
synced 2026-02-01 22:47:36 +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?
|
||||
;; defonce
|
||||
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]
|
||||
[: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!)
|
||||
foo-id (:db/id (ldb/get-page @conn "foo"))
|
||||
_ (retract-filters! conn foo-id)
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
(use-fixtures :each
|
||||
{:before (fn []
|
||||
(async done
|
||||
(test-helper/start-test-db!)
|
||||
(test-helper/start-test-db! {:db-graph? true})
|
||||
(done)))
|
||||
:after test-helper/destroy-test-db!})
|
||||
|
||||
@@ -45,18 +45,19 @@
|
||||
{:id block-dom-id
|
||||
:block-uuid (:block/uuid block)}]))]
|
||||
(p/do!
|
||||
(editor/delete-block! test-helper/test-db)
|
||||
(editor/delete-block! test-helper/test-db-name-db-version)
|
||||
(when (fn? on-delete)
|
||||
(on-delete))))))
|
||||
|
||||
(deftest-async delete-block-async!
|
||||
(testing "backspace deletes empty block"
|
||||
(load-test-files [{:file/path "pages/page1.md"
|
||||
:file/content "\n
|
||||
- b1
|
||||
- b2
|
||||
-"}])
|
||||
(p/let [conn (db/get-db test-helper/test-db false)
|
||||
(load-test-files
|
||||
[{:page {:block/title "page1"}
|
||||
:blocks
|
||||
[{:block/title "b1"}
|
||||
{:block/title "b2"}
|
||||
{:block/title ""}]}])
|
||||
(p/let [conn (db/get-db test-helper/test-db-name-db-version false)
|
||||
block (->> (d/q '[:find (pull ?b [*])
|
||||
:where [?b :block/title ""]
|
||||
[?p :block/name "page1"]
|
||||
@@ -69,7 +70,7 @@
|
||||
:where
|
||||
[?b :block/parent]
|
||||
[?b :block/title]
|
||||
[(missing? $ ?b :block/pre-block?)]]
|
||||
[(missing? $ ?b :logseq.property/built-in?)]]
|
||||
@conn)
|
||||
(map (comp :block/title first)))]
|
||||
(is (= ["b1" "b2"] updated-blocks) "Block is deleted")))})))
|
||||
@@ -77,12 +78,7 @@
|
||||
(testing "backspace deletes empty block in embedded context"
|
||||
;; testing embed at this layer doesn't require an embed block since
|
||||
;; delete-block handles all the embed setup
|
||||
(load-test-files [{:file/path "pages/page1.md"
|
||||
:file/content "\n
|
||||
- b1
|
||||
- b2
|
||||
-"}])
|
||||
(p/let [conn (db/get-db test-helper/test-db false)
|
||||
(p/let [conn (db/get-db test-helper/test-db-name-db-version false)
|
||||
block (->> (d/q '[:find (pull ?b [*])
|
||||
:where [?b :block/title ""]
|
||||
[?p :block/name "page1"]
|
||||
@@ -96,7 +92,7 @@
|
||||
:where
|
||||
[?b :block/parent]
|
||||
[?b :block/title]
|
||||
[(missing? $ ?b :block/pre-block?)]]
|
||||
[(missing? $ ?b :logseq.property/built-in?)]]
|
||||
@conn)
|
||||
(map (comp :block/title first)))]
|
||||
(is (= ["b1" "b2"] updated-blocks) "Block is deleted")))}))))
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
[frontend.test.helper :as test-helper]
|
||||
[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
|
||||
(testing "Page, block and tag links"
|
||||
@@ -196,9 +196,10 @@
|
||||
|
||||
(deftest save-block!
|
||||
(testing "Saving blocks with and without properties"
|
||||
(test-helper/load-test-files [{:file/path "foo.md"
|
||||
:file/content "# foo"}])
|
||||
(let [repo test-helper/test-db
|
||||
(test-helper/load-test-files [{:page {:block/title "foo"}
|
||||
:blocks [{:block/title "foo"
|
||||
:build/properties {:logseq.property/heading 1}}]}])
|
||||
(let [repo test-helper/test-db-name-db-version
|
||||
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"))]
|
||||
(editor/save-block! repo block-uuid "# bar")
|
||||
|
||||
@@ -7,29 +7,41 @@
|
||||
[promesa.core :as p]))
|
||||
|
||||
(def test-files
|
||||
[{:file/path "pages/page1.md"
|
||||
:file/content
|
||||
(string/trim "
|
||||
- 1
|
||||
id:: 61506710-484c-46d5-9983-3d1651ec02c8
|
||||
- 2
|
||||
id:: 61506711-5638-4899-ad78-187bdc2eaffc
|
||||
- 3
|
||||
id:: 61506712-3007-407e-b6d3-d008a8dfa88b
|
||||
- ((61506712-3007-407e-b6d3-d008a8dfa88b))
|
||||
- 4
|
||||
id:: 61506712-b8a7-491d-ad84-b71651c3fdab")}
|
||||
{:file/path "pages/page2.md"
|
||||
:file/content
|
||||
(string/trim "
|
||||
- 3
|
||||
id:: 97a00e55-48c3-48d8-b9ca-417b16e3a616
|
||||
- {{embed [[page1]]}}")}])
|
||||
(let [uuid-1 #uuid "61506710-484c-46d5-9983-3d1651ec02c8"
|
||||
uuid-2 #uuid "61506711-5638-4899-ad78-187bdc2eaffc"
|
||||
uuid-3 #uuid "61506712-3007-407e-b6d3-d008a8dfa88b"
|
||||
uuid-4 #uuid "61506712-b8a7-491d-ad84-b71651c3fdab"
|
||||
uuid-p2 #uuid "97a00e55-48c3-48d8-b9ca-417b16e3a616"]
|
||||
[{:page {:block/title "page1"}
|
||||
:blocks
|
||||
[{:block/title "1"
|
||||
:build/keep-uuid? true
|
||||
:block/uuid uuid-1
|
||||
:build/children
|
||||
[{:block/title "2"
|
||||
:build/keep-uuid? true
|
||||
:block/uuid uuid-2
|
||||
:build/children
|
||||
[{:block/title "3"
|
||||
:build/keep-uuid? true
|
||||
: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
|
||||
{:before (fn []
|
||||
(async done
|
||||
(test-helper/start-test-db!)
|
||||
(test-helper/start-test-db! {:db-graph? true})
|
||||
(p/let [_ (test-helper/load-test-files test-files)]
|
||||
(done))))
|
||||
:after test-helper/destroy-test-db!})
|
||||
@@ -43,7 +55,7 @@
|
||||
- 1
|
||||
- 2
|
||||
- 3
|
||||
- 3")
|
||||
- [[3]]")
|
||||
"61506710-484c-46d5-9983-3d1651ec02c8"
|
||||
|
||||
(string/trim "
|
||||
@@ -51,38 +63,10 @@
|
||||
- 1
|
||||
- 2
|
||||
- 3
|
||||
- 3
|
||||
- [[3]]
|
||||
- 4")
|
||||
"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
|
||||
(are [expect 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]]")
|
||||
"61506710-484c-46d5-9983-3d1651ec02c8"
|
||||
(string/trim "
|
||||
- 3
|
||||
@@ -122,30 +106,18 @@
|
||||
|
||||
- 3
|
||||
|
||||
- 3
|
||||
- [[3]]
|
||||
|
||||
- 4")
|
||||
"97a00e55-48c3-48d8-b9ca-417b16e3a616"))
|
||||
|
||||
|
||||
(deftest-async export-files-as-markdown
|
||||
(p/do!
|
||||
(are [expect files]
|
||||
(= expect
|
||||
(@#'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"]]
|
||||
[{:path "pages/page1.md" :content (:file/content (nth test-files 0)) :names ["page1"] :format :markdown}]
|
||||
(= expect
|
||||
(@#'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"]]
|
||||
[{: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"]]
|
||||
[{:path "pages/page2.md" :content (:file/content (nth test-files 1)) :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")))
|
||||
[["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 "- 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}])))
|
||||
@@ -4,23 +4,30 @@
|
||||
[frontend.db.utils :as db-utils]
|
||||
[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!})
|
||||
|
||||
(deftest default-page-route
|
||||
(load-test-files [{:file/path "foo.md"
|
||||
:file/content "foo:: bar
|
||||
- b1
|
||||
- ## B1
|
||||
- b2
|
||||
- ### Header 2
|
||||
foo:: bar
|
||||
- ## Header 3 [[Dec 19th, 2022]]"}])
|
||||
(let [journal-uuid (random-uuid)]
|
||||
(load-test-files
|
||||
[{:page {:block/title "foo"}
|
||||
:blocks
|
||||
[{:block/title "b1"}
|
||||
{:block/title "B1"
|
||||
:build/properties {:logseq.property/heading 2}}
|
||||
{: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"
|
||||
(let [block (ffirst
|
||||
(db-utils/q '[:find (pull ?b [:block/uuid])
|
||||
:where [?b :block/title "## B1"]]))]
|
||||
:where [?b :block/title "B1"]]))]
|
||||
(is (= {:to :page-block
|
||||
:path-params {:name "foo" :block-route-name "b1"}}
|
||||
(#'route-handler/default-page-route (:block/uuid block)))
|
||||
@@ -28,15 +35,13 @@ foo:: bar
|
||||
|
||||
(let [block (ffirst
|
||||
(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
|
||||
:path-params {:name "foo" :block-route-name "header 2"}}
|
||||
(#'route-handler/default-page-route (:block/uuid block)))
|
||||
"Generates a page-block link for route-name with whitespace and properties is found")
|
||||
|
||||
(let [block (ffirst
|
||||
(db-utils/q '[:find (pull ?b [:block/uuid])
|
||||
:where [?b :block/title "## Header 3 [[Dec 19th, 2022]]"]]))]
|
||||
(let [block (test-helper/find-block-by-content #"Header 3")]
|
||||
(is (= {:to :page-block
|
||||
:path-params {:name "foo" :block-route-name "header 3 [[dec 19th, 2022]]"}}
|
||||
(#'route-handler/default-page-route (:block/uuid block)))
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
[frontend.modules.outliner.tree :as tree]
|
||||
[frontend.state :as state]
|
||||
[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]
|
||||
[logseq.db :as ldb]
|
||||
[logseq.graph-parser.block :as gp-block]
|
||||
@@ -501,34 +501,6 @@
|
||||
'(16 17)
|
||||
(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
|
||||
|
||||
(def init-id (atom 100))
|
||||
|
||||
Reference in New Issue
Block a user