From f6e26fc3a62a8756533ef4699d5667d4b181d5d0 Mon Sep 17 00:00:00 2001 From: Icaro Motta Date: Mon, 10 Jun 2024 07:18:55 -0300 Subject: [PATCH] fix(profile)_: Fallback to name when display name is not present --- src/status_im/contexts/profile/utils.cljs | 2 +- .../contexts/profile/utils_test.cljs | 19 +++++++++++ src/status_im/subs/contact.cljs | 3 +- src/status_im/subs/contact_test.cljs | 34 +++++++++++++++++++ 4 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 src/status_im/contexts/profile/utils_test.cljs diff --git a/src/status_im/contexts/profile/utils.cljs b/src/status_im/contexts/profile/utils.cljs index f8ca89994d..d687402ef8 100644 --- a/src/status_im/contexts/profile/utils.cljs +++ b/src/status_im/contexts/profile/utils.cljs @@ -13,7 +13,7 @@ name)] (if (or preferred-name (and ens-verified name)) ens-name - (or display-name primary-name alias)))) + (or display-name primary-name alias name)))) (defn photo [{:keys [images]}] diff --git a/src/status_im/contexts/profile/utils_test.cljs b/src/status_im/contexts/profile/utils_test.cljs new file mode 100644 index 0000000000..b13151a292 --- /dev/null +++ b/src/status_im/contexts/profile/utils_test.cljs @@ -0,0 +1,19 @@ +(ns status-im.contexts.profile.utils-test + (:require + [cljs.test :refer [are deftest]] + [status-im.contexts.profile.utils :as sut])) + +(deftest displayed-name-test + (are [expected arg] (= expected (sut/displayed-name arg)) + "Display Name" {:display-name "Display Name"} + "Primary Name" {:primary-name "Primary Name"} + "Alias" {:alias "Alias"} + "Name" {:name "Name"} + nil {:preferred-name " "} + "Preferred Name" {:preferred-name "Preferred Name"} + "Preferred Name" {:preferred-name "Preferred Name" :display-name "Display Name"} + "Preferred Name" {:preferred-name "Preferred Name" :display-name "Display Name" :name "Name"} + "Display Name" {:ens-verified true :name "Name" :display-name "Display Name"} + "Name" {:ens-verified true :name "Name" :display-name " "} + "Name" {:ens-verified true :name "Name"} + "Name" {:name "Name"})) diff --git a/src/status_im/subs/contact.cljs b/src/status_im/subs/contact.cljs index 20fd37b36d..1a866e1b0f 100644 --- a/src/status_im/subs/contact.cljs +++ b/src/status_im/subs/contact.cljs @@ -258,13 +258,14 @@ [(re-frame/subscribe [:contacts/contact-by-identity contact-identity]) (re-frame/subscribe [:profile/profile])]) (fn [[{:keys [primary-name] :as contact} - {:keys [public-key preferred-name display-name]}] + {:keys [public-key preferred-name display-name name]}] [_ contact-identity]] [(if (= public-key contact-identity) (cond (not (string/blank? preferred-name)) preferred-name (not (string/blank? display-name)) display-name (not (string/blank? primary-name)) primary-name + (not (string/blank? name)) name :else public-key) (profile.utils/displayed-name contact)) (:secondary-name contact)])) diff --git a/src/status_im/subs/contact_test.cljs b/src/status_im/subs/contact_test.cljs index 55a5fbb3e9..f0111ba253 100644 --- a/src/status_im/subs/contact_test.cljs +++ b/src/status_im/subs/contact_test.cljs @@ -174,3 +174,37 @@ (rf/sub [sub-name]))] (is (= expected-sorted-contacts-without-images (mapv remove-contact-images contact-list-without-identicons)))))) + +(h/deftest-sub :contacts/contact-two-names-by-identity + [sub-name] + (testing "contact is current profile" + (let [profile-key "profile-key"] + (swap! rf-db/app-db assoc + :profile/profile + {:public-key profile-key + :display-name "Display Name" + :name "Name" + :preferred-name "Preferred Name"} + + :contacts/contacts + {profile-key {:primary-name "Primary Name"} + "contact-key" {:secondary-name "Secondary Name"}}) + + (is (= ["Preferred Name" nil] (rf/sub [sub-name profile-key]))) + + (swap! rf-db/app-db update :profile/profile dissoc :preferred-name) + (is (= ["Display Name" nil] (rf/sub [sub-name profile-key]))) + + (swap! rf-db/app-db update :profile/profile dissoc :display-name) + (is (= ["Primary Name" nil] (rf/sub [sub-name profile-key]))) + + (swap! rf-db/app-db update-in [:contacts/contacts profile-key] dissoc :primary-name) + (is (= ["Name" nil] (rf/sub [sub-name profile-key]))))) + + (testing "contact is not current profile" + (swap! rf-db/app-db assoc + :profile/profile {:public-key "profile-key"} + :contacts/contacts {"contact-key" {:preferred-name "Preferred Name" + :secondary-name "Secondary Name"}}) + + (is (= ["Preferred Name" "Secondary Name"] (rf/sub [sub-name "contact-key"])))))