mirror of https://github.com/logseq/logseq
chore: mv more tests to appropriate dep enabled by :build/journal
parent
14222a546f
commit
05227f475b
|
@ -2,6 +2,7 @@
|
|||
(:require [cljs.test :refer [deftest is]]
|
||||
[cljs-time.core :as t]
|
||||
[datascript.core :as d]
|
||||
[logseq.common.util.date-time :as date-time-util]
|
||||
[logseq.db.frontend.rules :as rules]
|
||||
[logseq.db.frontend.schema :as db-schema]
|
||||
[logseq.db.frontend.inputs :as db-inputs]
|
||||
|
@ -120,4 +121,104 @@
|
|||
:query '[:find (pull ?b [*])
|
||||
:in $ ?start ?end %
|
||||
:where (between ?b ?start ?end)]}))))
|
||||
":tomorrow and :Xd-after resolve to correct journal range")))
|
||||
":tomorrow and :Xd-after resolve to correct journal range")))
|
||||
|
||||
(defn- block-with-content [db block-content]
|
||||
(-> (d/q '[:find (pull ?b [:block/uuid])
|
||||
:in $ ?content
|
||||
:where [?b :block/content ?content]]
|
||||
db block-content)
|
||||
ffirst))
|
||||
|
||||
(defn- blocks-on-journal-page-from-block-with-content [db page-input block-content current-page-date]
|
||||
(map :block/content
|
||||
(custom-query db
|
||||
{:inputs [page-input]
|
||||
:query '[:find (pull ?b [*])
|
||||
:in $ ?page
|
||||
:where [?b :block/page ?e]
|
||||
[?e :block/name ?page]]
|
||||
:input-options
|
||||
{:current-block-uuid (get (block-with-content db block-content) :block/uuid)
|
||||
:current-page-fn (constantly
|
||||
(date-time-util/int->journal-title (date-time-util/date->int current-page-date)
|
||||
"MMM do, yyyy"))}})))
|
||||
|
||||
(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)
|
||||
_ (sqlite-build/create-blocks
|
||||
conn
|
||||
[{:page {:build/journal 20221231} :blocks [{:block/content "-1d"}]}
|
||||
{:page {:build/journal 20230101} :blocks [{:block/content "now"}]}
|
||||
{:page {:build/journal 20230102} :blocks [{:block/content "+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")
|
||||
|
||||
(is (= ["now"] (blocks-on-journal-page-from-block-with-content db :query-page "now" current-date))
|
||||
":query-page resolves to the stateful page when called from a block on the stateful page")
|
||||
|
||||
(is (= ["now"] (blocks-on-journal-page-from-block-with-content db :current-page "+1d" current-date))
|
||||
":current-page resolves to the stateful page when called from a block on another page")
|
||||
|
||||
(is (= ["+1d"] (blocks-on-journal-page-from-block-with-content db :query-page "+1d" current-date))
|
||||
":query-page resolves to the parent page when called from another page")))
|
||||
|
||||
(defn- blocks-journaled-between-inputs [db a b]
|
||||
;; reverse is for sort order and may be brittle
|
||||
(reverse
|
||||
(map :block/content
|
||||
(custom-query db
|
||||
{:inputs [a b]
|
||||
:query '[:find (pull ?b [*])
|
||||
:in $ ?start ?end %
|
||||
:where (between ?b ?start ?end)]}))))
|
||||
|
||||
(deftest resolve-input-for-relative-date-queries
|
||||
(let [conn (d/create-conn db-schema/schema-for-db-based-graph)
|
||||
_ (sqlite-build/create-blocks
|
||||
conn
|
||||
[{:page {:build/journal 20220101} :blocks [{:block/content "-1y"}]}
|
||||
{:page {:build/journal 20221201} :blocks [{:block/content "-1m"}]}
|
||||
{:page {:build/journal 20221225} :blocks [{:block/content "-1w"}]}
|
||||
{:page {:build/journal 20221231} :blocks [{:block/content "-1d"}]}
|
||||
{:page {:build/journal 20230101} :blocks [{:block/content "now"}]}
|
||||
{:page {:build/journal 20230102} :blocks [{:block/content "+1d"}]}
|
||||
{:page {:build/journal 20230108} :blocks [{:block/content "+1w"}]}
|
||||
{:page {:build/journal 20230201} :blocks [{:block/content "+1m"}]}
|
||||
{:page {:build/journal 20240101} :blocks [{:block/content "+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))
|
||||
":-365d and today resolve to correct journal range")
|
||||
|
||||
(is (= ["now" "-1d" "-1w" "-1m" "-1y"] (blocks-journaled-between-inputs db :-1y :today))
|
||||
":-1y and today resolve to correct journal range")
|
||||
|
||||
(is (= ["now" "-1d" "-1w" "-1m"] (blocks-journaled-between-inputs db :-1m :today))
|
||||
":-1m and today resolve to correct journal range")
|
||||
|
||||
(is (= ["now" "-1d" "-1w"] (blocks-journaled-between-inputs db :-1w :today))
|
||||
":-1w and today resolve to correct journal range")
|
||||
|
||||
(is (= ["now" "-1d"] (blocks-journaled-between-inputs db :-1d :today))
|
||||
":-1d and today resolve to correct journal range")
|
||||
|
||||
(is (= ["+1y" "+1m" "+1w" "+1d" "now"] (blocks-journaled-between-inputs db :today :+365d))
|
||||
":+365d and today resolve to correct journal range")
|
||||
|
||||
(is (= ["+1y" "+1m" "+1w" "+1d" "now"] (blocks-journaled-between-inputs db :today :+1y))
|
||||
":+1y and today resolve to correct journal range")
|
||||
|
||||
(is (= ["+1m" "+1w" "+1d" "now"] (blocks-journaled-between-inputs db :today :+1m))
|
||||
":+1m and today resolve to correct journal range")
|
||||
|
||||
(is (= ["+1w" "+1d" "now"] (blocks-journaled-between-inputs db :today :+1w))
|
||||
":+1w and today resolve to correct journal range")
|
||||
|
||||
(is (= ["+1d" "now"] (blocks-journaled-between-inputs db :today :+1d))
|
||||
":+1d and today resolve to correct journal range")
|
||||
|
||||
(is (= ["+1d" "now"] (blocks-journaled-between-inputs db :today :today/+1d))
|
||||
":today/+1d and today resolve to correct journal range"))))
|
|
@ -2,12 +2,9 @@
|
|||
(:require [cljs.test :refer [deftest is use-fixtures]]
|
||||
[cljs-time.core :as t]
|
||||
[clojure.string :as string]
|
||||
[frontend.state :as state]
|
||||
[frontend.date :as date]
|
||||
[logseq.db.frontend.inputs :as db-inputs]
|
||||
[frontend.test.helper :as test-helper :refer [load-test-files]]
|
||||
[frontend.db.query-custom :as query-custom]
|
||||
[frontend.db.utils :as db-utils]
|
||||
[goog.string :as gstring]))
|
||||
|
||||
(use-fixtures :each {:before test-helper/start-test-db!
|
||||
|
@ -32,42 +29,21 @@ adds rules that users often use"
|
|||
[(>= ?timestamp ?start)]
|
||||
[(<= ?timestamp ?end)]]}))))
|
||||
|
||||
(defn- blocks-journaled-between-inputs [a b]
|
||||
(map :block/content (custom-query {:inputs [a b]
|
||||
:query '[:find (pull ?b [*])
|
||||
:in $ ?start ?end
|
||||
:where (between ?b ?start ?end)]})))
|
||||
|
||||
(defn- block-with-content [block-content]
|
||||
(-> (db-utils/q '[:find (pull ?b [:block/uuid])
|
||||
:in $ ?content
|
||||
:where [?b :block/content ?content]]
|
||||
block-content)
|
||||
ffirst))
|
||||
|
||||
(defn- blocks-on-journal-page-from-block-with-content [page-input block-content]
|
||||
(map :block/content (custom-query {:inputs [page-input]
|
||||
:query '[:find (pull ?b [*])
|
||||
:in $ ?page
|
||||
:where [?b :block/page ?e]
|
||||
[?e :block/name ?page]]}
|
||||
{:current-block-uuid (get (block-with-content block-content) :block/uuid)})))
|
||||
|
||||
(defn- blocks-with-tag-on-specified-current-page [& {:keys [current-page tag]}]
|
||||
(map :block/content (custom-query {:title "Query title"
|
||||
:inputs [:current-page tag]
|
||||
:query '[:find (pull ?b [*])
|
||||
:inputs [:current-page tag]
|
||||
:query '[:find (pull ?b [*])
|
||||
:in $ ?current-page ?tag-name
|
||||
:where [?b :block/page ?bp]
|
||||
[?bp :block/name ?current-page]
|
||||
[?b :block/ref-pages ?t]
|
||||
[?t :block/name ?tag-name]]}
|
||||
:where [?b :block/page ?bp]
|
||||
[?bp :block/name ?current-page]
|
||||
[?b :block/ref-pages ?t]
|
||||
[?t :block/name ?tag-name]]}
|
||||
{:current-page-fn (constantly current-page)})))
|
||||
|
||||
;; TODO: Move most resolve-input tests to deps/db when a load-test-files helper is available for deps
|
||||
|
||||
;; These tests rely on seeding timestamps with properties. If this ability goes
|
||||
;; away we could still test page-level timestamps
|
||||
;; TODO: Move this test to inputs-test
|
||||
(deftest resolve-input-for-timestamp-inputs
|
||||
(load-test-files [{:file/path "pages/page1.md"
|
||||
:file/content (gstring/format "foo::bar
|
||||
|
@ -156,70 +132,6 @@ created-at:: %s"
|
|||
(is (= [] (blocks-created-between-inputs :-0d-abcd :+1d-23.45))
|
||||
":-XT-HHMM and :+XT-HHMM will not reoslve with invalid time formats but will fail gracefully"))
|
||||
|
||||
|
||||
(deftest resolve-input-for-relative-date-queries
|
||||
(load-test-files [{:file/content "- -1y" :file/path "journals/2022_01_01.md"}
|
||||
{:file/content "- -1m" :file/path "journals/2022_12_01.md"}
|
||||
{:file/content "- -1w" :file/path "journals/2022_12_25.md"}
|
||||
{:file/content "- -1d" :file/path "journals/2022_12_31.md"}
|
||||
{:file/content "- now" :file/path "journals/2023_01_01.md"}
|
||||
{:file/content "- +1d" :file/path "journals/2023_01_02.md"}
|
||||
{:file/content "- +1w" :file/path "journals/2023_01_08.md"}
|
||||
{:file/content "- +1m" :file/path "journals/2023_02_01.md"}
|
||||
{:file/content "- +1y" :file/path "journals/2024_01_01.md"}])
|
||||
|
||||
(with-redefs [t/today (constantly (t/date-time 2023 1 1))]
|
||||
(is (= ["now" "-1d" "-1w" "-1m" "-1y"] (blocks-journaled-between-inputs :-365d :today))
|
||||
":-365d and today resolve to correct journal range")
|
||||
|
||||
(is (= ["now" "-1d" "-1w" "-1m" "-1y"] (blocks-journaled-between-inputs :-1y :today))
|
||||
":-1y and today resolve to correct journal range")
|
||||
|
||||
(is (= ["now" "-1d" "-1w" "-1m"] (blocks-journaled-between-inputs :-1m :today))
|
||||
":-1m and today resolve to correct journal range")
|
||||
|
||||
(is (= ["now" "-1d" "-1w"] (blocks-journaled-between-inputs :-1w :today))
|
||||
":-1w and today resolve to correct journal range")
|
||||
|
||||
(is (= ["now" "-1d"] (blocks-journaled-between-inputs :-1d :today))
|
||||
":-1d and today resolve to correct journal range")
|
||||
|
||||
(is (= ["+1y" "+1m" "+1w" "+1d" "now"] (blocks-journaled-between-inputs :today :+365d))
|
||||
":+365d and today resolve to correct journal range")
|
||||
|
||||
(is (= ["+1y" "+1m" "+1w" "+1d" "now"] (blocks-journaled-between-inputs :today :+1y))
|
||||
":+1y and today resolve to correct journal range")
|
||||
|
||||
(is (= ["+1m" "+1w" "+1d" "now"] (blocks-journaled-between-inputs :today :+1m))
|
||||
":+1m and today resolve to correct journal range")
|
||||
|
||||
(is (= ["+1w" "+1d" "now"] (blocks-journaled-between-inputs :today :+1w))
|
||||
":+1w and today resolve to correct journal range")
|
||||
|
||||
(is (= ["+1d" "now"] (blocks-journaled-between-inputs :today :+1d))
|
||||
":+1d and today resolve to correct journal range")
|
||||
|
||||
(is (= ["+1d" "now"] (blocks-journaled-between-inputs :today :today/+1d))
|
||||
":today/+1d and today resolve to correct journal range")))
|
||||
|
||||
(deftest resolve-input-for-query-page
|
||||
(load-test-files [{:file/content "- -1d" :file/path "journals/2022_12_31.md"}
|
||||
{:file/content "- now" :file/path "journals/2023_01_01.md"}
|
||||
{:file/content "- +1d" :file/path "journals/2023_01_02.md"}])
|
||||
|
||||
(with-redefs [state/get-current-page (constantly (date/journal-name (t/date-time 2023 1 1)))]
|
||||
(is (= ["now"] (blocks-on-journal-page-from-block-with-content :current-page "now"))
|
||||
":current-page resolves to the stateful page when called from a block on the stateful page")
|
||||
|
||||
(is (= ["now"] (blocks-on-journal-page-from-block-with-content :query-page "now"))
|
||||
":query-page resolves to the stateful page when called from a block on the stateful page")
|
||||
|
||||
(is (= ["now"] (blocks-on-journal-page-from-block-with-content :current-page "+1d"))
|
||||
":current-page resolves to the stateful page when called from a block on another page")
|
||||
|
||||
(is (= ["+1d"] (blocks-on-journal-page-from-block-with-content :query-page "+1d"))
|
||||
":query-page resolves to the parent page when called from another page")))
|
||||
|
||||
(deftest cache-input-for-page-inputs
|
||||
(load-test-files [{:file/path "pages/a.md" :file/content "- a #shared-tag"}
|
||||
{:file/path "pages/b.md" :file/content "- b #shared-tag"}])
|
||||
|
|
Loading…
Reference in New Issue