Add some tests

This commit is contained in:
Juho Teperi 2023-03-23 15:36:48 +02:00
parent dd724f0d0e
commit e3e93eaffb
2 changed files with 19 additions and 0 deletions

View file

@ -104,11 +104,13 @@
(rfh/replace-state @history name path-params query-params)))
(defn update-query
;; TODO: Sync the docstring with other namespaces
"Takes the current location and updates the query params
with given fn and arguments."
[f & args]
;; TODO: rfh version?
(let [current-path (rfh/-get-path @history)
new-path (apply rf/update-path-query-params current-path f args)]
;; TODO: replaceState version
(.pushState js/window.history nil "" new-path)
(rfh/-on-navigate @history new-path)))

View file

@ -227,3 +227,20 @@
: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 %)))))))