Skip to content

Commit

Permalink
chore(schema): for user-avatar component
Browse files Browse the repository at this point in the history
Signed-off-by: yqrashawn <namy.19@gmail.com>
  • Loading branch information
yqrashawn committed Feb 22, 2024
1 parent 3c12ac8 commit 6cff16d
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 32 deletions.
6 changes: 3 additions & 3 deletions src/quo/components/avatars/user_avatar/component_spec.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
[quo.components.avatars.user-avatar.view :as user-avatar]
[test-helpers.component :as h]))

(defonce mock-picture {:uri (js/require "../resources/images/mock2/user_picture_male4.png")})
(defonce mock-picture 1)

(h/describe "user avatar"
(h/describe "Profile picture"
(h/test "Renders"
(h/render
(h/render-with-theme-provider
[user-avatar/user-avatar {:profile-picture mock-picture}])
(h/is-truthy (h/get-by-label-text :profile-picture)))

(h/test "Renders even if `:full-name` is passed"
(h/render
(h/render-with-theme-provider
[user-avatar/user-avatar {:profile-picture mock-picture}])
(h/is-truthy (h/get-by-label-text :profile-picture)))))
24 changes: 24 additions & 0 deletions src/quo/components/avatars/user_avatar/schema.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
(ns quo.components.avatars.user-avatar.schema
(:require
[quo.components.avatars.user-avatar.style :as style]))

(def ?schema
[:=>
[:catn
[:props
[:map
[:full-name {:optional true} [:maybe string?]]
[:size {:optional true} [:maybe (into [:enum] (keys style/sizes))]]
[:customization-color {:optional true} [:maybe :schema.common/customization-color]]
[:static? {:optional true} [:maybe boolean?]]
[:status-indicator? {:optional true} [:maybe boolean?]]
[:online? {:optional true} [:maybe boolean?]]
[:ring? {:optional true} [:maybe boolean?]]
[:theme :schema.common/theme]
[:profile-picture
{:optional true}
[:maybe
[:or
:schema.common/image-source
[:map [:fn fn?]]]]]]]]
:any])
8 changes: 6 additions & 2 deletions src/quo/components/avatars/user_avatar/view.cljs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
(ns quo.components.avatars.user-avatar.view
(:require
[quo.components.avatars.user-avatar.schema :as component-schema]
[quo.components.avatars.user-avatar.style :as style]
[quo.components.common.no-flicker-image :as no-flicker-image]
[quo.components.markdown.text :as text]
[quo.theme]
[react-native.core :as rn]
[react-native.fast-image :as fast-image]
[schema.core :as schema]
utils.string))

(defn initials-avatar
Expand Down Expand Up @@ -58,7 +60,7 @@
customization-color :blue}
:as props}]
(let [full-name (or full-name "Your Name")
;; image generated with profile-picture-fn is round cropped
;; image generated with `profile-picture-fn` is round cropped
;; no need to add border-radius for them
outer-styles (style/outer size (not (:fn profile-picture)))
;; Once image is loaded, fast image re-renders view with the help of reagent atom,
Expand Down Expand Up @@ -108,4 +110,6 @@

:else {:uri profile-picture})}])]))

