diff --git a/deps/outliner/src/logseq/outliner/property.cljs b/deps/outliner/src/logseq/outliner/property.cljs index c03312df8..aafef1d16 100644 --- a/deps/outliner/src/logseq/outliner/property.cljs +++ b/deps/outliner/src/logseq/outliner/property.cljs @@ -522,13 +522,6 @@ {:db/id property-id})]] (ldb/transact! conn tx-data))))) -(defn get-property-block-created-block - "Get the root block and property that created this property block." - [db eid] - (let [block (d/entity db eid) - created-from-property (:logseq.property/created-from-property block)] - {:from-property-id (:db/id created-from-property)})) - (defn class-add-property! [conn class-id property-id] (when-let [class (d/entity @conn class-id)] diff --git a/deps/outliner/test/logseq/outliner/property_test.cljs b/deps/outliner/test/logseq/outliner/property_test.cljs index 6d62c03a8..aa83df537 100644 --- a/deps/outliner/test/logseq/outliner/property_test.cljs +++ b/deps/outliner/test/logseq/outliner/property_test.cljs @@ -4,7 +4,8 @@ [datascript.core :as d] [logseq.db.sqlite.create-graph :as sqlite-create-graph] [logseq.db.sqlite.build :as sqlite-build] - [logseq.outliner.property :as outliner-property])) + [logseq.outliner.property :as outliner-property] + [logseq.db.frontend.property :as db-property])) (defn- find-block-by-content [conn content] (->> content @@ -14,15 +15,53 @@ @conn) first)) +(defn- create-conn-with-blocks [opts] + (let [conn (d/create-conn db-schema/schema-for-db-based-graph) + _ (d/transact! conn (sqlite-create-graph/build-db-initial-data "{}")) + _ (sqlite-build/create-blocks conn opts)] + conn)) + +(deftest create-property-text-block! + (testing "Create a new :default property value" + (let [conn (create-conn-with-blocks + [{:page {:block/original-name "page1"} + :blocks [{:block/content "b1" :build/properties {:default "foo"}} + {:block/content "b2"}]}]) + block (find-block-by-content conn "b2") + ;; Use same args as outliner.op + _ (outliner-property/create-property-text-block! conn (:db/id block) :user.property/default "" {}) + new-property-value (:user.property/default (find-block-by-content conn "b2"))] + + (is (some? (:db/id new-property-value)) "New property value created") + (is (= "" (db-property/ref->property-value-content @conn new-property-value)) + "Property value has correct content") + (is (= :user.property/default + (get-in (d/entity @conn (:db/id new-property-value)) [:logseq.property/created-from-property :db/ident])) + "Has correct created-from-property"))) + + (testing "Create a new :number property value" + (let [conn (create-conn-with-blocks + [{:page {:block/original-name "page1"} + :blocks [{:block/content "b1" :build/properties {:num 2}} + {:block/content "b2"}]}]) + block (find-block-by-content conn "b2") + ;; Use same args as outliner.op + _ (outliner-property/create-property-text-block! conn (:db/id block) :user.property/num "3" {}) + new-property-value (:user.property/num (find-block-by-content conn "b2"))] + + (is (some? (:db/id new-property-value)) "New property value created") + (is (= 3 (db-property/ref->property-value-content @conn new-property-value)) + "Property value has correct content") + (is (= :user.property/num + (get-in (d/entity @conn (:db/id new-property-value)) [:logseq.property/created-from-property :db/ident])) + "Has correct created-from-property")))) + (deftest set-block-property-with-ref-values (testing "Select a :number value from existing values" - (let [conn (d/create-conn db-schema/schema-for-db-based-graph) - _ (d/transact! conn (sqlite-create-graph/build-db-initial-data "{}")) - _ (sqlite-build/create-blocks - conn - [{:page {:block/original-name "page1"} - :blocks [{:block/content "b1" :build/properties {:num 2}} - {:block/content "b2"}]}]) + (let [conn (create-conn-with-blocks + [{:page {:block/original-name "page1"} + :blocks [{:block/content "b1" :build/properties {:num 2}} + {:block/content "b2"}]}]) property-value (:user.property/num (find-block-by-content conn "b1")) _ (assert (:db/id property-value)) block-uuid (:block/uuid (find-block-by-content conn "b2")) @@ -33,13 +72,10 @@ (deftest set-block-property-with-raw-values (testing "Setting :default with same property value reuses existing entity" - (let [conn (d/create-conn db-schema/schema-for-db-based-graph) - _ (d/transact! conn (sqlite-create-graph/build-db-initial-data "{}")) - _ (sqlite-build/create-blocks - conn - [{:page {:block/original-name "page1"} - :blocks [{:block/content "b1" :build/properties {:logseq.property/order-list-type "number"}} - {:block/content "b2"}]}]) + (let [conn (create-conn-with-blocks + [{:page {:block/original-name "page1"} + :blocks [{:block/content "b1" :build/properties {:logseq.property/order-list-type "number"}} + {:block/content "b2"}]}]) property-value (:logseq.property/order-list-type (find-block-by-content conn "b1")) block-uuid (:block/uuid (find-block-by-content conn "b2")) ;; Use same args as outliner.op @@ -50,13 +86,10 @@ (:db/id (:logseq.property/order-list-type (find-block-by-content conn "b2"))))))) (testing "Setting :checkbox with same property value reuses existing entity" - (let [conn (d/create-conn db-schema/schema-for-db-based-graph) - _ (d/transact! conn (sqlite-create-graph/build-db-initial-data "{}")) - _ (sqlite-build/create-blocks - conn - [{:page {:block/original-name "page1"} - :blocks [{:block/content "b1" :build/properties {:checkbox true}} - {:block/content "b2"}]}]) + (let [conn (create-conn-with-blocks + [{:page {:block/original-name "page1"} + :blocks [{:block/content "b1" :build/properties {:checkbox true}} + {:block/content "b2"}]}]) property-value (:user.property/checkbox (find-block-by-content conn "b1")) block-uuid (:block/uuid (find-block-by-content conn "b2")) ;; Use same args as outliner.op diff --git a/src/test/frontend/handler/db_based/property_test.cljs b/src/test/frontend/handler/db_based/property_test.cljs index d61554df8..e3db9dc2b 100644 --- a/src/test/frontend/handler/db_based/property_test.cljs +++ b/src/test/frontend/handler/db_based/property_test.cljs @@ -333,20 +333,6 @@ (is (nil? (db/entity [:block/uuid block-id]))) (is (= 2 (count (:property/closed-values (db/entity k))))))))))))) -;; property-create-new-block -;; get-property-block-created-block -(deftest text-block-test - (testing "Add property and create a block value" - (let [fb (db/entity [:block/uuid fbid]) - k :user.property/property-1 - conn (db/get-db false)] - ;; add property - (outliner-property/upsert-property! conn k {:type :default} {}) - (let [property (db/entity k) - block-id (outliner-property/create-property-text-block! conn (:db/id fb) (:db/id property) "Block content" {}) - {:keys [from-property-id]} (outliner-property/get-property-block-created-block @conn [:block/uuid block-id])] - (is (= from-property-id (:db/id property))))))) - ;; collapse-expand-property! (deftest collapse-expand-property-test (testing "Collapse and expand property"