mirror of
https://github.com/logseq/logseq.git
synced 2026-06-01 19:01:22 +00:00
refactor: move db graph page operations to outliner dep
This commit is contained in:
@@ -1,109 +0,0 @@
|
||||
(ns frontend.worker.handler.page.db-based.page-test
|
||||
(:require [cljs.test :refer [deftest is testing]]
|
||||
[datascript.core :as d]
|
||||
[frontend.worker.handler.page.db-based.page :as worker-db-page]
|
||||
[logseq.common.config :as common-config]
|
||||
[logseq.db :as ldb]
|
||||
[logseq.db.frontend.db :as db-db]
|
||||
[logseq.db.test.helper :as db-test]))
|
||||
|
||||
(deftest create-class
|
||||
(let [conn (db-test/create-conn)
|
||||
_ (worker-db-page/create! conn "movie" {:class? true})
|
||||
_ (worker-db-page/create! conn "Movie" {:class? true})
|
||||
movie-class (ldb/get-case-page @conn "movie")
|
||||
Movie-class (ldb/get-case-page @conn "Movie")]
|
||||
|
||||
(is (ldb/class? movie-class) "Creates a class")
|
||||
(is (ldb/class? Movie-class) "Creates another class with a different case sensitive name")
|
||||
(is (not= movie-class Movie-class) "The two classes are not the same")))
|
||||
|
||||
(deftest create-namespace-pages
|
||||
(let [conn (db-test/create-conn-with-blocks
|
||||
{:properties {:user.property/property1 {:logseq.property/type :default}}
|
||||
:classes {:class1 {}}
|
||||
:pages-and-blocks [{:page {:block/title "page1"}}]})]
|
||||
|
||||
(testing "Basic valid workflows"
|
||||
(let [[_ child-uuid] (worker-db-page/create! conn "foo/bar/baz" {:split-namespace? true})
|
||||
child-page (d/entity @conn [:block/uuid child-uuid])
|
||||
;; Create a 2nd child page using existing parent pages
|
||||
[_ child-uuid2] (worker-db-page/create! conn "foo/bar/baz2" {:split-namespace? true})
|
||||
child-page2 (d/entity @conn [:block/uuid child-uuid2])
|
||||
;; Create a child page for a class
|
||||
[_ child-uuid3] (worker-db-page/create! conn "c1/c2" {:split-namespace? true :class? true})
|
||||
child-page3 (d/entity @conn [:block/uuid child-uuid3])
|
||||
library (ldb/get-built-in-page @conn common-config/library-page-name)
|
||||
bar (ldb/get-page @conn "bar")]
|
||||
(is (= ["foo"] (map :block/title (:block/_parent library)))
|
||||
"Namespace (non-class) pages are added to the Library page")
|
||||
(is (= ["baz" "baz2"] (map :block/title (:block/_parent bar)))
|
||||
"Child pages are created under the same parent")
|
||||
(is (= ["foo" "bar"] (map :block/title [(:block/parent (:block/parent child-page))
|
||||
(:block/parent child-page)]))
|
||||
"Child page with new parent has correct parents")
|
||||
(is (= (map :block/uuid (db-db/get-page-parents child-page))
|
||||
(map :block/uuid (db-db/get-page-parents child-page2)))
|
||||
"Child page with existing parents has correct parents")
|
||||
(is (= #{"Root Tag" "c1"} (set (map :block/title (ldb/get-classes-parents [child-page3]))))
|
||||
"Child class with new parent has correct parents")
|
||||
|
||||
(worker-db-page/create! conn "foo/class1/baz3" {:split-namespace? true})
|
||||
(is (= #{"Tag" "Page"}
|
||||
(set (d/q '[:find [?tag-title ...]
|
||||
:where
|
||||
[?b :block/title "class1"]
|
||||
[?b :block/tags ?t]
|
||||
[?t :block/title ?tag-title]] @conn)))
|
||||
"Using an existing class page in a multi-parent namespace doesn't allow a page to have a class parent and instead creates a new page")))
|
||||
|
||||
(testing "Child pages with same name and different parents"
|
||||
(let [_ (worker-db-page/create! conn "vim/keys" {:split-namespace? true})
|
||||
_ (worker-db-page/create! conn "emacs/keys" {:split-namespace? true})]
|
||||
(is (= #{"vim" "emacs"}
|
||||
(->> (d/q '[:find [(pull ?b [{:block/parent [:block/title]}]) ...] :where [?b :block/title "keys"]] @conn)
|
||||
(map #(get-in % [:block/parent :block/title]))
|
||||
set))
|
||||
"Two child pages with same name exist and have different parents")))
|
||||
|
||||
(testing "Invalid workflows"
|
||||
(is (thrown-with-msg?
|
||||
js/Error
|
||||
#"Cannot create"
|
||||
(worker-db-page/create! conn "class1/page" {:split-namespace? true}))
|
||||
"Page can't have a class parent")
|
||||
(is (thrown-with-msg?
|
||||
js/Error
|
||||
#"Cannot create"
|
||||
(worker-db-page/create! conn "property1/page" {:split-namespace? true}))
|
||||
"Page can't have a property parent")
|
||||
(is (thrown-with-msg?
|
||||
js/Error
|
||||
#"Cannot create"
|
||||
(worker-db-page/create! conn "property1/class" {:split-namespace? true :class? true}))
|
||||
"Class can't have a property parent"))))
|
||||
|
||||
(deftest create-page
|
||||
(let [conn (db-test/create-conn)
|
||||
[_ page-uuid] (worker-db-page/create! conn "fooz" {})]
|
||||
(is (= "fooz" (:block/title (d/entity @conn [:block/uuid page-uuid])))
|
||||
"Page created correctly")
|
||||
|
||||
(is (thrown-with-msg?
|
||||
js/Error
|
||||
#"can't include \"/"
|
||||
(worker-db-page/create! conn "foo/bar" {}))
|
||||
"Page can't have '/'n title")))
|
||||
|
||||
(deftest create-journal
|
||||
(let [conn (db-test/create-conn)
|
||||
[_ page-uuid] (worker-db-page/create! conn "Dec 16th, 2024" {})]
|
||||
|
||||
(is (= "Dec 16th, 2024" (:block/title (d/entity @conn [:block/uuid page-uuid])))
|
||||
"Journal created correctly")
|
||||
|
||||
(is (= [:logseq.class/Journal]
|
||||
(->> (d/entity @conn [:block/uuid page-uuid])
|
||||
:block/tags
|
||||
(map #(:db/ident (d/entity @conn (:db/id %))))))
|
||||
"New journal only has Journal tag")))
|
||||
Reference in New Issue
Block a user