|
@@ -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)))
|