Browse Source

fix: plugins api e2e tests

Tienson Qin 2 weeks ago
parent
commit
6871463d26

+ 8 - 5
clj-e2e/test/logseq/e2e/plugins_basic_test.clj

@@ -34,10 +34,10 @@
         ;; Convert to lowercase
         (clojure.string/lower-case))))
 
-(let [*idx (atom 0)]
-  (defn- new-property
-    []
-    (str "p" (swap! *idx inc))))
+(defonce ^:private *property-idx (atom 0))
+(defn- new-property
+  []
+  (str "p" (swap! *property-idx inc)))
 
 (defn- ls-api-call!
   [tag & args]
@@ -130,7 +130,10 @@
                                               :cardinality "many"})
       (let [property (ls-api-call! :editor.getProperty p)]
         (is (= "number" (get property "type")))
-        (is (= ":db.cardinality/many" (get property "cardinality"))))))
+        (is (= ":db.cardinality/many" (get property "cardinality"))))
+      (ls-api-call! :editor.upsertProperty p {:type "default"})
+      (let [property (ls-api-call! :editor.getProperty p)]
+        (is (= "default" (get property "type"))))))
   ;; TODO: How to test against eval-js errors on playwright?
   #_(testing ":checkbox property doesn't allow :many cardinality"
       (let [p (new-property)]

+ 10 - 9
deps/outliner/src/logseq/outliner/page.cljs

@@ -26,15 +26,16 @@
         id-ref->page #(db-content/content-id-ref->page % [page-entity])]
     (when (seq refs)
       (let [tx-data (mapcat (fn [{:block/keys [raw-title] :as ref}]
-                                ;; block content
-                              (let [content' (id-ref->page raw-title)
-                                    content-tx (when (not= raw-title content')
-                                                 {:db/id (:db/id ref)
-                                                  :block/title content'})
-                                    tx content-tx]
-                                (concat
-                                 [[:db/retract (:db/id ref) :block/refs (:db/id page-entity)]]
-                                 (when tx [tx])))) refs)]
+                              ;; block content
+                              (when raw-title
+                                (let [content' (id-ref->page raw-title)
+                                      content-tx (when (not= raw-title content')
+                                                   {:db/id (:db/id ref)
+                                                    :block/title content'})
+                                      tx content-tx]
+                                  (concat
+                                   [[:db/retract (:db/id ref) :block/refs (:db/id page-entity)]]
+                                   (when tx [tx]))))) refs)]
         tx-data))))
 
 (defn delete!

+ 1 - 1
src/main/logseq/api/db_based.cljs

@@ -133,7 +133,7 @@
                                 (update-keys #(if (contains? #{:hide :public} %)
                                                 (keyword (str (name %) "?")) %))) {})
              _ (when (:type schema)
-                 (schema-type-check! (:type schema)))
+                 (schema-type-check! (keyword (:type schema))))
              schema (cond-> schema
                       (string? (:cardinality schema))
                       (-> (assoc :db/cardinality (->cardinality (:cardinality schema)))