瀏覽代碼

chore: add more db-import tests

Test for float and ref block/content replacement. Part of LOG-3092
Gabriel Horner 1 年之前
父節點
當前提交
21f959e5c0

+ 24 - 3
deps/graph-parser/test/logseq/graph_parser/exporter_test.cljs

@@ -142,7 +142,7 @@
 
       ;; Counts
       ;; Includes journals as property values e.g. :logseq.task/deadline
-      (is (= 14 (count (d/q '[:find ?b :where [?b :block/type "journal"]] @conn))))
+      (is (= 16 (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 (= 4
@@ -169,7 +169,7 @@
               set))))
 
     (testing "user properties"
-      (is (= 14
+      (is (= 15
              (->> @conn
                   (d/q '[:find [(pull ?b [:db/ident]) ...]
                          :where [?b :block/type "property"]])
@@ -216,7 +216,11 @@
               :user.property/prop-num 5
               :user.property/prop-string "yeehaw"}
              (readable-properties @conn (find-page-by-name @conn "some page")))
-          "Existing page has correct properties"))
+          "Existing page has correct properties")
+
+      (is (= {:user.property/rating 5.5}
+             (readable-properties @conn (find-block-by-content @conn ":rating float")))
+          "Block with float property imports as a float"))
 
     (testing "built-in properties"
       (is (= [(:db/id (find-block-by-content @conn "original block"))]
@@ -281,6 +285,23 @@
              (:user.property/description (readable-properties @conn (find-block-by-content @conn #":default to :page"))))
           ":page property value correctly saved as :default with full text"))
 
+    (testing "replacing refs in :block/content"
+      (is (= 2
+             (->> (find-block-by-content @conn #"replace with same start string")
+                  :block/content
+                  (re-seq #"\[\[~\^\S+\]\]")
+                  distinct
+                  count))
+          "A block with ref names that start with same string has 2 distinct refs")
+
+      (is (= 1
+             (->> (find-block-by-content @conn #"replace case insensitive")
+                  :block/content
+                  (re-seq #"\[\[~\^\S+\]\]")
+                  distinct
+                  count))
+          "A block with different case of same ref names has 1 distinct ref"))
+
     (testing "tags without tag options"
       (let [block (find-block-by-content @conn #"Inception")
             tag-page (find-page-by-name @conn "Movie")

+ 1 - 1
deps/graph-parser/test/resources/exporter-test-graph/journals/2024_02_16.md

@@ -3,7 +3,7 @@
   finishedAt:: [[Feb 7th, 2024]]
 - test :date -> :page
   finishedAt:: [[Gabriel]]
-- MEETING TITLE #Meeting
+- MEETING TITLE
   template:: meeting
   participants:: TODO
 - pending block for :number to :default

+ 10 - 0
deps/graph-parser/test/resources/exporter-test-graph/journals/2024_02_29.md

@@ -0,0 +1,10 @@
+- b1
+  rating:: 5
+- :rating float
+  rating:: 5.5
+- query-table:: false
+  FIXME
+  #+BEGIN_QUERY
+  {:title "2nd level tasks with `#p1`"
+  :query (and (task todo doing) [[p1]])}
+  #+END_QUERY

+ 5 - 0
deps/graph-parser/test/resources/exporter-test-graph/journals/2024_03_01.md

@@ -0,0 +1,5 @@
+- test ignore blank values so that property type doesn't change
+  sameAs::
+- replace tags edge cases
+	- replace with same start string #foo #foo-bar
+	- replace case insensitive #foo #Foo