From ef180796d56d3be000bc87eed9f30640fe550466 Mon Sep 17 00:00:00 2001 From: Omar Basem Date: Mon, 6 May 2024 13:02:40 +0400 Subject: [PATCH] lint --- src/status_im/subs/wallet/activities.cljs | 12 +++---- .../subs/wallet/activities_test.cljs | 33 +++++++++++++++++++ 2 files changed, 39 insertions(+), 6 deletions(-) create mode 100644 src/status_im/subs/wallet/activities_test.cljs diff --git a/src/status_im/subs/wallet/activities.cljs b/src/status_im/subs/wallet/activities.cljs index bf5707e4c73e..4261d17977c8 100644 --- a/src/status_im/subs/wallet/activities.cljs +++ b/src/status_im/subs/wallet/activities.cljs @@ -14,10 +14,10 @@ :<- [:wallet/current-viewing-account-address] (fn [[activities current-viewing-account-address]] (let [account-activities (filter (fn [{:keys [sender recipient]}] - (or (= sender current-viewing-account-address) - (= recipient current-viewing-account-address))) - activities) - grouped-by-day (group-by (fn [{:keys [timestamp]}] - (datetime/timestamp->relative-short-date (* timestamp 1000))) - account-activities)] + (or (= sender current-viewing-account-address) + (= recipient current-viewing-account-address))) + activities) + grouped-by-day (group-by (fn [{:keys [timestamp]}] + (datetime/timestamp->relative-short-date (* timestamp 1000))) + account-activities)] (map (fn [[date acts]] {:title date :data acts}) grouped-by-day)))) diff --git a/src/status_im/subs/wallet/activities_test.cljs b/src/status_im/subs/wallet/activities_test.cljs new file mode 100644 index 000000000000..c9ec11d8a62a --- /dev/null +++ b/src/status_im/subs/wallet/activities_test.cljs @@ -0,0 +1,33 @@ +(ns status-im.subs.wallet.activities-test + (:require + [cljs.test :refer [is testing]] + [re-frame.db :as rf-db] + status-im.subs.root + status-im.subs.wallet.collectibles + [test-helpers.unit :as h] + [utils.re-frame :as rf])) + +(h/deftest-sub :wallet/all-activities + [sub-name] + (testing "It should correctly return the activities list from wallet data" + (swap! rf-db/app-db assoc-in + [:wallet :activities] + [{:id 1 :name "Transaction1"} + {:id 2 :name "Transaction2"}]) + (let [result (rf/sub [sub-name])] + (is (= [{:id 1 :name "Transaction1"} {:id 2 :name "Transaction2"}] @result))))) + +(h/deftest-sub :wallet/activities-for-current-viewing-account + [sub-name] + (testing "Activities should be filtered and grouped by account and dates" + (swap! rf-db/app-db assoc + {:wallet/all-activities [{:sender "acc1" :recipient "acc2" :timestamp 1588291200} + {:sender "acc2" :recipient "acc1" :timestamp 1588377600}] + :wallet/current-viewing-account-address "acc1"}) + (let [result (rf/sub [sub-name])] + (is (= [{:title "May 1" :data [{:sender "acc1" :recipient "acc2" :timestamp 1588291200}]} + {:title "May 2" :data [{:sender "acc2" :recipient "acc1" :timestamp 1588377600}]}] + @result))))) + + +