fix: tests

feat/datascript-storage-test
Tienson Qin 2023-12-04 16:26:12 +08:00
parent e6bc77e8b5
commit fbb8f96191
3 changed files with 22 additions and 10 deletions

View File

@ -308,13 +308,11 @@
(defn create-new-block!
[block property value]
(let [repo (state/get-current-repo)
{:keys [page blocks]} (db-property-handler/property-create-new-block block property value editor-handler/wrap-parse-block)
last-block-id (:block/uuid (last blocks))]
(db/transact! repo (if page (cons page blocks) blocks) {:outliner-op :insert-blocks})
(add-property! block (:block/original-name property) (:block/uuid (first blocks)))
(editor-handler/edit-block! (db/entity [:block/uuid last-block-id]) :max last-block-id)
last-block-id))
(let [last-block-id (db-property-handler/create-property-text-block! block property value
editor-handler/wrap-parse-block
{})]
(editor-handler/edit-block! (db/entity [:block/uuid last-block-id]) :max last-block-id)))
(defn create-new-block-from-template!
"`template`: tag block"

View File

@ -592,6 +592,21 @@
{:page page-tx
:blocks [parent child-1]}))
(defn create-property-text-block!
[block property value parse-block {:keys [class-schema?]}]
(let [repo (state/get-current-repo)
{:keys [page blocks]} (property-create-new-block block property value parse-block)
first-block (first blocks)
last-block-id (:block/uuid (last blocks))
class? (contains? (:block/type block) "class")
property-key (:block/original-name property)]
(db/transact! repo (if page (cons page blocks) blocks) {:outliner-op :insert-blocks})
(when property-key
(if (and class? class-schema?)
(class-add-property! repo (:block/uuid block) property-key)
(set-block-property! repo (:block/uuid block) property-key (:block/uuid first-block) {})))
last-block-id))
(defn property-create-new-block-from-template
[block property template]
(let [current-page-id (:block/uuid (or (:block/page block) block))

View File

@ -7,8 +7,7 @@
[frontend.handler.property.util :as pu]
[frontend.state :as state]
[frontend.handler.page :as page-handler]
[frontend.handler.editor :as editor-handler]
[frontend.components.property.value :as component-pv]))
[frontend.handler.editor :as editor-handler]))
(def repo test-helper/test-db-name-db-version)
@ -291,7 +290,7 @@
;; add property
(db-property-handler/upsert-property! repo k {:type :default} {})
(let [property (db/entity [:block/name k])
last-block-id (component-pv/create-new-block! fb property "Block content")
last-block-id (db-property-handler/create-property-text-block! fb property "Block content" editor-handler/wrap-parse-block {})
{:keys [from-block-id from-property-id]} (db-property-handler/get-property-block-created-block [:block/uuid last-block-id])]
(is (= from-block-id (:db/id fb)))
(is (= from-property-id (:db/id property)))))))