浏览代码

enhance(dev): add tests for unique namespaced pages

also add more new graph validations
Gabriel Horner 3 月之前
父节点
当前提交
4b5305ed70

+ 2 - 2
deps/outliner/src/logseq/outliner/validate.cljs

@@ -183,12 +183,12 @@
                                    :blocks (map #(select-keys % [:db/id :block/title]) [child])}}))))))
 
 (defn validate-extends-property
-  [db parent-ent* child-ents]
+  [db parent-ent* child-ents & {:keys [built-in?] :or {built-in? true}}]
   (let [parent-ent (if (integer? parent-ent*)
                      (d/entity db parent-ent*)
                      parent-ent*)]
     (disallow-extends-cycle db parent-ent child-ents)
-    (disallow-built-in-class-extends-change parent-ent child-ents)
+    (when built-in? (disallow-built-in-class-extends-change parent-ent child-ents))
     (validate-extends-property-have-correct-type parent-ent child-ents)))
 
 (defn- disallow-node-cant-tag-with-built-in-non-tags

+ 38 - 0
deps/outliner/test/logseq/outliner/validate_test.cljs

@@ -2,6 +2,7 @@
   (:require [cljs.test :refer [are deftest is testing]]
             [datascript.core :as d]
             [logseq.db.common.entity-plus :as entity-plus]
+            [logseq.db.frontend.entity-util :as entity-util]
             [logseq.db.test.helper :as db-test]
             [logseq.outliner.validate :as outliner-validate]))
 
@@ -48,6 +49,39 @@
           (d/entity @conn :user.class/Class1)))
         "Disallow duplicate class names even if it's built-in")))
 
+(deftest validate-block-title-unique-for-namespaced-pages
+  (let [conn (db-test/create-conn-with-blocks
+              {:pages-and-blocks
+               [{:page {:block/title "Library"
+                        :block/uuid #uuid "d246c71a-3e71-42f0-928f-afe607ee5ce0"
+                        :build/keep-uuid? true
+                        :build/properties {:logseq.property/built-in? true}}}
+                {:page {:block/title "n1"
+                        :block/uuid #uuid "3aa1e950-5a9b-4efc-81d4-b6d89a504591"
+                        :build/keep-uuid? true
+                        :block/parent [:block/uuid #uuid "d246c71a-3e71-42f0-928f-afe607ee5ce0"]}}
+                {:page {:block/title "n2"
+                        :block/parent [:block/uuid #uuid "3aa1e950-5a9b-4efc-81d4-b6d89a504591"]}}
+                {:page {:block/title "n3"
+                        :block/parent [:block/uuid #uuid "3aa1e950-5a9b-4efc-81d4-b6d89a504591"]}}]
+               :build-existing-tx? true})]
+
+    (is (thrown-with-msg?
+         js/Error
+         #"Duplicate page"
+         (outliner-validate/validate-unique-by-name-and-tags
+          @conn
+          "n2"
+          (db-test/find-page-by-title @conn "n3")))
+        "Disallow duplicate namespace child")
+
+    (is (nil?
+         (outliner-validate/validate-unique-by-name-and-tags
+          @conn
+          "n4"
+          (db-test/find-page-by-title @conn "n3")))
+        "Allow namespace child if unique")))
+
 (deftest validate-block-title-unique-for-pages
   (let [conn (db-test/create-conn-with-blocks
               [{:page {:block/title "page1"}}
@@ -178,6 +212,10 @@
             (outliner-validate/validate-unique-by-name-and-tags @conn (:block/title page) page)
             (outliner-validate/validate-page-title (:block/title page) {:node page})
             (outliner-validate/validate-page-title-characters (:block/title page) {:node page})
+            (when (entity-util/property? page) (outliner-validate/validate-property-title (:block/title page)))
+            (when (entity-util/class? page)
+              (doseq [parent (:logseq.property.class/extends page)]
+                (outliner-validate/validate-extends-property @conn parent [page] {:built-in? false})))
 
             (catch :default e
               (if (= :notification (:type (ex-data e)))