mirror of
https://github.com/metosin/reitit.git
synced 2025-12-17 16:31:11 +00:00
Add some tests
This commit is contained in:
parent
dd724f0d0e
commit
e3e93eaffb
2 changed files with 19 additions and 0 deletions
|
|
@ -104,11 +104,13 @@
|
||||||
(rfh/replace-state @history name path-params query-params)))
|
(rfh/replace-state @history name path-params query-params)))
|
||||||
|
|
||||||
(defn update-query
|
(defn update-query
|
||||||
|
;; TODO: Sync the docstring with other namespaces
|
||||||
"Takes the current location and updates the query params
|
"Takes the current location and updates the query params
|
||||||
with given fn and arguments."
|
with given fn and arguments."
|
||||||
[f & args]
|
[f & args]
|
||||||
;; TODO: rfh version?
|
;; TODO: rfh version?
|
||||||
(let [current-path (rfh/-get-path @history)
|
(let [current-path (rfh/-get-path @history)
|
||||||
new-path (apply rf/update-path-query-params current-path f args)]
|
new-path (apply rf/update-path-query-params current-path f args)]
|
||||||
|
;; TODO: replaceState version
|
||||||
(.pushState js/window.history nil "" new-path)
|
(.pushState js/window.history nil "" new-path)
|
||||||
(rfh/-on-navigate @history new-path)))
|
(rfh/-on-navigate @history new-path)))
|
||||||
|
|
|
||||||
|
|
@ -227,3 +227,20 @@
|
||||||
:token_type "bearer"
|
:token_type "bearer"
|
||||||
:expires_in 3600}}})
|
:expires_in 3600}}})
|
||||||
(m (rf/match-by-path router "/5?mode=foo#access_token=foo&refresh_token=bar&provider_token=baz&token_type=bearer&expires_in=3600"))))))))
|
(m (rf/match-by-path router "/5?mode=foo#access_token=foo&refresh_token=bar&provider_token=baz&token_type=bearer&expires_in=3600"))))))))
|
||||||
|
|
||||||
|
(deftest update-path-query-params-test
|
||||||
|
(is (= "foo?bar=1"
|
||||||
|
(rf/update-path-query-params "foo" #(assoc % :bar 1))))
|
||||||
|
|
||||||
|
(is (= "foo?asd=1&bar=1"
|
||||||
|
(rf/update-path-query-params "foo?asd=1" #(assoc % :bar 1))))
|
||||||
|
|
||||||
|
(is (= "foo?bar=1"
|
||||||
|
(rf/update-path-query-params "foo?asd=1&bar=1" #(dissoc % :asd))))
|
||||||
|
|
||||||
|
(is (= "foo"
|
||||||
|
(rf/update-path-query-params "foo?asd=1" #(dissoc % :asd))))
|
||||||
|
|
||||||
|
(testing "Need to coerce current values manually"
|
||||||
|
(is (= "foo?foo=2"
|
||||||
|
(rf/update-path-query-params "foo?foo=1" update :foo #(inc (js/parseInt %)))))))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue