mirror of
https://github.com/logseq/logseq.git
synced 2026-06-01 19:01:22 +00:00
fix: fix tests
This commit is contained in:
@@ -7,7 +7,12 @@
|
||||
[rum.core :as rum]
|
||||
[datascript.core :as d]
|
||||
[frontend.db-schema :as db-schema]
|
||||
[frontend.state :as state]))
|
||||
[frontend.state :as state]
|
||||
[frontend.config :as config]))
|
||||
|
||||
(defn load-test-env
|
||||
[f]
|
||||
(with-redefs [config/test? true] (f)))
|
||||
|
||||
(defn react-components
|
||||
[f]
|
||||
|
||||
@@ -1,135 +0,0 @@
|
||||
(ns frontend.modules.file.core-test
|
||||
(:require [cljs.test :refer [deftest is are testing use-fixtures run-tests] :as test]
|
||||
[cljs-run-test :refer [run-test]]
|
||||
[frontend.modules.file.core :as file]
|
||||
[clojure.string :as str]))
|
||||
|
||||
(deftest test-transform-content
|
||||
(let [s "#### abc\n\n"
|
||||
r " abc"]
|
||||
(is (= r (file/clip-content s)))))
|
||||
|
||||
(comment
|
||||
(run-test test-transform-content))
|
||||
|
||||
(def tree
|
||||
'({:block/pre-block? true,
|
||||
:block/uuid #uuid "60643869-3b5b-4e1b-a1f8-28ec965abb4c",
|
||||
:block/left {:db/id 20},
|
||||
:block/body
|
||||
({:block/uuid #uuid "60643869-6feb-4b4a-87b0-7a8a76cf2746",
|
||||
:block/refs (),
|
||||
:block/anchor "level_1",
|
||||
:block/children
|
||||
#{[:block/uuid #uuid "60643869-c9dc-4a06-b1c3-e86bad631b3a"]},
|
||||
:block/body [],
|
||||
:block/meta
|
||||
{:timestamps [], :properties [], :start-pos 30, :end-pos 41},
|
||||
:block/level 2,
|
||||
:block/tags [],
|
||||
:block/title [["Plain" "level 1"]]}
|
||||
{:block/uuid #uuid "60643869-c9dc-4a06-b1c3-e86bad631b3a",
|
||||
:block/refs (),
|
||||
:block/anchor "level_1_1",
|
||||
:block/children
|
||||
#{[:block/uuid #uuid "60643869-3d80-4926-8854-5de911fb2aca"]},
|
||||
:block/body [],
|
||||
:block/meta
|
||||
{:timestamps [], :properties [], :start-pos 41, :end-pos 55},
|
||||
:block/level 3,
|
||||
:block/tags [],
|
||||
:block/title [["Plain" "level 1-1"]]}
|
||||
{:block/uuid #uuid "60643869-3d80-4926-8854-5de911fb2aca",
|
||||
:block/refs (),
|
||||
:block/anchor "level_1_1_1",
|
||||
:block/children #{},
|
||||
:block/body [],
|
||||
:block/meta
|
||||
{:timestamps [], :properties [], :start-pos 55, :end-pos 72},
|
||||
:block/level 4,
|
||||
:block/tags [],
|
||||
:block/title [["Plain" "level 1-1-1"]]}
|
||||
{:block/uuid #uuid "60643869-39d5-497e-b300-fa49993f6fda",
|
||||
:block/refs (),
|
||||
:block/anchor "level_2",
|
||||
:block/children #{},
|
||||
:block/body [],
|
||||
:block/meta
|
||||
{:timestamps [], :properties [], :start-pos 72, :end-pos 83},
|
||||
:block/level 2,
|
||||
:block/tags [],
|
||||
:block/title [["Plain" "level 2"]]}),
|
||||
:block/format :markdown,
|
||||
:block/level 2,
|
||||
:block/refs-with-children (),
|
||||
:block/content "---\ntitle: Mar 31th, 2021\n---\n",
|
||||
:db/id 24,
|
||||
:block/parent {:db/id 20},
|
||||
:block/page {:db/id 20},
|
||||
:block/file {:db/id 16}}
|
||||
{:block/uuid #uuid "60643869-6feb-4b4a-87b0-7a8a76cf2746",
|
||||
:block/left {:db/id 24},
|
||||
:block/anchor "level_1",
|
||||
:block/children
|
||||
({:block/uuid #uuid "60643869-c9dc-4a06-b1c3-e86bad631b3a",
|
||||
:block/left {:db/id 25},
|
||||
:block/anchor "level_1_1",
|
||||
:block/children
|
||||
({:block/uuid #uuid "60643869-3d80-4926-8854-5de911fb2aca",
|
||||
:block/left {:db/id 26},
|
||||
:block/anchor "level_1_1_1",
|
||||
:block/body [],
|
||||
:block/format :markdown,
|
||||
:block/level 4,
|
||||
:block/title [["Plain" "level 1-1-1"]],
|
||||
:block/refs-with-children (),
|
||||
:block/content "#### level 1-1-1\n",
|
||||
:db/id 27,
|
||||
:block/parent {:db/id 26},
|
||||
:block/page {:db/id 20},
|
||||
:block/file {:db/id 16}}),
|
||||
:block/body [],
|
||||
:block/format :markdown,
|
||||
:block/level 3,
|
||||
:block/title [["Plain" "level 1-1"]],
|
||||
:block/refs-with-children (),
|
||||
:block/content "### level 1-1",
|
||||
:db/id 26,
|
||||
:block/parent {:db/id 25},
|
||||
:block/page {:db/id 20},
|
||||
:block/file {:db/id 16}}),
|
||||
:block/body [],
|
||||
:block/format :markdown,
|
||||
:block/level 2,
|
||||
:block/title [["Plain" "level 1"]],
|
||||
:block/refs-with-children (),
|
||||
:block/content "## level 1\n",
|
||||
:db/id 25,
|
||||
:block/parent {:db/id 20},
|
||||
:block/page {:db/id 20},
|
||||
:block/file {:db/id 16}}
|
||||
{:block/uuid #uuid "60643869-39d5-497e-b300-fa49993f6fda",
|
||||
:block/left {:db/id 25},
|
||||
:block/anchor "level_2",
|
||||
:block/repo "logseq_local_test_navtive_fs",
|
||||
:block/body [],
|
||||
:block/format :markdown,
|
||||
:block/level 2,
|
||||
:block/title [["Plain" "level 2"]],
|
||||
:block/refs-with-children (),
|
||||
:block/content "## level 2",
|
||||
:db/id 28,
|
||||
:block/parent {:db/id 20},
|
||||
:block/page {:db/id 20},
|
||||
:block/file {:db/id 16}}))
|
||||
|
||||
(defn- clip-first-space [s]
|
||||
(str/replace s #"\n\s+" "\n"))
|
||||
|
||||
(deftest test-tree->file-content
|
||||
(let [r "---\ntitle: Mar 31th, 2021\n---\n## level 1\n### level 1-1\n#### level 1-1-1\n## level 2"
|
||||
r (clip-first-space r)]
|
||||
(is (= r (file/tree->file-content tree 2)))))
|
||||
|
||||
(comment
|
||||
(run-test test-tree->file-content))
|
||||
@@ -5,12 +5,14 @@
|
||||
[frontend.react :as r]
|
||||
[frontend.modules.outliner.utils :as outliner-u]
|
||||
[frontend.modules.outliner.core :as outliner-core]
|
||||
[frontend.modules.outliner.datascript :as outliner-ds]
|
||||
[frontend.fixtures :as fixtures]
|
||||
[cljs-run-test :refer [run-test]]
|
||||
[frontend.core-test :as core-test]
|
||||
[frontend.handler.block :as block]))
|
||||
|
||||
(use-fixtures :each
|
||||
fixtures/load-test-env
|
||||
fixtures/react-impl
|
||||
fixtures/react-components
|
||||
fixtures/reset-db)
|
||||
@@ -39,22 +41,24 @@
|
||||
(defn build-db-records
|
||||
"build RDS record from memory node struct."
|
||||
[tree-record]
|
||||
(letfn [(build [node queue]
|
||||
(let [{:keys [id left parent]} node
|
||||
block (build-block id parent left)
|
||||
left (atom (:id node))
|
||||
children (map (fn [c]
|
||||
(let [node (assoc c :left @left :parent (:id node))]
|
||||
(swap! left (constantly (:id c)))
|
||||
node))
|
||||
(:children node))
|
||||
queue (concat queue children)]
|
||||
(tree/-save block)
|
||||
(when (seq queue)
|
||||
(build (first queue) (rest queue)))))]
|
||||
(let [root (assoc tree-record :left "1" :parent "1")]
|
||||
(tree/-save (build-block "1"))
|
||||
(build root '()))))
|
||||
(outliner-ds/auto-transact!
|
||||
[state (outliner-ds/new-outliner-txs-state)] nil
|
||||
(letfn [(build [node queue]
|
||||
(let [{:keys [id left parent]} node
|
||||
block (build-block id parent left)
|
||||
left (atom (:id node))
|
||||
children (map (fn [c]
|
||||
(let [node (assoc c :left @left :parent (:id node))]
|
||||
(swap! left (constantly (:id c)))
|
||||
node))
|
||||
(:children node))
|
||||
queue (concat queue children)]
|
||||
(tree/-save block state)
|
||||
(when (seq queue)
|
||||
(build (first queue) (rest queue)))))]
|
||||
(let [root (assoc tree-record :left "1" :parent "1")]
|
||||
(tree/-save (build-block "1") state)
|
||||
(build root '())))))
|
||||
|
||||
|
||||
(def tree [1 [[2 [[3 [[4]
|
||||
@@ -93,7 +97,9 @@
|
||||
(build-db-records node-tree)
|
||||
(let [new-node (build-block 18 nil nil)
|
||||
parent-node (build-block 2 1 1)]
|
||||
(outliner-core/insert-node-as-first-child new-node parent-node)
|
||||
(outliner-ds/auto-transact!
|
||||
[state (outliner-ds/new-outliner-txs-state)] nil
|
||||
(outliner-core/insert-node-as-first-child state new-node parent-node))
|
||||
(let [children-of-2 (->> (build-block 2 1 1)
|
||||
(tree/-get-children)
|
||||
(mapv #(-> % :data :block/uuid)))]
|
||||
@@ -116,7 +122,9 @@
|
||||
(build-db-records node-tree)
|
||||
(let [new-node (build-block 18 nil nil)
|
||||
left-node (build-block 6 2 3)]
|
||||
(outliner-core/insert-node-as-sibling new-node left-node)
|
||||
(outliner-ds/auto-transact!
|
||||
[state (outliner-ds/new-outliner-txs-state)] nil
|
||||
(outliner-core/insert-node-as-sibling state new-node left-node))
|
||||
(let [children-of-2 (->> (build-block 2 1 1)
|
||||
(tree/-get-children)
|
||||
(mapv #(-> % :data :block/uuid)))]
|
||||
@@ -196,176 +204,3 @@
|
||||
(mapv #(-> % :data :block/uuid)))]
|
||||
(is (= [6 9] old-parent's-children))
|
||||
(is (= [3 13 14 15] new-parent's-children)))))
|
||||
|
||||
;
|
||||
;(r/defc render-react-tree
|
||||
; [root]
|
||||
; (let [children (tree/-get-children root)]
|
||||
; (if (seq children)
|
||||
; [(tree/-get-id root)
|
||||
; (mapv (fn [child]
|
||||
; @(->> (render-react-tree child)
|
||||
; (r/with-key (str "root-" (tree/-get-id child)))))
|
||||
; children)]
|
||||
; [(tree/-get-id root)])))
|
||||
;
|
||||
;(deftest test-react-insert-node-as-first-child
|
||||
; "
|
||||
; [1 [[2 [[3 [[4]
|
||||
; [5]]]
|
||||
; [6 [[7 [[8]]]]]
|
||||
; [9 [[10]
|
||||
; [11]]]]]
|
||||
; [12 [[13]
|
||||
; [14]
|
||||
; [15]]]
|
||||
; [16 [[17]]]]]
|
||||
; "
|
||||
; (build-db-records node-tree)
|
||||
; (let [root (build-block 1 nil nil)
|
||||
; result (->> (render-react-tree root)
|
||||
; (r/with-key (str "root-" (tree/-get-id root))))]
|
||||
; (is (= [1 [[2 [[3 [[4]
|
||||
; [5]]]
|
||||
; [6 [[7 [[8]]]]]
|
||||
; [9 [[10]
|
||||
; [11]]]]]
|
||||
; [12 [[13]
|
||||
; [14]
|
||||
; [15]]]
|
||||
; [16 [[17]]]]]
|
||||
; @result))
|
||||
; (let [new-node (build-block 18 nil nil)
|
||||
; parent-node (build-block 2 1 1)]
|
||||
; (outliner-core/insert-node-as-first-child new-node parent-node)
|
||||
; (is (= [1 [[2 [[18]
|
||||
; [3 [[4]
|
||||
; [5]]]
|
||||
; [6 [[7 [[8]]]]]
|
||||
; [9 [[10]
|
||||
; [11]]]]]
|
||||
; [12 [[13]
|
||||
; [14]
|
||||
; [15]]]
|
||||
; [16 [[17]]]]]
|
||||
; @result)))))
|
||||
;
|
||||
;(deftest test-react-for-insert-node-as-sibling
|
||||
; "
|
||||
; [1 [[2 [[3 [[4]
|
||||
; [5]]]
|
||||
; [6 [[7 [[8]]]]]
|
||||
; [9 [[10]
|
||||
; [11]]]]]
|
||||
; [12 [[13]
|
||||
; [14]
|
||||
; [15]]]
|
||||
; [16 [[17]]]]]
|
||||
; "
|
||||
; (build-db-records node-tree)
|
||||
; (let [root (build-block 1 nil nil)
|
||||
; result (->> (render-react-tree root)
|
||||
; (r/with-key (str "root-" (tree/-get-id root))))]
|
||||
; (is (= [1 [[2 [[3 [[4]
|
||||
; [5]]]
|
||||
; [6 [[7 [[8]]]]]
|
||||
; [9 [[10]
|
||||
; [11]]]]]
|
||||
; [12 [[13]
|
||||
; [14]
|
||||
; [15]]]
|
||||
; [16 [[17]]]]]
|
||||
; @result))
|
||||
; (let [new-node (build-block 18 nil nil)
|
||||
; left-node (build-block 3 2 2)]
|
||||
; (outliner-core/insert-node-as-sibling new-node left-node)
|
||||
; (is (= [1 [[2 [[3 [[4]
|
||||
; [5]]]
|
||||
; [18]
|
||||
; [6 [[7 [[8]]]]]
|
||||
; [9 [[10]
|
||||
; [11]]]]]
|
||||
; [12 [[13]
|
||||
; [14]
|
||||
; [15]]]
|
||||
; [16 [[17]]]]]
|
||||
; @result)))))
|
||||
;
|
||||
;(deftest test-react-for-delete-node
|
||||
; "
|
||||
; [1 [[2 [[3 [[4]
|
||||
; [5]]]
|
||||
; [6 [[7 [[8]]]]]
|
||||
; [9 [[10]
|
||||
; [11]]]]]
|
||||
; [12 [[13]
|
||||
; [14]
|
||||
; [15]]]
|
||||
; [16 [[17]]]]]
|
||||
; "
|
||||
; (build-db-records node-tree)
|
||||
; (let [root (build-block 1 nil nil)
|
||||
; result (->> (render-react-tree root)
|
||||
; (r/with-key (str "root-" (tree/-get-id root))))]
|
||||
; (is (= [1 [[2 [[3 [[4]
|
||||
; [5]]]
|
||||
; [6 [[7 [[8]]]]]
|
||||
; [9 [[10]
|
||||
; [11]]]]]
|
||||
; [12 [[13]
|
||||
; [14]
|
||||
; [15]]]
|
||||
; [16 [[17]]]]]
|
||||
; @result))
|
||||
; (let [node (build-block 6 2 3)]
|
||||
; (outliner-core/delete-node node)
|
||||
; (is (= [1 [[2 [[3 [[4]
|
||||
; [5]]]
|
||||
; [9 [[10]
|
||||
; [11]]]]]
|
||||
; [12 [[13]
|
||||
; [14]
|
||||
; [15]]]
|
||||
; [16 [[17]]]]]
|
||||
; @result)))))
|
||||
;
|
||||
;(deftest test-react-for-move-subtree
|
||||
; "
|
||||
; [1 [[2 [[3 [[4]
|
||||
; [5]]]
|
||||
; [6 [[7 [[8]]]]]
|
||||
; [9 [[10]
|
||||
; [11]]]]]
|
||||
; [12 [[13]
|
||||
; [14]
|
||||
; [15]]]
|
||||
; [16 [[17]]]]]
|
||||
; "
|
||||
; (build-db-records node-tree)
|
||||
; (let [root (build-block 1 nil nil)
|
||||
; result (->> (render-react-tree root)
|
||||
; (r/with-key (str "root-" (tree/-get-id root))))]
|
||||
; (is (= [1 [[2 [[3 [[4]
|
||||
; [5]]]
|
||||
; [6 [[7 [[8]]]]]
|
||||
; [9 [[10]
|
||||
; [11]]]]]
|
||||
; [12 [[13]
|
||||
; [14]
|
||||
; [15]]]
|
||||
; [16 [[17]]]]]
|
||||
; @result))
|
||||
; (let [node (build-block 3 2 2)
|
||||
; new-parent (build-block 12 1 2)
|
||||
; new-left (build-block 14 12 13)]
|
||||
; (outliner-core/move-subtree node new-parent new-left)
|
||||
; (is (= [1 [[2 [[6 [[7 [[8]]]]]
|
||||
; [9 [[10]
|
||||
; [11]]]]]
|
||||
; [12 [[13]
|
||||
; [14]
|
||||
; [3 [[4]
|
||||
; [5]]]
|
||||
; [15]]]
|
||||
; [16 [[17]]]]]
|
||||
; @result)))))
|
||||
|
||||
@@ -4,12 +4,14 @@
|
||||
[cljs-run-test :refer [run-test]]
|
||||
[frontend.modules.outliner.datascript :as ds]))
|
||||
|
||||
(use-fixtures :each fixtures/reset-db)
|
||||
(use-fixtures :each
|
||||
fixtures/load-test-env
|
||||
fixtures/reset-db)
|
||||
|
||||
(deftest test-with-db-macro
|
||||
(let [db-report (ds/auto-transact! [txs-state (ds/new-outliner-txs-state)]
|
||||
nil
|
||||
(let [datom [{:block/uuid #uuid"606c1962-ad7f-424e-b120-0dc7fcb25415",
|
||||
:block/left #:txs-state{:id 46},
|
||||
:block/refs (),
|
||||
:block/anchor "level_2123123",
|
||||
:block/repo "logseq_local_test_navtive_fs",
|
||||
@@ -22,33 +24,18 @@
|
||||
:block/refs-with-children (),
|
||||
:block/content "level test",
|
||||
:db/id 72,
|
||||
:block/path-refs (),
|
||||
:block/parent #:txs-state{:id 26},
|
||||
:block/page #:txs-state{:id 26},
|
||||
:block/file #:txs-state{:id 20}}]]
|
||||
:block/path-refs (),}]]
|
||||
(ds/add-txs txs-state datom)))
|
||||
rt [[72
|
||||
:block/uuid
|
||||
#uuid "606c1962-ad7f-424e-b120-0dc7fcb25415"
|
||||
536870913
|
||||
true]
|
||||
[72 :block/left 46 536870913 true]
|
||||
rt [[72 :block/uuid #uuid "606c1962-ad7f-424e-b120-0dc7fcb25415" 536870913 true]
|
||||
[72 :block/anchor "level_2123123" 536870913 true]
|
||||
[72 :block/repo "logseq_local_test_navtive_fs" 536870913 true]
|
||||
[72 :block/body [] 536870913 true]
|
||||
[72
|
||||
:block/meta
|
||||
{:timestamps [], :properties [], :start-pos 0, :end-pos 15}
|
||||
536870913
|
||||
true]
|
||||
[72 :block/meta {:timestamps [], :properties [], :start-pos 0, :end-pos 15} 536870913 true]
|
||||
[72 :block/format :markdown 536870913 true]
|
||||
[72 :block/level 1 536870913 true]
|
||||
[72 :block/title [["Plain" "level 2123123"]] 536870913 true]
|
||||
[72 :block/refs-with-children () 536870913 true]
|
||||
[72 :block/content "level test" 536870913 true]
|
||||
[72 :block/parent 26 536870913 true]
|
||||
[72 :block/page 26 536870913 true]
|
||||
[72 :block/file 20 536870913 true]]]
|
||||
[72 :block/content "level test" 536870913 true]]]
|
||||
(is (= rt (mapv vec (:tx-data db-report))))))
|
||||
|
||||
(comment
|
||||
|
||||
Reference in New Issue
Block a user