mirror of https://github.com/logseq/logseq
chore: move and add create-property-text-block tests
parent
c23513eaa8
commit
eae2156f6c
|
@ -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)]
|
||||
|
|
|
@ -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,12 +15,50 @@
|
|||
@conn)
|
||||
first))
|
||||
|
||||
(deftest set-block-property-with-ref-values
|
||||
(testing "Select a :number value from existing values"
|
||||
(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
|
||||
_ (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 (create-conn-with-blocks
|
||||
[{:page {:block/original-name "page1"}
|
||||
:blocks [{:block/content "b1" :build/properties {:num 2}}
|
||||
{:block/content "b2"}]}])
|
||||
|
@ -33,10 +72,7 @@
|
|||
|
||||
(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
|
||||
(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"}]}])
|
||||
|
@ -50,10 +86,7 @@
|
|||
(: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
|
||||
(let [conn (create-conn-with-blocks
|
||||
[{:page {:block/original-name "page1"}
|
||||
:blocks [{:block/content "b1" :build/properties {:checkbox true}}
|
||||
{:block/content "b2"}]}])
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in New Issue