Split out parse-property for use in dsl-query and tests

- Add tests for all *property dsl queries with and without new
  config option
- Add tests for property persistence
- Add tests for property relationships
This commit is contained in:
Gabriel Horner
2022-08-06 01:35:39 -04:00
parent 405183db09
commit 0719163d30
10 changed files with 234 additions and 51 deletions

View File

@@ -3,7 +3,7 @@
[clojure.string :as str]
[frontend.db :as db]
[frontend.db.query-dsl :as query-dsl]
[frontend.test.helper :as test-helper :refer [load-test-files]]))
[frontend.test.helper :as test-helper :include-macros true :refer [load-test-files]]))
;; TODO: quickcheck
;; 1. generate query filters
@@ -45,22 +45,8 @@
;; Tests
;; =====
(deftest ^:focus block-property-queries
(load-test-files [{:file/path "journals/2022_02_28.md"
:file/content "a:: b
- b1
prop-a:: val-a
prop-num:: 2000
- b2
prop-a:: val-a
prop-b:: val-b
- b3
prop-c:: [[page a]], [[page b]], [[page c]]
prop-linked-num:: [[3000]]
prop-d:: [[no-space-link]]
- b4
prop-d:: nada"}])
(defn- block-property-queries-test
[]
(testing "Blocks have given property value"
(is (= #{"b1" "b2"}
(set (map (comp first str/split-lines :block/content)
@@ -112,16 +98,31 @@ prop-d:: nada"}])
(dsl-query "(property prop-d)")))
"Blocks that have a property"))
(deftest ^:focus page-property-queries
(load-test-files [{:file/path "pages/page1.md"
:file/content "parent:: [[child page 1]], [[child-no-space]]"}
{:file/path "pages/page2.md"
:file/content "foo:: #bar"}
{:file/path "pages/page3.md"
:file/content "parent:: [[child page 1]], [[child page 2]]\nfoo:: bar"}
{:file/path "pages/page4.md"
:file/content "parent:: [[child page 2]]\nfoo:: baz"}])
(deftest block-property-queries
(load-test-files [{:file/path "journals/2022_02_28.md"
:file/content "a:: b
- b1
prop-a:: val-a
prop-num:: 2000
- b2
prop-a:: val-a
prop-b:: val-b
- b3
prop-c:: [[page a]], [[page b]], [[page c]]
prop-linked-num:: [[3000]]
prop-d:: [[no-space-link]]
- b4
prop-d:: nada"}])
(testing "block property tests with default config"
(test-helper/with-config {}
(block-property-queries-test)))
(testing "block property tests with property-values-allow-links-and-text? config"
(test-helper/with-config {:property-values-allow-links-and-text? true}
(block-property-queries-test))))
(defn- page-property-queries-test
[]
(is (= ["page1" "page3" "page4"]
(map :block/name (dsl-query "(page-property parent)")))
"Pages have given property")
@@ -160,7 +161,33 @@ prop-d:: nada"}])
(map
:block/name
(dsl-query "(and (not (page-property foo bar)) (page-property parent [[child page 2]]))")))
"Page property queries nested NOT in first clause"))
"Page property queries nested NOT in first clause")
(testing "boolean values"
(is (= ["page1"]
(map :block/name (dsl-query "(page-property interesting true)")))
"Boolean true")
(is (= ["page2" "page3"]
(map :block/name (dsl-query "(page-property interesting false)")))
"Boolean false")))
(deftest page-property-queries
(load-test-files [{:file/path "pages/page1.md"
:file/content "parent:: [[child page 1]], [[child-no-space]]\ninteresting:: true"}
{:file/path "pages/page2.md"
:file/content "foo:: #bar\ninteresting:: false"}
{:file/path "pages/page3.md"
:file/content "parent:: [[child page 1]], [[child page 2]]\nfoo:: bar\ninteresting:: false"}
{:file/path "pages/page4.md"
:file/content "parent:: [[child page 2]]\nfoo:: baz"}])
(testing "page property tests with default config"
(test-helper/with-config {}
(page-property-queries-test)))
(testing "page property tests with property-values-allow-links-and-text? config"
(test-helper/with-config {:property-values-allow-links-and-text? true}
(page-property-queries-test))))
(deftest task-queries
(load-test-files [{:file/path "pages/page1.md"