(def user-avatar (quo.theme/with-theme user-avatar-internal))
(def user-avatar
(quo.theme/with-theme
(schema/instrument #'user-avatar-internal component-schema/?schema)))
7 changes: 4 additions & 3 deletions src/quo/components/inputs/profile_input/component_spec.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
(h/describe "Profile Input"
(h/test "on press event fires"
(let [event (h/mock-fn)]
(h/render [profile-input/profile-input
{:placeholder "Your Name"
:on-press event}])
(h/render-with-theme-provider
[profile-input/profile-input
{:placeholder "Your Name"
:on-press event}])
(h/fire-event :press (h/get-by-label-text :select-profile-picture-button))
(h/was-called-times event 1))))
Original file line number Diff line number Diff line change
Expand Up @@ -12,43 +12,44 @@

(h/describe "List items: saved contact address"
(h/test "default render"
(h/render [saved-contact-address/view])
(h/render-with-theme-provider [saved-contact-address/view])
(h/is-truthy (h/query-by-label-text :container)))

(h/test "renders account detail when passing one account"
(h/render [saved-contact-address/view {:accounts (repeat 1 account)}])
(h/render-with-theme-provider [saved-contact-address/view {:accounts (repeat 1 account)}])
(h/is-truthy (h/query-by-label-text :account-container)))

(h/test "renders account count when passing multiple accounts"
(h/render [saved-contact-address/view {:accounts (repeat 2 account)}])
(h/render-with-theme-provider [saved-contact-address/view {:accounts (repeat 2 account)}])
(h/is-truthy (h/query-by-label-text :accounts-count)))

(h/test "on-press-in changes state to :pressed"
(h/render [saved-contact-address/view {:accounts (repeat 1 account)}])
(h/render-with-theme-provider [saved-contact-address/view {:accounts (repeat 1 account)}])
(h/fire-event :on-press-in (h/get-by-label-text :container))
(h/wait-for #(h/has-style (h/query-by-label-text :container)
{:backgroundColor (colors/custom-color :blue 50 5)})))

(h/test "on-press-out changes state to :active if active-state? is true (default value)"
(h/render [saved-contact-address/view {:accounts (repeat 1 account)}])
(h/render-with-theme-provider [saved-contact-address/view {:accounts (repeat 1 account)}])
(h/fire-event :on-press-in (h/get-by-label-text :container))
(h/fire-event :on-press-out (h/get-by-label-text :container))
(h/wait-for #(h/has-style (h/query-by-label-text :container)
{:backgroundColor (colors/custom-color :blue 50 10)})))

(h/test "on-press-out changes state to :default if active-state? is false"
(h/render [saved-contact-address/view
{:accounts (repeat 1 account)
:active-state? false}])
(h/render-with-theme-provider [saved-contact-address/view
{:accounts (repeat 1 account)
:active-state? false}])
(h/fire-event :on-press-in (h/get-by-label-text :container))
(h/fire-event :on-press-out (h/get-by-label-text :container))
(h/wait-for #(h/has-style (h/query-by-label-text :container)
{:backgroundColor :transparent})))

(h/test "on-press calls on-press"
(let [on-press (h/mock-fn)]
(h/render [saved-contact-address/view
{:on-press on-press
:accounts (repeat 1 account)}])
(h/render-with-theme-provider
[saved-contact-address/view
{:on-press on-press
:accounts (repeat 1 account)}])
(h/fire-event :on-press (h/get-by-label-text :container))
(h/was-called on-press))))
13 changes: 7 additions & 6 deletions src/quo/components/navigation/top_nav/component_spec.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

(h/describe "Top Nav component"
(h/test "Renders default"
(h/render [top-nav/view])
(h/render-with-theme-provider [top-nav/view])
(h/is-truthy (h/get-by-label-text :open-scanner-button))
(h/is-truthy (h/get-by-label-text :open-activity-center-button))
(h/is-truthy (h/get-by-label-text :show-qr-button))
Expand All @@ -17,11 +17,12 @@
activity-center-on-press (h/mock-fn)
qr-code-on-press (h/mock-fn)]

(h/render [top-nav/view
{:avatar-on-press avatar-on-press
:scan-on-press scan-on-press
:activity-center-on-press activity-center-on-press
:qr-code-on-press qr-code-on-press}])
(h/render-with-theme-provider
[top-nav/view
{:avatar-on-press avatar-on-press
:scan-on-press scan-on-press
:activity-center-on-press activity-center-on-press
:qr-code-on-press qr-code-on-press}])

(h/fire-event :press (h/get-by-label-text :open-scanner-button))
(h/was-called scan-on-press)
Expand Down
4 changes: 2 additions & 2 deletions src/quo/components/profile/select_profile/component_spec.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@

(h/describe "select-profile component"
(h/test "render component"
(h/render [select-profile/view])
(h/render-with-theme-provider [select-profile/view])
(-> (h/expect (h/get-by-label-text :select-profile))
(.toBeTruthy)))
(h/test "call on-change handler when clicked"
(let [on-change (h/mock-fn)]
(h/render [select-profile/view {:on-change on-change}])
(h/render-with-theme-provider [select-profile/view {:on-change on-change}])
(h/fire-event :on-press (h/get-by-label-text :select-profile))
(-> (h/expect on-change)
(.toHaveBeenCalledTimes 1)))))
Expand Down
11 changes: 6 additions & 5 deletions src/quo/components/tags/summary_tag/component_spec.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,12 @@
(h/is-truthy (h/get-by-text "Rare Artifact")))

(h/test "User view render"
(h/render [summary-tag/view
{:type :user
:label "Bob Smith"
:image-source "path/to/profile-pic.png"
:customization-color "#0000ff"}])
(h/render-with-theme-provider
[summary-tag/view
{:type :user
:label "Bob Smith"
:image-source "path/to/profile-pic.png"
:customization-color "#0000ff"}])
(h/is-truthy (h/get-by-text "Bob Smith")))

(h/test "Token view render"
Expand Down

0 comments on commit 6cff16d

Please sign in to comment.