mirror of
https://github.com/status-im/status-react.git
synced 2025-01-10 19:16:59 +00:00
events.cljs: Refactor
Reduce the overall nesting level in the test. Each `testing' statement now fits on a single screen, instead of spanning hundreds of lines. The final top-level expression went from 16 to 5 consecutive closing parens. Signed-off-by: Goran Jovic <goranjovic@gmail.com>
This commit is contained in:
parent
90863f1670
commit
f4b33d47ee
@ -192,24 +192,21 @@
|
||||
|
||||
(rf/dispatch [:initialize-db])
|
||||
|
||||
(let [contacts (rf/subscribe [:get-contacts])
|
||||
contact-groups (rf/subscribe [:get-contact-groups])
|
||||
view-id (rf/subscribe [:get :view-id])]
|
||||
(def contacts (rf/subscribe [:get-contacts]))
|
||||
(def contact-groups (rf/subscribe [:get-contact-groups]))
|
||||
(def view-id (rf/subscribe [:get :view-id]))
|
||||
|
||||
(testing ":load-contacts event"
|
||||
|
||||
;;Assert the initial state
|
||||
(is (and (map? @contacts) (empty? @contacts)))
|
||||
|
||||
(rf/dispatch [:load-contacts]))
|
||||
|
||||
(testing ":load-contact-groups event"
|
||||
|
||||
;;Assert the initial state
|
||||
(is (and (map? @contact-groups) (empty? @contact-groups)))
|
||||
|
||||
(rf/dispatch [:load-contact-groups])
|
||||
|
||||
(is (= {(:group-id test-contact-group) test-contact-group}
|
||||
@contact-groups)))
|
||||
|
||||
@ -239,14 +236,14 @@
|
||||
(testing "it does not add any other contact"
|
||||
(is (= 2 (count (keys @contacts))))))
|
||||
|
||||
(let [new-contact-public-key "0x048f7d5d4bda298447bbb5b021a34832509bd1a8dbe4e06f9b7223d00a59b6dc14f6e142b21d3220ceb3155a6d8f40ec115cd96394d3cc7c55055b433a1758dc74"
|
||||
new-contact-address "5392ccb49f2e9fef8b8068b3e3b5ba6c020a9aca"
|
||||
new-contact {:name ""
|
||||
(def new-contact-public-key "0x048f7d5d4bda298447bbb5b021a34832509bd1a8dbe4e06f9b7223d00a59b6dc14f6e142b21d3220ceb3155a6d8f40ec115cd96394d3cc7c55055b433a1758dc74")
|
||||
(def new-contact-address "5392ccb49f2e9fef8b8068b3e3b5ba6c020a9aca")
|
||||
(def new-contact {:name ""
|
||||
:photo-path ""
|
||||
:whisper-identity new-contact-public-key
|
||||
:address new-contact-address}
|
||||
contact (rf/subscribe [:contact-by-identity new-contact-public-key])
|
||||
current-chat-id (rf/subscribe [:get-current-chat-id])]
|
||||
:address new-contact-address})
|
||||
(def contact (rf/subscribe [:contact-by-identity new-contact-public-key]))
|
||||
(def current-chat-id (rf/subscribe [:get-current-chat-id]))
|
||||
|
||||
(testing ":add-contact-handler event - new contact"
|
||||
|
||||
@ -286,16 +283,15 @@
|
||||
;; :watch-contact
|
||||
;;TODO :update-chat!
|
||||
(rf/reg-event-db :update-chat! (fn [db _] db))
|
||||
|
||||
(let [received-contact {:name "test"
|
||||
(def received-contact {:name "test"
|
||||
:profile-image ""
|
||||
:address new-contact-address
|
||||
:status "test status"
|
||||
:fcm-token "0xwhatever"}
|
||||
received-contact' (merge new-contact
|
||||
:fcm-token "0xwhatever"})
|
||||
(def received-contact1 (merge new-contact
|
||||
(dissoc received-contact :profile-image)
|
||||
{:public-key new-contact-public-key
|
||||
:private-key ""})]
|
||||
:private-key ""}))
|
||||
|
||||
(rf/dispatch [:contact-request-received {:from new-contact-public-key
|
||||
:payload {:contact received-contact
|
||||
@ -303,8 +299,8 @@
|
||||
:private ""}}}])
|
||||
|
||||
(testing "it adds the new contact to the list of contacts"
|
||||
(is (= received-contact'
|
||||
(get @contacts new-contact-public-key))))
|
||||
(is (= received-contact1
|
||||
(get @contacts new-contact-public-key)))))
|
||||
|
||||
(testing ":contact-update-received event"
|
||||
|
||||
@ -312,21 +308,21 @@
|
||||
;;
|
||||
;; :update-contact!
|
||||
;;TODO :update-chat!
|
||||
(let [timestamp (datetime/now-ms)
|
||||
received-contact'' (assoc received-contact'
|
||||
(let [timestamp (datetime/now-ms)]
|
||||
(def received-contact2 (assoc received-contact1
|
||||
:last-updated timestamp
|
||||
:status "new status"
|
||||
:name "new name")]
|
||||
:name "new name"))
|
||||
|
||||
(rf/dispatch [:contact-update-received {:from new-contact-public-key
|
||||
:payload {:content {:profile {:profile-image ""
|
||||
:status "new status"
|
||||
:name "new name"}}
|
||||
:timestamp timestamp}}])
|
||||
:timestamp timestamp}}]))
|
||||
|
||||
(testing "it updates the contact and set the :last-updated key"
|
||||
(is (= received-contact''
|
||||
(get @contacts new-contact-public-key))))
|
||||
(is (= received-contact2
|
||||
(get @contacts new-contact-public-key)))))
|
||||
|
||||
(testing ":hide-contact event"
|
||||
|
||||
@ -339,7 +335,7 @@
|
||||
(rf/dispatch [:hide-contact @contact])
|
||||
|
||||
(testing "it sets the pending? flag to true"
|
||||
(is (= (assoc received-contact'' :pending? true)
|
||||
(is (= (assoc received-contact2 :pending? true)
|
||||
(get @contacts new-contact-public-key)))))
|
||||
|
||||
(testing ":add-contact-handler event - :add-pending-contact"
|
||||
@ -358,7 +354,7 @@
|
||||
(rf/dispatch [:add-contact-handler])
|
||||
|
||||
(testing "it sets the pending? flag to false"
|
||||
(is (= (assoc received-contact'' :pending? false)
|
||||
(is (= (assoc received-contact2 :pending? false)
|
||||
(get @contacts new-contact-public-key))))
|
||||
|
||||
(testing "it loads the 1-1 chat"
|
||||
@ -369,8 +365,7 @@
|
||||
|
||||
(testing ":create-new-contact-group event"
|
||||
|
||||
(let [new-group-name "new group"]
|
||||
|
||||
(def new-group-name "new group")
|
||||
(rf/dispatch [:select-contact new-contact-public-key])
|
||||
(rf/dispatch [:select-contact "demo-bot"])
|
||||
(rf/dispatch [:select-contact "browse"])
|
||||
@ -380,27 +375,28 @@
|
||||
|
||||
(rf/dispatch [:deselect-contact "demo-bot"])
|
||||
(rf/dispatch [:deselect-contact new-contact-public-key])
|
||||
|
||||
(let [new-group-id (->> @contact-groups
|
||||
(def new-group-id (->> @contact-groups
|
||||
(vals)
|
||||
(filter #(= (:name %) new-group-name))
|
||||
(first)
|
||||
(:group-id))
|
||||
new-group {:group-id new-group-id
|
||||
(:group-id)))
|
||||
(def new-group {:group-id new-group-id
|
||||
:name new-group-name
|
||||
:order 2
|
||||
:timestamp 0
|
||||
:contacts [{:identity new-contact-public-key}
|
||||
{:identity "demo-bot"}]}
|
||||
groups-with-new-group {new-group-id new-group
|
||||
{:identity "demo-bot"}]})
|
||||
(def groups-with-new-group {new-group-id new-group
|
||||
"dapps" dapps-contact-group
|
||||
(:group-id test-contact-group) test-contact-group}]
|
||||
(:group-id test-contact-group) test-contact-group})
|
||||
(def groups-with-new-group1 (update groups-with-new-group new-group-id assoc :name "new group name"))
|
||||
(def groups-with-new-group2 (-> groups-with-new-group1
|
||||
(update new-group-id assoc :order 1)
|
||||
(update "dapps" assoc :order 2)))
|
||||
|
||||
(rf/dispatch [:set-in [:group/contact-groups new-group-id :timestamp] 0])
|
||||
|
||||
(is (= groups-with-new-group @contact-groups))
|
||||
|
||||
(let [groups-with-new-group' (update groups-with-new-group new-group-id assoc :name "new group name")]
|
||||
(is (= groups-with-new-group @contact-groups)))
|
||||
|
||||
(testing ":set-contact-group-name event"
|
||||
|
||||
@ -412,11 +408,7 @@
|
||||
(rf/dispatch [::prepare-group-name])
|
||||
(rf/dispatch [:set-contact-group-name])
|
||||
|
||||
(is (= groups-with-new-group' @contact-groups)))
|
||||
|
||||
(let [groups-with-new-group'' (-> groups-with-new-group'
|
||||
(update new-group-id assoc :order 1)
|
||||
(update "dapps" assoc :order 2))]
|
||||
(is (= groups-with-new-group1 @contact-groups)))
|
||||
|
||||
(testing ":save-contact-group-order event"
|
||||
|
||||
@ -432,7 +424,7 @@
|
||||
(rf/dispatch [:change-contact-group-order 1 0])
|
||||
(rf/dispatch [:save-contact-group-order])
|
||||
|
||||
(is (= groups-with-new-group'' @contact-groups)))
|
||||
(is (= groups-with-new-group2 @contact-groups)))
|
||||
|
||||
(testing ":add-selected-contacts-to-group event"
|
||||
|
||||
@ -440,7 +432,7 @@
|
||||
(rf/dispatch [:add-selected-contacts-to-group])
|
||||
(rf/dispatch [:deselect-contact "browse"])
|
||||
|
||||
(is (= (update groups-with-new-group'' new-group-id assoc :contacts [{:identity new-contact-public-key}
|
||||
(is (= (update groups-with-new-group2 new-group-id assoc :contacts [{:identity new-contact-public-key}
|
||||
{:identity "demo-bot"}
|
||||
{:identity "browse"}])
|
||||
@contact-groups)))
|
||||
@ -449,14 +441,14 @@
|
||||
|
||||
(rf/dispatch [:remove-contact-from-group "browse" new-group-id])
|
||||
|
||||
(is (= groups-with-new-group'' @contact-groups)))
|
||||
(is (= groups-with-new-group2 @contact-groups)))
|
||||
|
||||
|
||||
(testing ":add-contacts-to-group event"
|
||||
|
||||
(rf/dispatch [:add-contacts-to-group new-group-id ["browse"]])
|
||||
|
||||
(is (= (update groups-with-new-group'' new-group-id assoc :contacts [{:identity new-contact-public-key}
|
||||
(is (= (update groups-with-new-group2 new-group-id assoc :contacts [{:identity new-contact-public-key}
|
||||
{:identity "demo-bot"}
|
||||
{:identity "browse"}])
|
||||
@contact-groups))
|
||||
@ -467,5 +459,5 @@
|
||||
|
||||
(rf/dispatch [:delete-contact-group])
|
||||
|
||||
(is (= (update groups-with-new-group'' new-group-id assoc :pending? true)
|
||||
@contact-groups))))))))))))))))
|
||||
(is (= (update groups-with-new-group2 new-group-id assoc :pending? true)
|
||||
@contact-groups)))))
|
||||
|
Loading…
x
Reference in New Issue
Block a user