-
Notifications
You must be signed in to change notification settings - Fork 984
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
234 additions
and
76 deletions.
There are no files selected for viewing
147 changes: 116 additions & 31 deletions
147
src/quo/components/share/share_qr_code/component_spec.cljs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,119 @@ | ||
(ns quo.components.share.share-qr-code.component-spec | ||
(:require | ||
[quo.components.share.share-qr-code.view :as share-qr-code] | ||
[test-helpers.component :as h])) | ||
(:require [quo.components.share.share-qr-code.view :as share-qr-code] | ||
[test-helpers.component :as h])) | ||
|
||
(defn render-share-qr-code | ||
[{share-qr-type :type :as props}] | ||
(let [component-rendered (h/render [share-qr-code/view {:type share-qr-type}]) | ||
rerender-fn (h/get-rerender-fn component-rendered) | ||
share-qr-code (h/get-by-label-text :share-qr-code)] | ||
;; Fires on-layout since it's needed to render the content | ||
(h/fire-event :layout share-qr-code #js {:nativeEvent #js {:layout #js {:width 500}}}) | ||
(rerender-fn [share-qr-code/view props]))) | ||
|
||
(h/describe "Share QR Code component" | ||
(h/test "renders share qr code component" | ||
(h/render [share-qr-code/view | ||
{:link-title " A test title"}]) | ||
(-> (js/expect (h/get-by-text "A test title")) | ||
(.toBeTruthy))) | ||
|
||
(h/test "renders share qr code url" | ||
(h/render [share-qr-code/view | ||
{:qr-url " A test url"}]) | ||
(-> (js/expect (h/get-by-text "A test url")) | ||
(.toBeTruthy))) | ||
|
||
(h/test "on press link event fires" | ||
(let [event (h/mock-fn)] | ||
(h/render [share-qr-code/view | ||
{:url-on-press event | ||
:qr-url " A test url"}]) | ||
(h/fire-event :press (h/get-by-text "A test url")) | ||
(-> (js/expect event) | ||
(.toHaveBeenCalledTimes 1)))) | ||
|
||
(h/test "on press share event fires" | ||
(let [event (h/mock-fn)] | ||
(h/render [share-qr-code/view | ||
{:share-on-press event}]) | ||
(h/fire-event :press (h/get-by-label-text :share-profile)) | ||
(-> (js/expect event) | ||
(.toHaveBeenCalledTimes 1))))) | ||
(h/describe "Renders share-qr-code component in all types" | ||
(let [qr-label "Text shown below QR"] | ||
(h/test "Profile" | ||
(render-share-qr-code {:type :profile | ||
:qr-data qr-label}) | ||
(h/is-truthy (h/get-by-text qr-label))) | ||
|
||
(h/test "Wallet Legacy" | ||
(render-share-qr-code {:type :wallet-legacy | ||
:qr-data qr-label | ||
:emoji "👻"}) | ||
(h/is-truthy (h/get-by-text qr-label))) | ||
|
||
(h/test "Wallet Multichain" | ||
(render-share-qr-code {:type :wallet-multichain | ||
:qr-data qr-label | ||
:emoji "👻"}) | ||
(h/is-truthy (h/get-by-text qr-label))))) | ||
|
||
(h/describe "Fires all events for all types" | ||
(letfn [(test-fire-events [props test-seq] | ||
(doseq [{:keys [test-name event-name | ||
callback-prop-key | ||
accessibility-label]} test-seq | ||
:let [event-fn (h/mock-fn)]] | ||
(h/test test-name | ||
(render-share-qr-code (assoc props callback-prop-key event-fn)) | ||
(h/fire-event event-name (h/get-by-label-text accessibility-label)) | ||
(h/was-called-times event-fn 1))))] | ||
|
||
(h/describe "Profile" | ||
(test-fire-events | ||
{:type :profile} | ||
[{:test-name "Text pressed" | ||
:accessibility-label :share-qr-code-info-text | ||
:event-name :press | ||
:callback-prop-key :on-text-press} | ||
{:test-name "Text long pressed" | ||
:accessibility-label :share-qr-code-info-text | ||
:event-name :long-press | ||
:callback-prop-key :on-text-long-press} | ||
{:test-name "Share button" | ||
:accessibility-label :link-to-profile | ||
:event-name :press | ||
:callback-prop-key :on-share-press}])) | ||
|
||
(h/describe "Wallet Legacy" | ||
(test-fire-events | ||
{:type :wallet-legacy :emoji "👽"} | ||
[{:test-name "Text pressed" | ||
:accessibility-label :share-qr-code-info-text | ||
:event-name :press | ||
:callback-prop-key :on-text-press} | ||
{:test-name "Text long pressed" | ||
:accessibility-label :share-qr-code-info-text | ||
:event-name :long-press | ||
:callback-prop-key :on-text-long-press} | ||
{:test-name "Share button pressed" | ||
:accessibility-label :link-to-profile | ||
:event-name :press | ||
:callback-prop-key :on-share-press} | ||
{:test-name "Info icon pressed" | ||
:accessibility-label :share-qr-code-info-icon | ||
:event-name :press | ||
:callback-prop-key :on-info-press} | ||
{:test-name "Legacy tab pressed" | ||
:accessibility-label :share-qr-code-legacy-tab | ||
:event-name :press | ||
:callback-prop-key :on-legacy-press} | ||
{:test-name "Multichain tab pressed" | ||
:accessibility-label :share-qr-code-multichain-tab | ||
:event-name :press | ||
:callback-prop-key :on-multichain-press}])) | ||
|
||
(h/describe "Wallet Multichain" | ||
(test-fire-events | ||
{:type :wallet-multichain :emoji "👽"} | ||
[{:test-name "Text pressed" | ||
:accessibility-label :share-qr-code-info-text | ||
:event-name :press | ||
:callback-prop-key :on-text-press} | ||
{:test-name "Text long pressed" | ||
:accessibility-label :share-qr-code-info-text | ||
:event-name :long-press | ||
:callback-prop-key :on-text-long-press} | ||
{:test-name "Share button pressed" | ||
:accessibility-label :link-to-profile | ||
:event-name :press | ||
:callback-prop-key :on-share-press} | ||
{:test-name "Info icon pressed" | ||
:accessibility-label :share-qr-code-info-icon | ||
:event-name :press | ||
:callback-prop-key :on-info-press} | ||
{:test-name "Legacy tab pressed" | ||
:accessibility-label :share-qr-code-legacy-tab | ||
:event-name :press | ||
:callback-prop-key :on-legacy-press} | ||
{:test-name "Multichain tab pressed" | ||
:accessibility-label :share-qr-code-multichain-tab | ||
:event-name :press | ||
:callback-prop-key :on-multichain-press} | ||
{:test-name "Settings pressed" | ||
:accessibility-label :share-qr-code-settings | ||
:event-name :press | ||
:callback-prop-key :on-settings-press}]))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.