mirror of
https://github.com/logseq/logseq.git
synced 2026-04-24 14:14:55 +00:00
Add tests for timestamp blocks
Also make block attributes more explicit in pre-block and reduce needless coupling
This commit is contained in:
committed by
Gabriel Horner
parent
6506c369e8
commit
6108aa1036
@@ -526,21 +526,24 @@
|
||||
(when (coll? refs)
|
||||
refs))))
|
||||
(map :block/original-name))
|
||||
block {:uuid id
|
||||
:content content
|
||||
:level 1
|
||||
:properties properties
|
||||
:properties-order (vec properties-order)
|
||||
:properties-text-values properties-text-values
|
||||
:invalid-properties invalid-properties
|
||||
:refs property-refs
|
||||
:pre-block? true
|
||||
:unordered true
|
||||
:macros (extract-macros-from-ast body)
|
||||
:body body}
|
||||
block (with-page-block-refs block false supported-formats db date-formatter)
|
||||
block' (update block :refs concat (:block-refs pre-block-properties))]
|
||||
(block-keywordize block'))
|
||||
block {:block/uuid id
|
||||
:block/content content
|
||||
:block/level 1
|
||||
:block/properties properties
|
||||
:block/properties-order (vec properties-order)
|
||||
:block/properties-text-values properties-text-values
|
||||
:block/invalid-properties invalid-properties
|
||||
:block/pre-block? true
|
||||
:block/unordered true
|
||||
:block/macros (extract-macros-from-ast body)
|
||||
:block/body body}
|
||||
{:keys [tags refs]}
|
||||
(with-page-block-refs {:body body :refs property-refs} false supported-formats db date-formatter)]
|
||||
(cond-> block
|
||||
tags
|
||||
(assoc :block/tags tags)
|
||||
true
|
||||
(assoc :block/refs (concat refs (:block-refs pre-block-properties)))))
|
||||
(select-keys first-block [:block/format :block/page]))
|
||||
blocks)
|
||||
blocks)]
|
||||
|
||||
@@ -110,30 +110,32 @@
|
||||
{:property-pages/enabled? true})))
|
||||
"Only editable linkable built-in properties have page-refs in property values")))
|
||||
|
||||
(defn find-block-for-content
|
||||
[db content]
|
||||
(->> (d/q '[:find (pull ?b [* {:block/refs [:block/uuid]}])
|
||||
:in $ ?content
|
||||
:where [?b :block/content ?content]]
|
||||
db
|
||||
content)
|
||||
(map first)
|
||||
first))
|
||||
|
||||
(deftest refs-from-block-refs
|
||||
(let [conn (ldb/start-conn)
|
||||
id "63f528da-284a-45d1-ac9c-5d6a7435f6b4"
|
||||
block (str "A block\nid:: " id)
|
||||
block-ref-via-content (str "Link to " (block-ref/->block-ref id))
|
||||
block-ref-via-block-properties (str "B block\nref:: " (block-ref/->block-ref id))
|
||||
body (str "- " block "\n- " block-ref-via-content "\n- " block-ref-via-block-properties)
|
||||
find-block-for-content (fn [content]
|
||||
(->> (d/q '[:find (pull ?b [:block/content {:block/refs [:block/uuid]}])
|
||||
:in $ ?content
|
||||
:where [?b :block/content ?content]]
|
||||
@conn
|
||||
content)
|
||||
(map first)
|
||||
first))]
|
||||
body (str "- " block "\n- " block-ref-via-content "\n- " block-ref-via-block-properties)]
|
||||
(graph-parser/parse-file conn "foo.md" body {})
|
||||
|
||||
(testing "Block refs in blocks"
|
||||
(is (= [{:block/uuid (uuid id)}]
|
||||
(:block/refs (find-block-for-content block-ref-via-content)))
|
||||
(:block/refs (find-block-for-content @conn block-ref-via-content)))
|
||||
"Block that links to a block via paragraph content has correct block ref")
|
||||
|
||||
(is (contains?
|
||||
(set (:block/refs (find-block-for-content block-ref-via-block-properties)))
|
||||
(set (:block/refs (find-block-for-content @conn block-ref-via-block-properties)))
|
||||
{:block/uuid (uuid id)})
|
||||
"Block that links to a block via block properties has correct block ref"))
|
||||
|
||||
@@ -141,6 +143,21 @@
|
||||
(let [block-ref-via-page-properties (str "page-ref:: " (block-ref/->block-ref id))]
|
||||
(graph-parser/parse-file conn "foo2.md" block-ref-via-page-properties {})
|
||||
(is (contains?
|
||||
(set (:block/refs (find-block-for-content block-ref-via-page-properties)))
|
||||
(set (:block/refs (find-block-for-content @conn block-ref-via-page-properties)))
|
||||
{:block/uuid (uuid id)})
|
||||
"Block that links to a block via page properties has correct block ref")))))
|
||||
|
||||
(deftest timestamp-blocks
|
||||
(let [conn (ldb/start-conn)
|
||||
deadline-block "do something\nDEADLINE: <2023-02-21 Tue>"
|
||||
scheduled-block "do something else\nSCHEDULED: <2023-02-20 Mon>"
|
||||
body (str "- " deadline-block "\n- " scheduled-block)]
|
||||
(graph-parser/parse-file conn "foo.md" body {})
|
||||
|
||||
(is (= 20230220
|
||||
(:block/scheduled (find-block-for-content @conn scheduled-block)))
|
||||
"Scheduled block has correct block attribute and value")
|
||||
|
||||
(is (= 20230221
|
||||
(:block/deadline (find-block-for-content @conn deadline-block)))
|
||||
"Deadline block has correct block attribute and value")))
|
||||
|
||||
Reference in New Issue
Block a user