fix(profile)_: Fallback to name when display name is not present

This commit is contained in:
Icaro Motta 2024-06-10 07:18:55 -03:00 committed by Siddarth Kumar
parent 686f6bdf5e
commit c439d48d05
No known key found for this signature in database
GPG Key ID: 599D10112BF518DB
4 changed files with 56 additions and 2 deletions

View File

@ -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]}]

View File

@ -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"}))

View File

@ -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)]))

View File

@ -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"])))))