mirror of https://github.com/logseq/logseq
fix: tests
parent
37f0893b01
commit
b9bc4130e9
|
@ -204,15 +204,16 @@
|
|||
(defn with-whiteboard-block-props
|
||||
[block page-name]
|
||||
(let [shape (:block/properties block)
|
||||
shape? (= :whiteboard-shape (:ls-type shape))]
|
||||
shape? (= :whiteboard-shape (:ls-type shape))
|
||||
default-page-ref {:block/name (gp-util/page-name-sanity-lc page-name)}]
|
||||
(merge (when shape?
|
||||
(merge
|
||||
{:block/uuid (uuid (:id shape))}
|
||||
(with-whiteboard-block-refs shape)
|
||||
(with-whiteboard-content shape)))
|
||||
(when (nil? (:block/parent block)) {:block/name (gp-util/page-name-sanity-lc page-name)})
|
||||
(when (nil? (:block/format block)) {:block/format :markdown})
|
||||
{:block/page {:block/name (gp-util/page-name-sanity-lc page-name)}})))
|
||||
(when (nil? (:block/parent block)) {:block/parent default-page-ref})
|
||||
(when (nil? (:block/format block)) {:block/format :markdown}) ;; TODO: read from config
|
||||
{:block/page default-page-ref})))
|
||||
|
||||
(defn extract-whiteboard-edn
|
||||
"Extracts whiteboard page from given edn file
|
||||
|
@ -224,7 +225,8 @@
|
|||
{:keys [pages blocks]} (gp-util/safe-read-string content)
|
||||
page-block (first pages)
|
||||
page-name (filepath->page-name file)
|
||||
page-entity (build-page-entity {} file page-name page-name nil options)
|
||||
page-original-name (or (:block/original-name page-block) page-name)
|
||||
page-entity (build-page-entity (:block/properties page-block) file page-name page-original-name nil options)
|
||||
page-block (merge page-block page-entity (when-not (:block/uuid page-block) {:block/uuid (d/squuid)}))
|
||||
blocks (->> blocks
|
||||
(map #(merge % {:block/level 1 ;; fixme
|
||||
|
@ -233,7 +235,7 @@
|
|||
(with-whiteboard-block-props % page-name)))
|
||||
(gp-block/with-parent-and-left {:block/name page-name}))
|
||||
_ (when verbose (println "Parsing finished: " file))]
|
||||
{:pages [page-block]
|
||||
{:pages (list page-block)
|
||||
:blocks blocks}))
|
||||
|
||||
(defn- with-block-uuid
|
||||
|
|
|
@ -68,22 +68,23 @@
|
|||
(def foo-edn
|
||||
"Example exported whiteboard page as an edn exportable."
|
||||
'{:blocks
|
||||
[{:block/content "foo content a",
|
||||
:block/format :markdown,
|
||||
:block/unordered true},
|
||||
({:block/content "foo content a",
|
||||
:block/format :markdown},
|
||||
{:block/content "foo content b",
|
||||
:block/format :markdown,
|
||||
:block/unordered true}],
|
||||
:block/format :markdown}),
|
||||
:pages
|
||||
({:block/format :markdown,
|
||||
:block/whiteboard? true,
|
||||
:block/original-name "my foo whiteboard"})})
|
||||
:block/original-name "Foo"
|
||||
:block/properties {:title "my whiteboard foo"}})})
|
||||
|
||||
(extract/extract-whiteboard-edn "/whiteboards/foo.edn" (pr-str foo-edn) {})
|
||||
|
||||
(deftest test-extract-whiteboard-edn
|
||||
[]
|
||||
(let [{:keys [pages blocks]} (extract/extract-whiteboard-edn "/whiteboards/foo.edn" (pr-str foo-edn) {})
|
||||
page (first pages)]
|
||||
(is (= (get-in page [:block/file :file/path]) "/whiteboards/foo.edn"))
|
||||
(is (= (get-in page [:block/name]) "foo"))
|
||||
(is (= (:block/name page) "foo"))
|
||||
(is (= (:block/original-name page) "Foo"))
|
||||
(is (every? #(= (:block/parent %) {:block/name "foo"}) blocks))
|
||||
(is (= (:block/uuid (first blocks)) (get-in (second blocks) [:block/left 1])))))
|
||||
|
|
|
@ -9,13 +9,14 @@
|
|||
(def foo-edn
|
||||
"Example exported whiteboard page as an edn exportable."
|
||||
'{:blocks
|
||||
[{:block/content "foo content",
|
||||
:block/format :markdown,
|
||||
:block/unordered true}],
|
||||
({:block/content "foo content a",
|
||||
:block/format :markdown},
|
||||
{:block/content "foo content b",
|
||||
:block/format :markdown}),
|
||||
:pages
|
||||
({:block/format :markdown,
|
||||
:block/whiteboard? true,
|
||||
:block/original-name "my foo whiteboard"})})
|
||||
:block/original-name "Foo"
|
||||
:block/properties {:title "my whiteboard foo"}})})
|
||||
|
||||
(deftest parse-file
|
||||
(testing "id properties"
|
||||
|
|
|
@ -28,8 +28,7 @@
|
|||
:block/format
|
||||
{:block/page [:block/name :block/uuid]}
|
||||
{:block/left [:block/name :block/uuid]}
|
||||
{:block/parent [:block/name :block/uuid]}
|
||||
{:block/path-refs [:block/name :block/uuid]}])
|
||||
{:block/parent [:block/name :block/uuid]}])
|
||||
|
||||
(defn do-write-file!
|
||||
[repo page-db-id]
|
||||
|
@ -39,7 +38,13 @@
|
|||
repo (:block/name page-block)
|
||||
{:pull-keys (if whiteboard? whiteboard-blocks-pull-keys-with-persisted-ids '[*])})
|
||||
blocks (map #(if (get-in % [:block/properties :ls-type] false)
|
||||
(dissoc % :block/content :block/format) %) blocks)]
|
||||
(dissoc %
|
||||
:block/content
|
||||
:block/format
|
||||
:block/left
|
||||
:block/page
|
||||
:block/parent) ;; these are auto-generated for whiteboard shapes
|
||||
%) blocks)]
|
||||
(when-not (and (= 1 (count blocks))
|
||||
(string/blank? (:block/content (first blocks)))
|
||||
(nil? (:block/file page-block)))
|
||||
|
|
Loading…
Reference in New Issue