From fbb8f9619171cd8adca237de2d0171bba5b846eb Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Mon, 4 Dec 2023 16:26:12 +0800 Subject: [PATCH] fix: tests --- src/main/frontend/components/property/value.cljs | 12 +++++------- src/main/frontend/handler/db_based/property.cljs | 15 +++++++++++++++ .../frontend/handler/db_based/property_test.cljs | 5 ++--- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/main/frontend/components/property/value.cljs b/src/main/frontend/components/property/value.cljs index d852f74edc..02833300c2 100644 --- a/src/main/frontend/components/property/value.cljs +++ b/src/main/frontend/components/property/value.cljs @@ -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" diff --git a/src/main/frontend/handler/db_based/property.cljs b/src/main/frontend/handler/db_based/property.cljs index c76b5b0a57..f666e0263f 100644 --- a/src/main/frontend/handler/db_based/property.cljs +++ b/src/main/frontend/handler/db_based/property.cljs @@ -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)) diff --git a/src/test/frontend/handler/db_based/property_test.cljs b/src/test/frontend/handler/db_based/property_test.cljs index e9ead0e573..95127f38d1 100644 --- a/src/test/frontend/handler/db_based/property_test.cljs +++ b/src/test/frontend/handler/db_based/property_test.cljs @@ -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)))))))