chore: add more property tests for db import

Part of LOG-3092
feat/asset-sync
Gabriel Horner 2024-07-08 15:38:13 -04:00
parent 057d6b459f
commit 13048a901c
4 changed files with 56 additions and 24 deletions

View File

@ -141,11 +141,14 @@
;; Counts
;; Includes 2 journals as property values for :logseq.task/deadline
(is (= 9 (count (d/q '[:find ?b :where [?b :block/type "journal"]] @conn))))
;; Count includes Contents and page references
(is (= 9
(count (->> (d/q '[:find [(pull ?b [:block/original-name :block/type]) ...] :where [?b :block/original-name]] @conn)
(filter #(= ["page"] (:block/type %)))))))
(is (= 10 (count (d/q '[:find ?b :where [?b :block/type "journal"]] @conn))))
;; Don't count pages like url.md that have properties but no content
(is (= 5
(count (->> (d/q '[:find [(pull ?b [:block/original-name :block/type]) ...]
:where [?b :block/original-name] [_ :block/page ?b]] @conn)
(filter #(= ["page"] (:block/type %))))))
"Correct number of pages with block content")
(is (= 1 (count @assets))))
(testing "logseq files"
@ -155,30 +158,38 @@
(ffirst (d/q '[:find ?content :where [?b :file/path "logseq/custom.js"] [?b :file/content ?content]] @conn)))))
(testing "favorites"
(is (= #{"Interstellar" "some page"}
(->>
(ldb/get-page-blocks @conn
(:db/id (ldb/get-page @conn common-config/favorites-page-name))
{:pull-keys '[* {:block/link [:block/original-name]}]})
(map #(get-in % [:block/link :block/original-name]))
set))))
(is (= #{"Interstellar" "some page"}
(->>
(ldb/get-page-blocks @conn
(:db/id (ldb/get-page @conn common-config/favorites-page-name))
{:pull-keys '[* {:block/link [:block/original-name]}]})
(map #(get-in % [:block/link :block/original-name]))
set))))
(testing "user properties"
(is (= 12
(->> @conn
(d/q '[:find [(pull ?b [:db/ident]) ...]
:where [?b :block/type "property"]])
(remove #(db-malli-schema/internal-ident? (:db/ident %)))
count))
"Correct number of user properties")
(is (= #{{:db/ident :user.property/prop-bool :block/schema {:type :checkbox}}
{:db/ident :user.property/prop-string :block/schema {:type :default}}
{:db/ident :user.property/prop-num :block/schema {:type :number}}
{:db/ident :user.property/prop-num2 :block/schema {:type :number}}
{:db/ident :user.property/type :block/schema {:type :page}}
{:db/ident :user.property/url :block/schema {:type :url}}
{:db/ident :user.property/sameas :block/schema {:type :url}}
{:db/ident :user.property/rangeincludes :block/schema {:type :page}}
{:db/ident :user.property/unique :block/schema {:type :checkbox}}}
{:db/ident :user.property/rangeincludes :block/schema {:type :page}}}
(->> @conn
(d/q '[:find [(pull ?b [:db/ident :block/schema]) ...]
:where [?b :block/type "property"]])
(remove #(db-malli-schema/internal-ident? (:db/ident %)))
(filter #(contains? #{:prop-bool :prop-string :prop-num :rangeincludes :url :sameas}
(keyword (name (:db/ident %)))))
set))
"Properties defined correctly")
"Main property types have correct inferred :type")
(is (= :default
(get-in (d/entity @conn :user.property/description) [:block/schema :type]))
"Property value consisting of text and refs is inferred as :default")
(is (= {:user.property/prop-bool true
:user.property/prop-num 5
@ -192,9 +203,6 @@
(map :block/original-name)
set))
"Block with properties has correct refs")
(is (= #{"Uri"}
(:user.property/rangeincludes (readable-properties @conn (find-page-by-name @conn "url"))))
"Block with :page property is correct")
(is (= {:user.property/prop-num2 10}
(readable-properties @conn (find-page-by-name @conn "new page")))
@ -228,7 +236,11 @@
(is (= #{:logseq.task/status :block/tags}
(set (keys (readable-properties @conn (find-block-by-content @conn "old todo block")))))
"old task properties are ignored")
"old task properties like 'todo' are ignored")
(is (= {:logseq.property/order-list-type "number"}
(readable-properties @conn (find-block-by-content @conn "list one")))
"numered block has correct property")
(is (= {:logseq.property/query-sort-by :user.property/prop-num
:logseq.property/query-properties [:block :page :user.property/prop-string :user.property/prop-num]
@ -262,6 +274,9 @@
another-tag-page (find-page-by-name @conn "p0")]
(is (= (:block/content block) "Inception")
"tagged block with configured tag strips tag from content")
(is (= [:user.class/Movie]
(:block/tags (readable-properties @conn block)))
"tagged block has configured tag imported as a class")
(is (= ["class" "page"] (:block/type tag-page))
"configured tag page in :tag-classes is a class")
@ -282,6 +297,13 @@
tag-page (find-page-by-name @conn "Movie")]
(is (= (:block/content block) "The Creator")
"tagged block with configured tag strips tag from content")
(is (= [:user.class/Movie]
(:block/tags (readable-properties @conn block)))
"tagged block has configured tag imported as a class")
(is (= (:user.property/testtagclass block) (:block/tags block))
"tagged block can have another property that references the same class it is tagged with,
without creating a duplicate class")
(is (= ["class" "page"] (:block/type tag-page))
"configured tag page derived from :property-classes is a class")
(is (nil? (find-page-by-name @conn "type"))

View File

@ -0,0 +1,10 @@
- b1
duration:: 20
- Review 15 candidates #Meeting
participants:: [[Gabriel]] [[Jakob]]
description:: [[Jakob]] thought candidate was #awesome
- numbered list
- list one
logseq.order-list-type:: number
- list two
logseq.order-list-type:: number

View File

@ -1,2 +1,3 @@
- The Creator
type:: [[Movie]]
type:: [[Movie]]
testTagClass:: #Movie

View File

@ -2,4 +2,3 @@ type:: [[Property]]
url:: {{docs-base-url url}}
sameAs:: https://schema.org/url
rangeIncludes:: [[Uri]]
unique:: true