mirror of
https://github.com/logseq/logseq.git
synced 2026-02-01 22:47:36 +00:00
chore: use test helpers across db tests
instead of copied and pasted versions
This commit is contained in:
@@ -173,6 +173,7 @@
|
||||
logseq.db.frontend.validate db-validate
|
||||
logseq.db.sqlite.cli sqlite-cli
|
||||
logseq.db.sqlite.util sqlite-util
|
||||
logseq.db.test.helper db-test
|
||||
logseq.graph-parser graph-parser
|
||||
logseq.graph-parser.text text
|
||||
logseq.graph-parser.db gp-db
|
||||
|
||||
1
deps/db/.carve/config.edn
vendored
1
deps/db/.carve/config.edn
vendored
@@ -12,5 +12,6 @@
|
||||
;; Some fns are used by frontend but not worth moving over yet
|
||||
logseq.db.frontend.schema
|
||||
logseq.db.frontend.validate
|
||||
logseq.db.test.helper
|
||||
logseq.db]
|
||||
:report {:format :ignore}}
|
||||
|
||||
49
deps/db/test/logseq/db/frontend/inputs_test.cljs
vendored
49
deps/db/test/logseq/db/frontend/inputs_test.cljs
vendored
@@ -7,7 +7,7 @@
|
||||
[logseq.db.frontend.schema :as db-schema]
|
||||
[logseq.db.frontend.inputs :as db-inputs]
|
||||
[logseq.db.sqlite.build :as sqlite-build]
|
||||
[logseq.db.sqlite.create-graph :as sqlite-create-graph]))
|
||||
[logseq.db.test.helper :as db-test]))
|
||||
|
||||
(defn- custom-query [db {:keys [inputs query input-options]}]
|
||||
(let [q-args (cond-> (mapv #(db-inputs/resolve-input db % input-options) inputs)
|
||||
@@ -97,14 +97,11 @@
|
||||
":parent-block input resolves to parent of current blocks's :db/id")))
|
||||
|
||||
(deftest resolve-input-for-journal-date-inputs
|
||||
(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
|
||||
[{:page {:build/journal 20230101}
|
||||
:blocks [{:block/title "b1"}]}
|
||||
{:page {:build/journal 20230107}
|
||||
:blocks [{:block/title "b2"}]}])]
|
||||
(let [conn (db-test/create-conn-with-blocks
|
||||
[{:page {:build/journal 20230101}
|
||||
:blocks [{:block/title "b1"}]}
|
||||
{:page {:build/journal 20230107}
|
||||
:blocks [{:block/title "b2"}]}])]
|
||||
(is (= ["b2"]
|
||||
(with-redefs [t/today (constantly (t/date-time 2023 1 7))]
|
||||
(map :block/title
|
||||
@@ -148,13 +145,10 @@
|
||||
|
||||
(deftest resolve-input-for-query-page
|
||||
(let [current-date (t/date-time 2023 1 1)
|
||||
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
|
||||
[{:page {:build/journal 20221231} :blocks [{:block/title "-1d"}]}
|
||||
{:page {:build/journal 20230101} :blocks [{:block/title "now"}]}
|
||||
{:page {:build/journal 20230102} :blocks [{:block/title "+1d"}]}])
|
||||
conn (db-test/create-conn-with-blocks
|
||||
[{:page {:build/journal 20221231} :blocks [{:block/title "-1d"}]}
|
||||
{:page {:build/journal 20230101} :blocks [{:block/title "now"}]}
|
||||
{:page {:build/journal 20230102} :blocks [{:block/title "+1d"}]}])
|
||||
db @conn]
|
||||
(is (= ["now"] (blocks-on-journal-page-from-block-with-content db :current-page "now" current-date))
|
||||
":current-page resolves to the stateful page when called from a block on the stateful page")
|
||||
@@ -179,19 +173,16 @@
|
||||
:where (between ?b ?start ?end)]}))))
|
||||
|
||||
(deftest resolve-input-for-relative-date-queries
|
||||
(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
|
||||
[{:page {:build/journal 20220101} :blocks [{:block/title "-1y"}]}
|
||||
{:page {:build/journal 20221201} :blocks [{:block/title "-1m"}]}
|
||||
{:page {:build/journal 20221225} :blocks [{:block/title "-1w"}]}
|
||||
{:page {:build/journal 20221231} :blocks [{:block/title "-1d"}]}
|
||||
{:page {:build/journal 20230101} :blocks [{:block/title "now"}]}
|
||||
{:page {:build/journal 20230102} :blocks [{:block/title "+1d"}]}
|
||||
{:page {:build/journal 20230108} :blocks [{:block/title "+1w"}]}
|
||||
{:page {:build/journal 20230201} :blocks [{:block/title "+1m"}]}
|
||||
{:page {:build/journal 20240101} :blocks [{:block/title "+1y"}]}])
|
||||
(let [conn (db-test/create-conn-with-blocks
|
||||
[{:page {:build/journal 20220101} :blocks [{:block/title "-1y"}]}
|
||||
{:page {:build/journal 20221201} :blocks [{:block/title "-1m"}]}
|
||||
{:page {:build/journal 20221225} :blocks [{:block/title "-1w"}]}
|
||||
{:page {:build/journal 20221231} :blocks [{:block/title "-1d"}]}
|
||||
{:page {:build/journal 20230101} :blocks [{:block/title "now"}]}
|
||||
{:page {:build/journal 20230102} :blocks [{:block/title "+1d"}]}
|
||||
{:page {:build/journal 20230108} :blocks [{:block/title "+1w"}]}
|
||||
{:page {:build/journal 20230201} :blocks [{:block/title "+1m"}]}
|
||||
{:page {:build/journal 20240101} :blocks [{:block/title "+1y"}]}])
|
||||
db @conn]
|
||||
(with-redefs [t/today (constantly (t/date-time 2023 1 1))]
|
||||
(is (= ["now" "-1d" "-1w" "-1m" "-1y"] (blocks-journaled-between-inputs db :-365d :today))
|
||||
|
||||
45
deps/db/test/logseq/db/frontend/rules_test.cljs
vendored
45
deps/db/test/logseq/db/frontend/rules_test.cljs
vendored
@@ -1,15 +1,8 @@
|
||||
(ns logseq.db.frontend.rules-test
|
||||
(:require [cljs.test :refer [deftest is testing]]
|
||||
[datascript.core :as d]
|
||||
[logseq.db.frontend.schema :as db-schema]
|
||||
[logseq.db.frontend.rules :as rules]
|
||||
[logseq.db.sqlite.create-graph :as sqlite-create-graph]
|
||||
[logseq.db.sqlite.build :as sqlite-build]))
|
||||
|
||||
(defn- new-db-conn []
|
||||
(let [conn (d/create-conn db-schema/schema-for-db-based-graph)
|
||||
_ (d/transact! conn (sqlite-create-graph/build-db-initial-data "{}"))]
|
||||
conn))
|
||||
[logseq.db.test.helper :as db-test]))
|
||||
|
||||
(defn q-with-rules [query db]
|
||||
;; query assumes no :in given
|
||||
@@ -18,14 +11,12 @@
|
||||
(rules/extract-rules rules/db-query-dsl-rules)))
|
||||
|
||||
(deftest has-page-property-rule
|
||||
(let [conn (new-db-conn)
|
||||
_ (sqlite-build/create-blocks
|
||||
conn
|
||||
{:properties {:foo {:block/schema {:type :default}}
|
||||
:foo2 {:block/schema {:type :default}}}
|
||||
:pages-and-blocks
|
||||
[{:page {:block/title "Page"
|
||||
:build/properties {:foo "bar"}}}]})]
|
||||
(let [conn (db-test/create-conn-with-blocks
|
||||
{:properties {:foo {:block/schema {:type :default}}
|
||||
:foo2 {:block/schema {:type :default}}}
|
||||
:pages-and-blocks
|
||||
[{:page {:block/title "Page"
|
||||
:build/properties {:foo "bar"}}}]})]
|
||||
|
||||
(is (= ["Page"]
|
||||
(->> (q-with-rules '[:find (pull ?b [:block/title]) :where (has-page-property ?b :user.property/foo)]
|
||||
@@ -44,18 +35,16 @@
|
||||
"has-page-property can bind to property arg")))
|
||||
|
||||
(deftest page-property-rule
|
||||
(let [conn (new-db-conn)
|
||||
_ (sqlite-build/create-blocks
|
||||
conn
|
||||
{:properties {:foo {:block/schema {:type :default}}
|
||||
:foo2 {:block/schema {:type :default}}
|
||||
:number-many {:block/schema {:type :number :cardinality :many}}
|
||||
:page-many {:block/schema {:type :node :cardinality :many}}}
|
||||
:pages-and-blocks
|
||||
[{:page {:block/title "Page"
|
||||
:build/properties {:foo "bar" :number-many #{5 10} :page-many #{[:page "Page A"]}}}}
|
||||
{:page {:block/title "Page A"
|
||||
:build/properties {:foo "bar A"}}}]})]
|
||||
(let [conn (db-test/create-conn-with-blocks
|
||||
{:properties {:foo {:block/schema {:type :default}}
|
||||
:foo2 {:block/schema {:type :default}}
|
||||
:number-many {:block/schema {:type :number :cardinality :many}}
|
||||
:page-many {:block/schema {:type :node :cardinality :many}}}
|
||||
:pages-and-blocks
|
||||
[{:page {:block/title "Page"
|
||||
:build/properties {:foo "bar" :number-many #{5 10} :page-many #{[:page "Page A"]}}}}
|
||||
{:page {:block/title "Page A"
|
||||
:build/properties {:foo "bar A"}}}]})]
|
||||
(testing "cardinality :one property"
|
||||
(is (= ["Page"]
|
||||
(->> (q-with-rules '[:find (pull ?b [:block/title]) :where (page-property ?b :user.property/foo "bar")]
|
||||
|
||||
14
deps/db/test/logseq/db/sqlite/build_test.cljs
vendored
14
deps/db/test/logseq/db/sqlite/build_test.cljs
vendored
@@ -1,14 +1,12 @@
|
||||
(ns logseq.db.sqlite.build-test
|
||||
(:require [cljs.test :refer [deftest is]]
|
||||
[datascript.core :as d]
|
||||
[logseq.db.frontend.schema :as db-schema]
|
||||
[logseq.db.sqlite.create-graph :as sqlite-create-graph]
|
||||
[logseq.db.sqlite.build :as sqlite-build]
|
||||
[logseq.db.frontend.property :as db-property]))
|
||||
[logseq.db.frontend.property :as db-property]
|
||||
[logseq.db.test.helper :as db-test]))
|
||||
|
||||
(deftest build-tags
|
||||
(let [conn (d/create-conn db-schema/schema-for-db-based-graph)
|
||||
_ (d/transact! conn (sqlite-create-graph/build-db-initial-data "{}"))
|
||||
(let [conn (db-test/create-conn)
|
||||
_ (sqlite-build/create-blocks
|
||||
conn
|
||||
[{:page {:block/title "page1"}
|
||||
@@ -27,8 +25,7 @@
|
||||
"Person class is created and correctly associated to a page")))
|
||||
|
||||
(deftest build-properties-user
|
||||
(let [conn (d/create-conn db-schema/schema-for-db-based-graph)
|
||||
_ (d/transact! conn (sqlite-create-graph/build-db-initial-data "{}"))
|
||||
(let [conn (db-test/create-conn)
|
||||
_ (sqlite-build/create-blocks
|
||||
conn
|
||||
[{:page {:block/title "page1"}
|
||||
@@ -53,8 +50,7 @@
|
||||
"description property is created and correctly associated to a page")))
|
||||
|
||||
(deftest build-properties-built-in
|
||||
(let [conn (d/create-conn db-schema/schema-for-db-based-graph)
|
||||
_ (d/transact! conn (sqlite-create-graph/build-db-initial-data "{}"))
|
||||
(let [conn (db-test/create-conn)
|
||||
_ (sqlite-build/create-blocks
|
||||
conn
|
||||
[{:page {:block/title "page1"}
|
||||
|
||||
@@ -8,12 +8,12 @@
|
||||
[logseq.db.frontend.validate :as db-validate]
|
||||
[logseq.db.frontend.property :as db-property]
|
||||
[logseq.db.sqlite.build :as sqlite-build]
|
||||
[logseq.db :as ldb]))
|
||||
[logseq.db :as ldb]
|
||||
[logseq.db.test.helper :as db-test]))
|
||||
|
||||
(deftest new-graph-db-idents
|
||||
(testing "a new graph follows :db/ident conventions for"
|
||||
(let [conn (d/create-conn db-schema/schema-for-db-based-graph)
|
||||
_ (d/transact! conn (sqlite-create-graph/build-db-initial-data "{}"))
|
||||
(let [conn (db-test/create-conn)
|
||||
ident-ents (->> (d/q '[:find (pull ?b [:db/ident :block/type])
|
||||
:where [?b :db/ident]]
|
||||
@conn)
|
||||
@@ -45,8 +45,7 @@
|
||||
"All closed values start with a prefix that is a property name"))))))
|
||||
|
||||
(deftest new-graph-marks-built-ins
|
||||
(let [conn (d/create-conn db-schema/schema-for-db-based-graph)
|
||||
_ (d/transact! conn (sqlite-create-graph/build-db-initial-data "{}"))
|
||||
(let [conn (db-test/create-conn)
|
||||
idents (->> (d/q '[:find [(pull ?b [:db/ident :logseq.property/built-in?]) ...]
|
||||
:where [?b :db/ident]]
|
||||
@conn)
|
||||
@@ -58,8 +57,7 @@
|
||||
"All entities with :db/ident have built-in property (except for kv idents)")))
|
||||
|
||||
(deftest new-graph-creates-class
|
||||
(let [conn (d/create-conn db-schema/schema-for-db-based-graph)
|
||||
_ (d/transact! conn (sqlite-create-graph/build-db-initial-data "{}"))
|
||||
(let [conn (db-test/create-conn)
|
||||
task (d/entity @conn :logseq.class/Task)]
|
||||
(is (ldb/class? task)
|
||||
"Task class has correct type")
|
||||
@@ -69,8 +67,7 @@
|
||||
"Each task property has correct type")))
|
||||
|
||||
(deftest new-graph-is-valid
|
||||
(let [conn (d/create-conn db-schema/schema-for-db-based-graph)
|
||||
_ (d/transact! conn (sqlite-create-graph/build-db-initial-data "{}"))
|
||||
(let [conn (db-test/create-conn)
|
||||
validation (db-validate/validate-db! @conn)]
|
||||
;; For debugging
|
||||
;; (println (count (:errors validation)) "errors of" (count (:entities validation)))
|
||||
|
||||
4
deps/db/test/logseq/db_test.cljs
vendored
4
deps/db/test/logseq/db_test.cljs
vendored
@@ -3,7 +3,6 @@
|
||||
[logseq.db.frontend.schema :as db-schema]
|
||||
[datascript.core :as d]
|
||||
[logseq.db :as ldb]
|
||||
[logseq.db.sqlite.create-graph :as sqlite-create-graph]
|
||||
[logseq.db.test.helper :as db-test]))
|
||||
|
||||
|
||||
@@ -47,8 +46,7 @@
|
||||
:logseq.property/parent [:block/uuid #uuid "7008db08-ba0c-4aa9-afc6-7e4783e40a99"]}])
|
||||
|
||||
(deftest get-page-parents
|
||||
(let [conn (d/create-conn db-schema/schema-for-db-based-graph)]
|
||||
(d/transact! conn (sqlite-create-graph/build-db-initial-data "{}"))
|
||||
(let [conn (db-test/create-conn)]
|
||||
(d/transact! conn class-parents-data)
|
||||
(is (= #{"x" "y"}
|
||||
(->> (ldb/get-page-parents (ldb/get-page @conn "z") {:node-class? true})
|
||||
|
||||
@@ -9,16 +9,15 @@
|
||||
["fs" :as fs]
|
||||
[logseq.common.graph :as common-graph]
|
||||
[promesa.core :as p]
|
||||
[logseq.db.frontend.schema :as db-schema]
|
||||
[logseq.db.frontend.validate :as db-validate]
|
||||
[logseq.db.sqlite.create-graph :as sqlite-create-graph]
|
||||
[logseq.graph-parser.exporter :as gp-exporter]
|
||||
[logseq.db.frontend.malli-schema :as db-malli-schema]
|
||||
[logseq.db.frontend.property :as db-property]
|
||||
[logseq.db.frontend.property.type :as db-property-type]
|
||||
[logseq.common.config :as common-config]
|
||||
[logseq.db :as ldb]
|
||||
[logseq.outliner.db-pipeline :as db-pipeline]))
|
||||
[logseq.outliner.db-pipeline :as db-pipeline]
|
||||
[logseq.db.test.helper :as db-test]))
|
||||
|
||||
;; Helpers
|
||||
;; =======
|
||||
@@ -140,8 +139,7 @@
|
||||
(deftest-async ^:integration export-docs-graph
|
||||
(p/let [file-graph-dir "test/resources/docs-0.10.9"
|
||||
_ (docs-graph-helper/clone-docs-repo-if-not-exists file-graph-dir "v0.10.9")
|
||||
conn (d/create-conn db-schema/schema-for-db-based-graph)
|
||||
_ (d/transact! conn (sqlite-create-graph/build-db-initial-data "{}"))
|
||||
conn (db-test/create-conn)
|
||||
assets (atom [])
|
||||
{:keys [import-state]}
|
||||
(import-file-graph-to-db file-graph-dir conn {:assets assets})]
|
||||
@@ -153,8 +151,7 @@
|
||||
(deftest-async export-basic-graph
|
||||
;; This graph will contain basic examples of different features to import
|
||||
(p/let [file-graph-dir "test/resources/exporter-test-graph"
|
||||
conn (d/create-conn db-schema/schema-for-db-based-graph)
|
||||
_ (d/transact! conn (sqlite-create-graph/build-db-initial-data "{}"))
|
||||
conn (db-test/create-conn)
|
||||
;; Simulate frontend path-refs being calculated
|
||||
_ (db-pipeline/add-listener conn)
|
||||
assets (atom [])
|
||||
@@ -410,8 +407,7 @@
|
||||
(deftest-async export-files-with-tag-classes-option
|
||||
(p/let [file-graph-dir "test/resources/exporter-test-graph"
|
||||
files (mapv #(node-path/join file-graph-dir %) ["journals/2024_02_07.md" "pages/Interstellar.md"])
|
||||
conn (d/create-conn db-schema/schema-for-db-based-graph)
|
||||
_ (d/transact! conn (sqlite-create-graph/build-db-initial-data "{}"))
|
||||
conn (db-test/create-conn)
|
||||
_ (import-files-to-db files conn {:tag-classes ["movie"]})]
|
||||
|
||||
(is (empty? (map :entity (:errors (db-validate/validate-db! @conn))))
|
||||
@@ -438,8 +434,7 @@
|
||||
(deftest-async export-files-with-property-classes-option
|
||||
(p/let [file-graph-dir "test/resources/exporter-test-graph"
|
||||
files (mapv #(node-path/join file-graph-dir %) ["journals/2024_02_23.md" "pages/url.md"])
|
||||
conn (d/create-conn db-schema/schema-for-db-based-graph)
|
||||
_ (d/transact! conn (sqlite-create-graph/build-db-initial-data "{}"))
|
||||
conn (db-test/create-conn)
|
||||
_ (import-files-to-db files conn {:property-classes ["type"]})
|
||||
_ (@#'gp-exporter/export-class-properties conn conn)]
|
||||
|
||||
@@ -483,8 +478,7 @@
|
||||
(deftest-async export-files-with-ignored-properties
|
||||
(p/let [file-graph-dir "test/resources/exporter-test-graph"
|
||||
files (mapv #(node-path/join file-graph-dir %) ["ignored/icon-page.md"])
|
||||
conn (d/create-conn db-schema/schema-for-db-based-graph)
|
||||
_ (d/transact! conn (sqlite-create-graph/build-db-initial-data "{}"))
|
||||
conn (db-test/create-conn)
|
||||
{:keys [import-state]} (import-files-to-db files conn {})]
|
||||
(is (= 2
|
||||
(count (filter #(= :icon (:property %)) @(:ignored-properties import-state))))
|
||||
@@ -493,8 +487,7 @@
|
||||
(deftest-async export-files-with-property-parent-classes-option
|
||||
(p/let [file-graph-dir "test/resources/exporter-test-graph"
|
||||
files (mapv #(node-path/join file-graph-dir %) ["pages/CreativeWork.md" "pages/Movie.md" "pages/type.md"])
|
||||
conn (d/create-conn db-schema/schema-for-db-based-graph)
|
||||
_ (d/transact! conn (sqlite-create-graph/build-db-initial-data "{}"))
|
||||
conn (db-test/create-conn)
|
||||
_ (import-files-to-db files conn {:property-parent-classes ["parent"]})]
|
||||
|
||||
(is (empty? (map :entity (:errors (db-validate/validate-db! @conn))))
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
(ns logseq.outliner.property-test
|
||||
(:require [cljs.test :refer [deftest is testing are]]
|
||||
[logseq.db.frontend.schema :as db-schema]
|
||||
[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.db.frontend.property :as db-property]))
|
||||
[logseq.db.frontend.property :as db-property]
|
||||
[logseq.db.test.helper :as db-test]))
|
||||
|
||||
(defn- find-block-by-content [conn content]
|
||||
(->> content
|
||||
@@ -15,27 +13,21 @@
|
||||
@conn)
|
||||
first))
|
||||
|
||||
(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 opts)]
|
||||
conn))
|
||||
|
||||
(deftest upsert-property!
|
||||
(testing "Creates a property"
|
||||
(let [conn (create-conn-with-blocks [])
|
||||
(let [conn (db-test/create-conn-with-blocks [])
|
||||
_ (outliner-property/upsert-property! conn nil {:type :number} {:property-name "num"})]
|
||||
(is (= {:type :number}
|
||||
(:block/schema (d/entity @conn :user.property/num)))
|
||||
"Creates property with property-name")))
|
||||
|
||||
(testing "Updates a property"
|
||||
(let [conn (create-conn-with-blocks {:properties {:num {:block/schema {:type :number}}}})
|
||||
(let [conn (db-test/create-conn-with-blocks {:properties {:num {:block/schema {:type :number}}}})
|
||||
_ (outliner-property/upsert-property! conn :user.property/num {:type :default :cardinality :many} {})]
|
||||
(is (db-property/many? (d/entity @conn :user.property/num)))))
|
||||
|
||||
(testing "Multiple properties that generate the same initial :db/ident"
|
||||
(let [conn (create-conn-with-blocks [])]
|
||||
(let [conn (db-test/create-conn-with-blocks [])]
|
||||
(outliner-property/upsert-property! conn nil {:type :default} {:property-name "p1"})
|
||||
(outliner-property/upsert-property! conn nil {} {:property-name "p1"})
|
||||
(outliner-property/upsert-property! conn nil {} {:property-name "p1"})
|
||||
@@ -65,7 +57,7 @@
|
||||
|
||||
(deftest create-property-text-block!
|
||||
(testing "Create a new :default property value"
|
||||
(let [conn (create-conn-with-blocks
|
||||
(let [conn (db-test/create-conn-with-blocks
|
||||
[{:page {:block/title "page1"}
|
||||
:blocks [{:block/title "b1" :build/properties {:default "foo"}}
|
||||
{:block/title "b2"}]}])
|
||||
@@ -82,7 +74,7 @@
|
||||
"Has correct created-from-property")))
|
||||
|
||||
(testing "Create cases for a new :one :number property value"
|
||||
(let [conn (create-conn-with-blocks
|
||||
(let [conn (db-test/create-conn-with-blocks
|
||||
[{:page {:block/title "page1"}
|
||||
:blocks [{:block/title "b1" :build/properties {:num 2}}
|
||||
{:block/title "b2"}]}])
|
||||
@@ -105,7 +97,7 @@
|
||||
"Wrong value isn't transacted")))
|
||||
|
||||
(testing "Create new :many :number property values"
|
||||
(let [conn (create-conn-with-blocks
|
||||
(let [conn (db-test/create-conn-with-blocks
|
||||
[{:page {:block/title "page1"}
|
||||
:blocks [{:block/title "b1" :build/properties {:num-many #{2}}}
|
||||
{:block/title "b2"}]}])
|
||||
@@ -122,7 +114,7 @@
|
||||
|
||||
(deftest set-block-property-basic-cases
|
||||
(testing "Set a :number value with existing value"
|
||||
(let [conn (create-conn-with-blocks
|
||||
(let [conn (db-test/create-conn-with-blocks
|
||||
[{:page {:block/title "page1"}
|
||||
:blocks [{:block/title "b1" :build/properties {:num 2}}
|
||||
{:block/title "b2"}]}])
|
||||
@@ -135,7 +127,7 @@
|
||||
(:db/id (:user.property/num (find-block-by-content conn "b2")))))))
|
||||
|
||||
(testing "Update a :number value with existing value"
|
||||
(let [conn (create-conn-with-blocks
|
||||
(let [conn (db-test/create-conn-with-blocks
|
||||
[{:page {:block/title "page1"}
|
||||
:blocks [{:block/title "b1" :build/properties {:num 2}}
|
||||
{:block/title "b2" :build/properties {:num 3}}]}])
|
||||
@@ -149,7 +141,7 @@
|
||||
|
||||
(deftest set-block-property-with-non-ref-values
|
||||
(testing "Setting :default with same property value reuses existing entity"
|
||||
(let [conn (create-conn-with-blocks
|
||||
(let [conn (db-test/create-conn-with-blocks
|
||||
[{:page {:block/title "page1"}
|
||||
:blocks [{:block/title "b1" :build/properties {:logseq.property/order-list-type "number"}}
|
||||
{:block/title "b2"}]}])
|
||||
@@ -163,7 +155,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 (create-conn-with-blocks
|
||||
(let [conn (db-test/create-conn-with-blocks
|
||||
[{:page {:block/title "page1"}
|
||||
:blocks [{:block/title "b1" :build/properties {:checkbox true}}
|
||||
{:block/title "b2"}]}])
|
||||
@@ -176,7 +168,7 @@
|
||||
(is (= property-value (:user.property/checkbox (find-block-by-content conn "b2")))))))
|
||||
|
||||
(deftest remove-block-property!
|
||||
(let [conn (create-conn-with-blocks
|
||||
(let [conn (db-test/create-conn-with-blocks
|
||||
[{:page {:block/title "page1"}
|
||||
:blocks [{:block/title "b1" :build/properties {:default "foo"}}]}])
|
||||
block (find-block-by-content conn "b1")
|
||||
@@ -188,7 +180,7 @@
|
||||
(is (nil? (:user.property/default updated-block)) "Block property is deleted")))
|
||||
|
||||
(deftest batch-set-property!
|
||||
(let [conn (create-conn-with-blocks
|
||||
(let [conn (db-test/create-conn-with-blocks
|
||||
[{:page {:block/title "page1"}
|
||||
:blocks [{:block/title "item 1"}
|
||||
{:block/title "item 2"}]}])
|
||||
@@ -201,7 +193,7 @@
|
||||
"Property values are batch set")))
|
||||
|
||||
(deftest batch-remove-property!
|
||||
(let [conn (create-conn-with-blocks
|
||||
(let [conn (db-test/create-conn-with-blocks
|
||||
[{:page {:block/title "page1"}
|
||||
:blocks [{:block/title "item 1" :build/properties {:logseq.property/order-list-type "number"}}
|
||||
{:block/title "item 2" :build/properties {:logseq.property/order-list-type "number"}}]}])
|
||||
@@ -213,7 +205,7 @@
|
||||
"Property values are batch removed")))
|
||||
|
||||
(deftest add-existing-values-to-closed-values!
|
||||
(let [conn (create-conn-with-blocks
|
||||
(let [conn (db-test/create-conn-with-blocks
|
||||
[{:page {:block/title "page1"}
|
||||
:blocks [{:block/title "b1" :build/properties {:num 1}}
|
||||
{:block/title "b2" :build/properties {:num 2}}]}])
|
||||
@@ -223,7 +215,7 @@
|
||||
(map db-property/closed-value-content (:block/_closed-value-property (d/entity @conn :user.property/num)))))))
|
||||
|
||||
(deftest upsert-closed-value!
|
||||
(let [conn (create-conn-with-blocks
|
||||
(let [conn (db-test/create-conn-with-blocks
|
||||
{:properties {:num {:build/closed-values [{:uuid (random-uuid) :value 2}]
|
||||
:block/schema {:type :number}}}})]
|
||||
|
||||
@@ -260,7 +252,7 @@
|
||||
(deftest delete-closed-value!
|
||||
(let [closed-value-uuid (random-uuid)
|
||||
used-closed-value-uuid (random-uuid)
|
||||
conn (create-conn-with-blocks
|
||||
conn (db-test/create-conn-with-blocks
|
||||
{:properties {:default {:build/closed-values [{:uuid closed-value-uuid :value "foo"}
|
||||
{:uuid used-closed-value-uuid :value "bar"}]
|
||||
:block/schema {:type :default}}}
|
||||
@@ -273,7 +265,7 @@
|
||||
(is (nil? (d/entity @conn [:block/uuid closed-value-uuid])))))
|
||||
|
||||
(deftest class-add-property!
|
||||
(let [conn (create-conn-with-blocks
|
||||
(let [conn (db-test/create-conn-with-blocks
|
||||
{:classes {:c1 {}}
|
||||
:properties {:p1 {:block/schema {:type :default}}
|
||||
:p2 {:block/schema {:type :default}}}})
|
||||
@@ -283,14 +275,14 @@
|
||||
(map :db/ident (:logseq.property.class/properties (d/entity @conn :user.class/c1)))))))
|
||||
|
||||
(deftest class-remove-property!
|
||||
(let [conn (create-conn-with-blocks
|
||||
(let [conn (db-test/create-conn-with-blocks
|
||||
{:classes {:c1 {:build/schema-properties [:p1 :p2]}}})
|
||||
_ (outliner-property/class-remove-property! conn :user.class/c1 :user.property/p1)]
|
||||
(is (= [:user.property/p2]
|
||||
(map :db/ident (:logseq.property.class/properties (d/entity @conn :user.class/c1)))))))
|
||||
|
||||
(deftest get-block-classes-properties
|
||||
(let [conn (create-conn-with-blocks
|
||||
(let [conn (db-test/create-conn-with-blocks
|
||||
{:classes {:c1 {:build/schema-properties [:p1]}
|
||||
:c2 {:build/schema-properties [:p2 :p3]}}
|
||||
:pages-and-blocks
|
||||
|
||||
@@ -1,16 +1,8 @@
|
||||
(ns logseq.outliner.validate-test
|
||||
(:require [cljs.test :refer [deftest is]]
|
||||
[logseq.db.frontend.schema :as db-schema]
|
||||
[datascript.core :as d]
|
||||
[logseq.db.sqlite.create-graph :as sqlite-create-graph]
|
||||
[logseq.db.sqlite.build :as sqlite-build]
|
||||
[logseq.outliner.validate :as outliner-validate]))
|
||||
|
||||
(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 opts)]
|
||||
conn))
|
||||
[logseq.outliner.validate :as outliner-validate]
|
||||
[logseq.db.test.helper :as db-test]))
|
||||
|
||||
(defn- find-block-by-content [conn content]
|
||||
(->> content
|
||||
@@ -21,7 +13,7 @@
|
||||
first))
|
||||
|
||||
(deftest validate-block-title-unique-for-properties
|
||||
(let [conn (create-conn-with-blocks
|
||||
(let [conn (db-test/create-conn-with-blocks
|
||||
;; use a property name that's same as built-in
|
||||
{:properties {:background-image {:block/schema {:type :default}}}})]
|
||||
|
||||
@@ -42,7 +34,7 @@
|
||||
"Disallow duplicate user property")))
|
||||
|
||||
(deftest validate-block-title-unique-for-pages
|
||||
(let [conn (create-conn-with-blocks
|
||||
(let [conn (db-test/create-conn-with-blocks
|
||||
[{:page {:block/title "page1"}}
|
||||
{:page {:block/title "Apple" :build/tags [:Company]}}
|
||||
{:page {:block/title "Banana" :build/tags [:Fruit]}}])]
|
||||
@@ -79,7 +71,7 @@
|
||||
"Allow class to have same name as a page")))
|
||||
|
||||
(deftest new-graph-should-be-valid
|
||||
(let [conn (create-conn-with-blocks {})
|
||||
(let [conn (db-test/create-conn)
|
||||
pages (d/q '[:find [(pull ?b [*]) ...] :where [?b :block/title] [?b :block/type]] @conn)
|
||||
validation-errors (atom {})]
|
||||
(doseq [page pages]
|
||||
|
||||
Reference in New Issue
Block a user