Jelajahi Sumber

enhance(plugins): WIP add property related e2e tests

charlie 7 bulan lalu
induk
melakukan
9291e877c8
2 mengubah file dengan 32 tambahan dan 10 penghapusan
  1. 25 4
      clj-e2e/test/logseq/e2e/plugins_basic_test.clj
  2. 7 6
      src/main/logseq/api.cljs

+ 25 - 4
clj-e2e/test/logseq/e2e/plugins_basic_test.clj

@@ -82,10 +82,31 @@
       (is (= 1 (get props1 ":plugin.property._api/p1")))
       (ls-api-call! :editor.upsertBlockProperty uuid' "p2" "p2")
       (ls-api-call! :editor.upsertBlockProperty uuid' "p3" true)
+      (ls-api-call! :editor.upsertBlockProperty uuid' "p4" {:a 1, :b [2, 3]})
       (let [prop2 (ls-api-call! :editor.getBlockProperty uuid' "p2")
-            prop3 (ls-api-call! :editor.getBlockProperty uuid' "p3")]
+            prop3 (ls-api-call! :editor.getBlockProperty uuid' "p3")
+            prop4 (ls-api-call! :editor.getBlockProperty uuid' "p4")]
         (w/wait-for ".property-k:text('p2')")
         (is (= "p2" (get prop2 "value")))
-        (is (true? prop3)))
-      (prn uuid'))
-    ))
+        (is (true? prop3))
+        (is (= prop4 {"a" 1, "b" [2 3]})))
+      (ls-api-call! :editor.removeBlockProperty uuid' "p4")
+      (is (nil? (w/find-one-by-text ".property-k" "p4")))
+      (ls-api-call! :editor.upsertBlockProperty uuid' "p3" false)
+      (ls-api-call! :editor.upsertBlockProperty uuid' "p2" "p2-updated")
+      (w/wait-for ".block-title-wrap:text('p2-updated')")
+      (let [props (ls-api-call! :editor.getBlockProperties uuid')]
+        (is (= (get props ":plugin.property._api/p3") false))
+        (is (= (get props ":plugin.property._api/p2") "p2-updated")))))
+
+  (testing "properties management related apis"
+    (let [_ (ls-api-call! :editor.upsertProperty "o1")
+          _ (ls-api-call! :editor.upsertProperty "o2" {:type "number"})
+          ;_ (ls-api-call! :editor.upsertProperty "user.property/o3" {:type "node"})
+          prop1 (ls-api-call! :editor.getProperty "o1")
+          prop2 (ls-api-call! :editor.getProperty "o2")
+          prop3 (ls-api-call! :editor.getProperty "user.property/o3")]
+      (is (= (get prop1 "ident") ":plugin.property._api/o1"))
+      (is (= (get prop1 "type") "default"))
+      (is (= (get prop2 "type") "number"))
+      (is (nil? prop3)))))

+ 7 - 6
src/main/logseq/api.cljs

@@ -893,11 +893,11 @@
 (defn ^:export get_property
   [k]
   (this-as this
-           (p/let [prop (-get-property this k)]
-             (-> prop
-                 (assoc :type (:logseq.property/type prop))
-                 (sdk-utils/normalize-keyword-for-json)
-                 (bean/->js)))))
+    (p/let [prop (-get-property this k)]
+      (some-> prop
+        (assoc :type (:logseq.property/type prop))
+        (sdk-utils/normalize-keyword-for-json)
+        (bean/->js)))))
 
 (defn ^:export upsert_property
   "schema:
@@ -992,7 +992,8 @@
                 property-value (cond-> property-value
                                  (map? property-value)
                                  (assoc
-                                   :value (:logseq.property/value property-value)
+                                   :value (or (:logseq.property/value property-value)
+                                            (:block/title property-value))
                                    :ident ident))
                 parsed-value (api-block/parse-property-json-value-if-need ident property-value)]
             (or parsed-value