Improve test failure readability (#18049)
Problem: failed equality checks as in "(is (= expected actual))" will give a single, long line of output that for anything but the simplest data structures is unreadable by humans, and the output doesn't give a useful diff. Solution: use library https://github.com/nubank/matcher-combinators and its test directive "match?" which will pinpoint where two data structures differ. Then, instead of "(is (= ...", use "(is (match? expected actual)". It works beautifully. The library offers other nice matchers, but the majority of the time match? is sufficient. Can we use another test runner like Kaocha? kaocha-cljs2 (https://github.com/lambdaisland/kaocha-cljs2) would be able to print better test errors out of the box, among other features, but I have no clue if it would work well or at all in our stack (in theory yes, but it's a larger piece of work).
This commit is contained in:
parent
6b612588c4
commit
563f1c588d
|
@ -62,7 +62,15 @@
|
|||
;; https://github.com/borkdude/clj-kondo/issues/867
|
||||
:unresolved-symbol {:exclude [PersistentPriorityMap.EMPTY
|
||||
number
|
||||
status-im.test-helpers/restore-app-db]}
|
||||
status-im.test-helpers/restore-app-db
|
||||
|
||||
;; When the namespace
|
||||
;; matcher-combinators.test is loaded, it
|
||||
;; extends cljs.test/is macro with
|
||||
;; directives `match?` and
|
||||
;; `thrown-match?`.
|
||||
match?
|
||||
thrown-match?]}
|
||||
:unresolved-var {:level :error}
|
||||
:unsorted-required-namespaces {:level :error}
|
||||
:unused-alias {:level :warning}
|
||||
|
|
|
@ -641,6 +641,26 @@ keywords and concatenating them into a single string.
|
|||
```
|
||||
|
||||
### Tests
|
||||
#### Prefer `match?` over `=` when comparing data structures
|
||||
|
||||
Prefer the `match?` directive over `=` when comparing data structures, otherwise
|
||||
when the check fails the output can be too difficult to read. `match?` is
|
||||
defined by library https://github.com/nubank/matcher-combinators.
|
||||
|
||||
```clojure
|
||||
;; bad
|
||||
(deftest some-test
|
||||
(let [expected {...}
|
||||
actual {...}]
|
||||
(is (= expected actual))))
|
||||
|
||||
;; good
|
||||
(deftest some-test
|
||||
(let [expected {...}
|
||||
actual {...}]
|
||||
(is (match? expected actual))))
|
||||
```
|
||||
|
||||
#### Subscription tests
|
||||
|
||||
Test [layer-3 subscriptions](https://day8.github.io/re-frame/subscriptions/) by
|
||||
|
|
|
@ -602,6 +602,15 @@
|
|||
}
|
||||
},
|
||||
|
||||
{
|
||||
"path": "nubank/matcher-combinators/3.8.8/matcher-combinators-3.8.8",
|
||||
"host": "https://repo.clojars.org",
|
||||
"jar": {
|
||||
"sha1": "4c94bd510f0c18a20191e46dd6becedebc640bbd",
|
||||
"sha256": "0wpla2hx0s4mda58ndyd8938zmnz1gyhgfr6pzfphy27xfbvsssl"
|
||||
}
|
||||
},
|
||||
|
||||
{
|
||||
"path": "org/apache/ant/ant/1.10.11/ant-1.10.11",
|
||||
"host": "https://repo1.maven.org/maven2",
|
||||
|
@ -746,6 +755,15 @@
|
|||
}
|
||||
},
|
||||
|
||||
{
|
||||
"path": "org/clojure/math.combinatorics/0.2.0/math.combinatorics-0.2.0",
|
||||
"host": "https://repo1.maven.org/maven2",
|
||||
"jar": {
|
||||
"sha1": "aa95d25ea98bfe1152ea540f6e58a303c8cacc86",
|
||||
"sha256": "0qvdsr5ryjmrpz622ivpyq5aayn42y4bk531vbasyj2yj7gcg35h"
|
||||
}
|
||||
},
|
||||
|
||||
{
|
||||
"path": "org/clojure/spec.alpha/0.3.218/spec.alpha-0.3.218",
|
||||
"host": "https://repo1.maven.org/maven2",
|
||||
|
|
|
@ -65,6 +65,7 @@ net/cgrand/macrovich/0.2.1/macrovich-0.2.1.jar
|
|||
net/java/dev/jna/jna/5.12.1/jna-5.12.1.jar
|
||||
nrepl/bencode/1.1.0/bencode-1.1.0.jar
|
||||
nrepl/nrepl/1.0.0/nrepl-1.0.0.jar
|
||||
nubank/matcher-combinators/3.8.8/matcher-combinators-3.8.8.jar
|
||||
org/apache/ant/ant/1.10.11/ant-1.10.11.jar
|
||||
org/apache/ant/ant-launcher/1.10.11/ant-launcher-1.10.11.jar
|
||||
org/babashka/sci/0.7.38/sci-0.7.38.jar
|
||||
|
@ -81,6 +82,7 @@ org/clojure/data.json/2.4.0/data.json-2.4.0.jar
|
|||
org/clojure/data.priority-map/1.1.0/data.priority-map-1.1.0.jar
|
||||
org/clojure/google-closure-library/0.0-20230227-c7c0a541/google-closure-library-0.0-20230227-c7c0a541.jar
|
||||
org/clojure/google-closure-library-third-party/0.0-20230227-c7c0a541/google-closure-library-third-party-0.0-20230227-c7c0a541.jar
|
||||
org/clojure/math.combinatorics/0.2.0/math.combinatorics-0.2.0.jar
|
||||
org/clojure/spec.alpha/0.3.218/spec.alpha-0.3.218.jar
|
||||
org/clojure/test.check/1.1.1/test.check-1.1.1.jar
|
||||
org/clojure/tools.analyzer/1.1.0/tools.analyzer-1.1.0.jar
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
[cider/piggieback "0.4.1"]
|
||||
[org.slf4j/slf4j-nop "2.0.9"]
|
||||
[re-frisk-remote "1.6.0"]
|
||||
[nubank/matcher-combinators "3.8.8"]
|
||||
|
||||
;; Use the same version specified in the Nix dependency.
|
||||
[clj-kondo/clj-kondo "2023.09.07"]
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
(ns status-im2.contexts.add-new-contact.events-test
|
||||
(:require
|
||||
[cljs.test :refer-macros [deftest are]]
|
||||
matcher-combinators.test
|
||||
[status-im2.contexts.add-new-contact.events :as events]))
|
||||
|
||||
(def user-ukey
|
||||
|
@ -18,7 +19,7 @@
|
|||
;;; unit tests (no app-db involved)
|
||||
|
||||
(deftest validate-contact-test
|
||||
(are [i e] (= (events/validate-contact (events/init-contact
|
||||
(are [i e] (match? (events/validate-contact (events/init-contact
|
||||
{:user-public-key user-ukey
|
||||
:input i}))
|
||||
(events/init-contact e))
|
||||
|
@ -90,7 +91,7 @@
|
|||
|
||||
(deftest set-new-identity-test
|
||||
(with-redefs [events/dispatcher (fn [& args] args)]
|
||||
(are [i edb] (= (events/set-new-identity {:db db} i nil) edb)
|
||||
(are [i edb] (match? (events/set-new-identity {:db db} i nil) edb)
|
||||
|
||||
"" {:db db}
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
(ns status-im2.contexts.chat.composer.link-preview.events-test
|
||||
(:require
|
||||
[cljs.test :refer [deftest is testing]]
|
||||
matcher-combinators.test
|
||||
[status-im2.contexts.chat.composer.link-preview.events :as events]))
|
||||
|
||||
(def url-github "https://github.com")
|
||||
|
@ -20,14 +21,14 @@
|
|||
(let [cofx {:db {:chat/link-previews {:unfurled {}
|
||||
:cache {}
|
||||
:request-id "123"}}}]
|
||||
(is (= {:db {:chat/link-previews {:cache {}}}}
|
||||
(is (match? {:db {:chat/link-previews {:cache {}}}}
|
||||
(events/unfurl-urls cofx " ")))))
|
||||
|
||||
(testing "fetches parsed URLs"
|
||||
(let [cofx {:db {:chat/link-previews {:unfurled {}
|
||||
:cache {}
|
||||
:request-id "123"}}}]
|
||||
(is (= {:json-rpc/call [{:method "wakuext_getTextURLs"
|
||||
(is (match? {:json-rpc/call [{:method "wakuext_getTextURLs"
|
||||
:params [url-github]}]}
|
||||
(remove-rpc-callbacks
|
||||
(events/unfurl-urls cofx url-github)))))))
|
||||
|
@ -38,7 +39,7 @@
|
|||
(let [cofx {:db {:chat/link-previews
|
||||
{:cache {}
|
||||
:unfurled []}}}]
|
||||
(is (= {:db {:chat/link-previews
|
||||
(is (match? {:db {:chat/link-previews
|
||||
{:request-id request-id
|
||||
:cache {}
|
||||
:unfurled [{:url url-github :loading? true}
|
||||
|
@ -53,7 +54,7 @@
|
|||
cofx {:db {:chat/link-previews
|
||||
{:cache cache
|
||||
:unfurled []}}}]
|
||||
(is (= {:db {:chat/link-previews
|
||||
(is (match? {:db {:chat/link-previews
|
||||
{:request-id request-id
|
||||
:cache cache
|
||||
:unfurled [preview-github
|
||||
|
@ -75,7 +76,7 @@
|
|||
cofx {:db {:chat/link-previews
|
||||
{:cache cache
|
||||
:unfurled [preview-github]}}}]
|
||||
(is (= {:db {:chat/link-previews
|
||||
(is (match? {:db {:chat/link-previews
|
||||
{:request-id request-id
|
||||
:cache cache
|
||||
:unfurled []}}}
|
||||
|
@ -87,7 +88,7 @@
|
|||
cofx {:db {:chat/link-previews
|
||||
{:cache cache
|
||||
:unfurled [preview-github preview-gitlab]}}}]
|
||||
(is (= {:db {:chat/link-previews
|
||||
(is (match? {:db {:chat/link-previews
|
||||
{:request-id request-id
|
||||
:cache cache
|
||||
:unfurled [preview-github preview-gitlab]}}}
|
||||
|
@ -100,7 +101,7 @@
|
|||
cofx {:db {:chat/link-previews
|
||||
{:cache cache
|
||||
:unfurled [preview-github]}}}]
|
||||
(is (= {:db {:chat/link-previews
|
||||
(is (match? {:db {:chat/link-previews
|
||||
{:request-id request-id
|
||||
:cache cache
|
||||
:unfurled [preview-github]}}}
|
||||
|
@ -111,7 +112,7 @@
|
|||
cofx {:db {:chat/link-previews
|
||||
{:cache cache
|
||||
:unfurled []}}}]
|
||||
(is (= {:db {:chat/link-previews
|
||||
(is (match? {:db {:chat/link-previews
|
||||
{:request-id request-id
|
||||
:cache cache
|
||||
:unfurled [{:url url-github :loading? true}]}}
|
||||
|
@ -127,7 +128,7 @@
|
|||
cofx {:db {:chat/link-previews
|
||||
{:cache cache
|
||||
:unfurled [preview-github]}}}]
|
||||
(is (= {:db {:chat/link-previews
|
||||
(is (match? {:db {:chat/link-previews
|
||||
{:request-id request-id
|
||||
:cache cache
|
||||
:unfurled []}}}
|
||||
|
@ -152,7 +153,7 @@
|
|||
cofx
|
||||
request-id
|
||||
{:linkPreviews [preview-gitlab]})]
|
||||
(is (= {:chat/link-previews
|
||||
(is (match? {:chat/link-previews
|
||||
{:request-id request-id
|
||||
:unfurled [preview-github preview-gitlab]
|
||||
:cache {url-github preview-github
|
||||
|
@ -172,7 +173,7 @@
|
|||
request-id
|
||||
{:linkPreviews [preview-github
|
||||
preview-youtube]})]
|
||||
(is (= {:chat/link-previews
|
||||
(is (match? {:chat/link-previews
|
||||
{:request-id request-id
|
||||
:unfurled [preview-github preview-youtube]
|
||||
:cache {(:url preview-youtube) preview-youtube
|
||||
|
@ -186,13 +187,13 @@
|
|||
{:db {:chat/link-previews {:unfurled [preview-github]
|
||||
:request-id request-id
|
||||
:cache cache}}})]
|
||||
(is (= {:db {:chat/link-previews {:cache cache
|
||||
(is (match? {:db {:chat/link-previews {:cache cache
|
||||
:cleared #{url-github}}}}
|
||||
effects))))
|
||||
|
||||
(deftest reset-unfurled-test
|
||||
(let [cache {url-github preview-github}]
|
||||
(is (= {:db {:chat/link-previews {:cache cache}}}
|
||||
(is (match? {:db {:chat/link-previews {:cache cache}}}
|
||||
(events/reset-unfurled
|
||||
{:db {:chat/link-previews {:unfurled [preview-github]
|
||||
:request-id request-id
|
||||
|
@ -200,7 +201,7 @@
|
|||
:cache cache}}})))))
|
||||
|
||||
(deftest reset-all-test
|
||||
(is (= {:db {:non-related-key :some-value}}
|
||||
(is (match? {:db {:non-related-key :some-value}}
|
||||
(events/reset-all
|
||||
{:db {:non-related-key :some-value
|
||||
:chat/link-previews {:request-id request-id
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
(ns status-im2.contexts.communities.discover.events-test
|
||||
(:require
|
||||
[cljs.test :refer-macros [deftest are]]
|
||||
matcher-combinators.test
|
||||
[status-im2.contexts.communities.discover.events :as events]))
|
||||
|
||||
(deftest rename-contract-community-key-test
|
||||
|
@ -13,7 +14,7 @@
|
|||
:3f9e77b8-97c7 "3f9e77b8-97c7"))
|
||||
|
||||
(deftest rename-contract-community-keys-test
|
||||
(are [i e] (= (events/rename-contract-community-keys i) e)
|
||||
(are [i e] (match? (events/rename-contract-community-keys i) e)
|
||||
|
||||
{:contractCommunities
|
||||
["0x032aa2439b14eb2caaf724223951da89de1530fbfa5d5a639b93b82cd5341713fd"
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
(ns status-im2.contexts.communities.overview.events-test
|
||||
(:require [cljs.test :refer [deftest is]]
|
||||
matcher-combinators.test
|
||||
[native-module.core :as native-module]
|
||||
[status-im2.contexts.communities.overview.events :as sut]))
|
||||
|
||||
|
@ -14,7 +15,7 @@
|
|||
:params [account-pub-key community-id []]
|
||||
:on-success [:communities/sign-data community-id password]
|
||||
:on-error [:communities/requested-to-join-error community-id]}]]]}]
|
||||
(is (= expected
|
||||
(is (match? expected
|
||||
(sut/request-to-join cofx
|
||||
[{:community-id community-id
|
||||
:password password}])))))
|
||||
|
@ -32,7 +33,7 @@
|
|||
:on-success [:communities/request-to-join-with-signatures
|
||||
community-id addresses-to-reveal]
|
||||
:on-error [:communities/requested-to-join-error community-id]}]]]}]
|
||||
(is (= expected
|
||||
(is (match? expected
|
||||
(sut/sign-data cofx [community-id password sign-params])))))
|
||||
|
||||
(deftest request-to-join-with-signatures-test
|
||||
|
@ -49,5 +50,6 @@
|
|||
:on-success [:communities/requested-to-join]
|
||||
:on-error [:communities/requested-to-join-error
|
||||
community-id]}]]]}]
|
||||
(is (= expected
|
||||
(sut/request-to-join-with-signatures cofx [community-id addresses-to-reveal signatures])))))
|
||||
(is (match? expected
|
||||
(sut/request-to-join-with-signatures cofx
|
||||
[community-id addresses-to-reveal signatures])))))
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
(ns status-im2.contexts.shell.activity-center.events-test
|
||||
(:require
|
||||
[cljs.test :refer [deftest is testing]]
|
||||
matcher-combinators.test
|
||||
[status-im2.constants :as constants]
|
||||
[status-im2.contexts.shell.activity-center.events :as events]
|
||||
[status-im2.contexts.shell.activity-center.notification-types :as types]
|
||||
|
@ -14,13 +15,13 @@
|
|||
|
||||
(deftest open-activity-center-test
|
||||
(testing "opens the activity center with default filters"
|
||||
(is (= {:db {}
|
||||
(is (match? {:db {}
|
||||
:fx [[:dispatch [:open-modal :activity-center {}]]
|
||||
[:dispatch-later [{:ms 1000 :dispatch [:activity-center/mark-as-seen]}]]]}
|
||||
(events/open-activity-center {:db {}} [nil]))))
|
||||
|
||||
(testing "opens the activity center with filters enabled"
|
||||
(is (= {:db {:activity-center {:filter {:status :unread :type types/contact-request}}}
|
||||
(is (match? {:db {:activity-center {:filter {:status :unread :type types/contact-request}}}
|
||||
:fx [[:dispatch [:open-modal :activity-center {}]]
|
||||
[:dispatch-later [{:ms 1000 :dispatch [:activity-center/mark-as-seen]}]]]}
|
||||
(events/open-activity-center {:db {}}
|
||||
|
@ -34,7 +35,7 @@
|
|||
notification-id
|
||||
:some-action-name
|
||||
:some-error)))
|
||||
(is (= {:args ["Failed to :some-action-name"
|
||||
(is (match? {:args ["Failed to :some-action-name"
|
||||
{:notification-id notification-id
|
||||
:error :some-error}]
|
||||
:level :warn}
|
||||
|
@ -53,7 +54,7 @@
|
|||
(testing "dispatches RPC call"
|
||||
(let [notif {:id "0x1" :read false :type types/one-to-one-chat}
|
||||
cofx {:db {:activity-center {:notifications [notif]}}}]
|
||||
(is (= {:json-rpc/call
|
||||
(is (match? {:json-rpc/call
|
||||
[{:method "wakuext_markActivityCenterNotificationsRead"
|
||||
:params [[(:id notif)]]
|
||||
:on-success [:activity-center.notifications/mark-as-read-success notif]
|
||||
|
@ -70,7 +71,7 @@
|
|||
(reset! f-args args)
|
||||
:result)]
|
||||
(is (= :result (events/mark-as-read-success cofx notif)))
|
||||
(is (= [cofx [(assoc notif :read true)]]
|
||||
(is (match? [cofx [(assoc notif :read true)]]
|
||||
@f-args)))))
|
||||
|
||||
(deftest mark-as-unread-test
|
||||
|
@ -84,7 +85,7 @@
|
|||
(testing "dispatches RPC call"
|
||||
(let [notif {:id "0x1" :read true :type types/one-to-one-chat}
|
||||
cofx {:db {:activity-center {:notifications [notif]}}}]
|
||||
(is (= {:json-rpc/call
|
||||
(is (match? {:json-rpc/call
|
||||
[{:method "wakuext_markActivityCenterNotificationsUnread"
|
||||
:params [[(:id notif)]]
|
||||
:on-success [:activity-center.notifications/mark-as-unread-success notif]
|
||||
|
@ -101,13 +102,13 @@
|
|||
(reset! f-args args)
|
||||
:reconciliation-result)]
|
||||
(is (= :reconciliation-result (events/mark-as-unread-success cofx notif)))
|
||||
(is (= [cofx [(assoc notif :read false)]]
|
||||
(is (match? [cofx [(assoc notif :read false)]]
|
||||
@f-args)))))
|
||||
|
||||
;;;; Acceptance/dismissal
|
||||
|
||||
(deftest accept-notification-test
|
||||
(is (= {:json-rpc/call
|
||||
(is (match? {:json-rpc/call
|
||||
[{:method "wakuext_acceptActivityCenterNotifications"
|
||||
:params [[notification-id]]
|
||||
:on-success [:activity-center.notifications/accept-success notification-id]
|
||||
|
@ -129,12 +130,12 @@
|
|||
notif-2-accepted (assoc notif-2 :accepted true :read true)
|
||||
cofx {:db {:activity-center {:filter {:type types/no-type :status :all}
|
||||
:notifications [notif-2 notif-1]}}}]
|
||||
(is (= {:fx [[:dispatch [:chat/ensure-chats []]]
|
||||
(is (match? {:fx [[:dispatch [:chat/ensure-chats []]]
|
||||
[:dispatch [:activity-center.notifications/reconcile [notif-2-accepted]]]]}
|
||||
(events/accept-notification-success cofx [(:id notif-2) nil]))))))
|
||||
|
||||
(deftest dismiss-notification-test
|
||||
(is (= {:json-rpc/call
|
||||
(is (match? {:json-rpc/call
|
||||
[{:method "wakuext_dismissActivityCenterNotifications"
|
||||
:params [[notification-id]]
|
||||
:on-success [:activity-center.notifications/dismiss-success notification-id]
|
||||
|
@ -156,7 +157,7 @@
|
|||
notif-2-dismissed (assoc notif-2 :dismissed true :read true)
|
||||
cofx {:db {:activity-center {:filter {:type types/no-type :status :all}
|
||||
:notifications [notif-2 notif-1]}}}]
|
||||
(is (= {:db {:activity-center {:filter {:type 0 :status :all}
|
||||
(is (match? {:db {:activity-center {:filter {:type 0 :status :all}
|
||||
:notifications [notif-2-dismissed notif-1]}}
|
||||
:dispatch-n [[:activity-center.notifications/fetch-unread-count]
|
||||
[:activity-center.notifications/fetch-pending-contact-requests]]}
|
||||
|
@ -208,7 +209,7 @@
|
|||
:type types/contact-verification})
|
||||
|
||||
(deftest contact-verification-decline-test
|
||||
(is (= {:json-rpc/call
|
||||
(is (match? {:json-rpc/call
|
||||
[{:method "wakuext_declineContactVerificationRequest"
|
||||
:params [notification-id]
|
||||
:on-success [:activity-center/reconcile-notifications-from-response]
|
||||
|
@ -218,7 +219,7 @@
|
|||
|
||||
(deftest contact-verification-reply-test
|
||||
(let [reply "The answer is 42"]
|
||||
(is (= {:json-rpc/call
|
||||
(is (match? {:json-rpc/call
|
||||
[{:method "wakuext_acceptContactVerificationRequest"
|
||||
:params [notification-id reply]
|
||||
:on-success [:activity-center/reconcile-notifications-from-response]
|
||||
|
@ -227,7 +228,7 @@
|
|||
(events/contact-verification-reply {:db {}} notification-id reply)))))
|
||||
|
||||
(deftest contact-verification-mark-as-trusted-test
|
||||
(is (= {:json-rpc/call
|
||||
(is (match? {:json-rpc/call
|
||||
[{:method "wakuext_verifiedTrusted"
|
||||
:params [{:id notification-id}]
|
||||
:on-success [:activity-center/reconcile-notifications-from-response]
|
||||
|
@ -236,7 +237,7 @@
|
|||
(events/contact-verification-mark-as-trusted {:db {}} notification-id))))
|
||||
|
||||
(deftest contact-verification-mark-as-untrustworthy-test
|
||||
(is (= {:json-rpc/call
|
||||
(is (match? {:json-rpc/call
|
||||
[{:method "wakuext_verifiedUntrustworthy"
|
||||
:params [{:id notification-id}]
|
||||
:on-success [:activity-center/reconcile-notifications-from-response]
|
||||
|
@ -256,7 +257,7 @@
|
|||
cofx {:db {:activity-center
|
||||
{:filter {:type types/no-type :status :all}
|
||||
:notifications [notif-2 notif-1]}}}]
|
||||
(is (= {:db {:activity-center
|
||||
(is (match? {:db {:activity-center
|
||||
{:filter {:type types/no-type :status :all}
|
||||
:notifications [new-notif-4 new-notif-3 new-notif-2]}}
|
||||
:dispatch-n [[:activity-center.notifications/fetch-unread-count]
|
||||
|
@ -278,7 +279,7 @@
|
|||
cofx {:db {:activity-center
|
||||
{:filter {:type types/no-type :status :unread}
|
||||
:notifications [notif-5 notif-2 notif-1]}}}]
|
||||
(is (= {:db {:activity-center
|
||||
(is (match? {:db {:activity-center
|
||||
{:filter {:type types/no-type :status :unread}
|
||||
:notifications [new-notif-3 notif-1]}}
|
||||
:dispatch-n [[:activity-center.notifications/fetch-unread-count]
|
||||
|
@ -301,7 +302,7 @@
|
|||
cofx {:db {:activity-center
|
||||
{:filter {:type types/contact-request :status :all}
|
||||
:notifications [notif-5 notif-2 notif-1]}}}]
|
||||
(is (= {:db {:activity-center
|
||||
(is (match? {:db {:activity-center
|
||||
{:filter {:type types/contact-request :status :all}
|
||||
:notifications [new-notif-3 new-notif-2 notif-1]}}
|
||||
:dispatch-n [[:activity-center.notifications/fetch-unread-count]
|
||||
|
@ -326,7 +327,7 @@
|
|||
{:filter {:type types/contact-request
|
||||
:status :unread}
|
||||
:notifications [notif-6 notif-2 notif-1]}}}]
|
||||
(is (= {:db {:activity-center
|
||||
(is (match? {:db {:activity-center
|
||||
{:filter {:type types/contact-request
|
||||
:status :unread}
|
||||
:notifications [new-notif-3 notif-1]}}
|
||||
|
@ -354,7 +355,7 @@
|
|||
cofx {:db {:activity-center
|
||||
{:notifications [notif-1 notif-3 notif-4 notif-2
|
||||
notif-5]}}}]
|
||||
(is (= {:db {:activity-center
|
||||
(is (match? {:db {:activity-center
|
||||
{:notifications [notif-5
|
||||
new-notif-4
|
||||
notif-3
|
||||
|
@ -376,7 +377,7 @@
|
|||
notif-2 ; will be removed
|
||||
notif-1 ; will be ignored because it's not from the same author
|
||||
]}}}]
|
||||
(is (= {:db {:activity-center {:notifications [notif-3 notif-1]}}}
|
||||
(is (match? {:db {:activity-center {:notifications [notif-3 notif-1]}}}
|
||||
(events/notifications-remove-pending-contact-request cofx author))))))
|
||||
|
||||
;;;; Notifications fetching and pagination
|
||||
|
@ -384,12 +385,13 @@
|
|||
(deftest notifications-fetch-first-page-test
|
||||
(testing "fetches first page"
|
||||
(let [cofx {:db {}}]
|
||||
(is (= {:db {:activity-center {:filter {:type types/one-to-one-chat
|
||||
(is (match? {:db {:activity-center {:filter {:type types/one-to-one-chat
|
||||
:status :unread}
|
||||
:loading? true}}
|
||||
:json-rpc/call [{:method "wakuext_activityCenterNotifications"
|
||||
:params [{:cursor ""
|
||||
:limit (:notifications-per-page events/defaults)
|
||||
:limit (:notifications-per-page
|
||||
events/defaults)
|
||||
:activityTypes [types/one-to-one-chat]
|
||||
:readType events/read-type-unread}]
|
||||
:on-success [:activity-center.notifications/fetch-success true]
|
||||
|
@ -413,7 +415,7 @@
|
|||
(reset! f-args args)
|
||||
:result)]
|
||||
(is (= :result (events/notifications-fetch-next-page cofx)))
|
||||
(is (= [cofx
|
||||
(is (match? [cofx
|
||||
{:cursor cursor
|
||||
:filter-type types/one-to-one-chat
|
||||
:filter-status :unread
|
||||
|
@ -427,23 +429,23 @@
|
|||
:filter {:status :unread
|
||||
:type types/one-to-one-chat}
|
||||
:cursor ""}}}]
|
||||
(is (= {:db {:activity-center {:filter {:status :unread
|
||||
(is (match? {:db {:activity-center {:filter {:status :unread
|
||||
:type types/one-to-one-chat}
|
||||
:cursor ""}}}
|
||||
(events/notifications-fetch-error cofx :dummy-error))))))
|
||||
|
||||
(deftest seen-state-test
|
||||
(testing "update seen state"
|
||||
(is (= {:db {:activity-center {:seen? true}}}
|
||||
(is (match? {:db {:activity-center {:seen? true}}}
|
||||
(events/reconcile-seen-state {:db {}} true))))
|
||||
|
||||
(testing "update seen state when the user is on other screen"
|
||||
(is (= {:db {:view-id :chats-stack
|
||||
(is (match? {:db {:view-id :chats-stack
|
||||
:activity-center {:seen? false}}}
|
||||
(events/reconcile-seen-state {:db {:view-id :chats-stack}} false))))
|
||||
|
||||
(testing "update seen state when the user is on activity center"
|
||||
(is (= {:db {:view-id :activity-center
|
||||
(is (match? {:db {:view-id :activity-center
|
||||
:activity-center {:seen? false}}
|
||||
:dispatch [:activity-center/mark-as-seen]}
|
||||
(events/reconcile-seen-state {:db {:view-id :activity-center}} false)))))
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
(ns status-im2.contexts.wallet.events-test
|
||||
(:require
|
||||
[cljs.test :refer-macros [deftest is testing]]
|
||||
matcher-combinators.test
|
||||
[status-im2.contexts.wallet.events :as events]))
|
||||
|
||||
(def address "0x2f88d65f3cb52605a54a833ae118fb1363acccd2")
|
||||
|
@ -11,7 +12,7 @@
|
|||
(let [expected-db {:wallet/scanned-address address}
|
||||
effects (events/scan-address-success {:db db} address)
|
||||
result-db (:db effects)]
|
||||
(is (= result-db expected-db))))))
|
||||
(is (match? result-db expected-db))))))
|
||||
|
||||
(deftest clean-scanned-address
|
||||
(let [db {:wallet/scanned-address address}]
|
||||
|
@ -19,7 +20,7 @@
|
|||
(let [expected-db {}
|
||||
effects (events/clean-scanned-address {:db db})
|
||||
result-db (:db effects)]
|
||||
(is (= result-db expected-db))))))
|
||||
(is (match? result-db expected-db))))))
|
||||
|
||||
(deftest store-collectibles
|
||||
(testing "(displayable-collectible?) helper function"
|
||||
|
@ -34,7 +35,8 @@
|
|||
[false {:collectible-data {:image-url nil :animation-url ""}}]
|
||||
[false {:collectible-data {:image-url "" :animation-url ""}}]]]
|
||||
(doseq [[result collection] expected-results]
|
||||
(is (= result (events/displayable-collectible? collection))))))
|
||||
(is (match? result (events/displayable-collectible? collection))))))
|
||||
|
||||
(testing "save-collectibles-request-details"
|
||||
(let [db {:wallet {}}
|
||||
collectibles [{:collectible-data {:image-url "https://..." :animation-url "https://..."}}
|
||||
|
@ -46,7 +48,7 @@
|
|||
{:image-url "" :animation-url "https://..."}}]}}
|
||||
effects (events/store-collectibles {:db db} [collectibles])
|
||||
result-db (:db effects)]
|
||||
(is (= result-db expected-db)))))
|
||||
(is (match? result-db expected-db)))))
|
||||
|
||||
(deftest clear-stored-collectibles
|
||||
(let [db {:wallet {:collectibles [{:id 1} {:id 2}]}}]
|
||||
|
@ -54,7 +56,7 @@
|
|||
(let [expected-db {:wallet {}}
|
||||
effects (events/clear-stored-collectibles {:db db})
|
||||
result-db (:db effects)]
|
||||
(is (= result-db expected-db))))))
|
||||
(is (match? result-db expected-db))))))
|
||||
|
||||
(deftest store-last-collectible-details
|
||||
(testing "store-last-collectible-details"
|
||||
|
@ -65,4 +67,4 @@
|
|||
:image-url "https://..."}}}
|
||||
effects (events/store-last-collectible-details {:db db} [last-collectible])
|
||||
result-db (:db effects)]
|
||||
(is (= result-db expected-db)))))
|
||||
(is (match? result-db expected-db)))))
|
||||
|
|
Loading…
Reference in New Issue