@@ -6,9 +6,16 @@ import CardWelcome from './CardWelcome';
66import { CardWelcomeSelectors } from '../../../../../../e2e/selectors/Card/CardWelcome.selectors' ;
77import { strings } from '../../../../../../locales/i18n' ;
88import Routes from '../../../../../constants/navigation/Routes' ;
9+ import { MetaMetricsEvents } from '../../../../hooks/useMetrics' ;
910
1011// Mocks
1112const mockNavigate = jest . fn ( ) ;
13+ const mockTrackEvent = jest . fn ( ) ;
14+ const mockBuild = jest . fn ( ) ;
15+ const mockAddProperties = jest . fn ( ( ) => ( { build : mockBuild } ) ) ;
16+ const mockCreateEventBuilder = jest . fn ( ( ) => ( {
17+ addProperties : mockAddProperties ,
18+ } ) ) ;
1219
1320jest . mock ( '@react-navigation/native' , ( ) => {
1421 const actual = jest . requireActual ( '@react-navigation/native' ) ;
@@ -20,25 +27,31 @@ jest.mock('@react-navigation/native', () => {
2027 } ;
2128} ) ;
2229
30+ jest . mock ( '../../../../hooks/useMetrics' , ( ) => ( {
31+ useMetrics : ( ) => ( {
32+ trackEvent : mockTrackEvent ,
33+ createEventBuilder : mockCreateEventBuilder ,
34+ } ) ,
35+ MetaMetricsEvents : {
36+ CARD_VIEWED : 'Card Viewed' ,
37+ CARD_BUTTON_CLICKED : 'Card Button Clicked' ,
38+ } ,
39+ } ) ) ;
40+
2341jest . mock ( '../../../../../../locales/i18n' , ( ) => ( {
2442 strings : ( key : string ) => {
2543 const map : Record < string , string > = {
2644 'card.card_onboarding.title' : 'Enable MetaMask Card features' ,
2745 'card.card_onboarding.description' :
2846 'Change your spending token and network by signing in with your Crypto Life email and password.' ,
29- 'card.card_onboarding.verify_account_button' : 'Sign in' ,
30- 'card.card_onboarding.non_cardholder_title' : 'Welcome to MetaMask Card' ,
31- 'card.card_onboarding.non_cardholder_description' :
32- 'MetaMask Card is the free and easy way to spend your crypto, with rich onchain rewards.' ,
33- 'card.card_onboarding.non_cardholder_verify_account_button' :
34- 'Get started' ,
35- 'card.card' : 'Card' ,
47+ 'card.card_onboarding.apply_now_button' : 'Sign in' ,
48+ 'predict.gtm_content.not_now' : 'Not now' ,
3649 } ;
3750 return map [ key ] || key ;
3851 } ,
3952} ) ) ;
4053
41- jest . mock ( '../../../../../images/metal -card.png' , ( ) => 1 ) ;
54+ jest . mock ( '../../../../../images/mm -card-welcome .png' , ( ) => 1 ) ;
4255
4356jest . mock ( '../../../../../util/theme' , ( ) => ( {
4457 useTheme : ( ) => ( { colors : { background : { default : '#fff' } } } ) ,
@@ -57,9 +70,11 @@ describe('CardWelcome', () => {
5770 beforeEach ( ( ) => {
5871 jest . clearAllMocks ( ) ;
5972 mockNavigate . mockClear ( ) ;
73+ mockTrackEvent . mockClear ( ) ;
74+ mockCreateEventBuilder . mockClear ( ) ;
6075 } ) ;
6176
62- describe ( 'Non-cardholder flow ' , ( ) => {
77+ describe ( 'Render ' , ( ) => {
6378 beforeEach ( ( ) => {
6479 store = createTestStore ( { cardholderAccounts : [ ] } ) ;
6580 } ) ;
@@ -81,9 +96,10 @@ describe('CardWelcome', () => {
8196 expect (
8297 getByTestId ( CardWelcomeSelectors . VERIFY_ACCOUNT_BUTTON ) ,
8398 ) . toBeTruthy ( ) ;
99+ expect ( getByTestId ( 'predict-gtm-not-now-button' ) ) . toBeTruthy ( ) ;
84100 } ) ;
85101
86- it ( 'displays non-cardholder title when no cardholder accounts exist ' , ( ) => {
102+ it ( 'displays correct title and description ' , ( ) => {
87103 const { getByTestId } = render (
88104 < Provider store = { store } >
89105 < CardWelcome />
@@ -92,69 +108,62 @@ describe('CardWelcome', () => {
92108
93109 expect (
94110 getByTestId ( CardWelcomeSelectors . WELCOME_TO_CARD_TITLE_TEXT ) ,
95- ) . toHaveTextContent ( strings ( 'card.card_onboarding.non_cardholder_title' ) ) ;
111+ ) . toHaveTextContent ( strings ( 'card.card_onboarding.title' ) ) ;
112+ expect (
113+ getByTestId ( CardWelcomeSelectors . WELCOME_TO_CARD_DESCRIPTION_TEXT ) ,
114+ ) . toHaveTextContent ( strings ( 'card.card_onboarding.description' ) ) ;
96115 } ) ;
97116
98- it ( 'displays non-cardholder description when no cardholder accounts exist ' , ( ) => {
99- const { getByTestId } = render (
117+ it ( 'tracks view event on mount ' , ( ) => {
118+ render (
100119 < Provider store = { store } >
101120 < CardWelcome />
102121 </ Provider > ,
103122 ) ;
104123
105- expect (
106- getByTestId ( CardWelcomeSelectors . WELCOME_TO_CARD_DESCRIPTION_TEXT ) ,
107- ) . toHaveTextContent (
108- strings ( 'card.card_onboarding.non_cardholder_description' ) ,
124+ expect ( mockCreateEventBuilder ) . toHaveBeenCalledWith (
125+ MetaMetricsEvents . CARD_VIEWED ,
109126 ) ;
127+ expect ( mockTrackEvent ) . toHaveBeenCalled ( ) ;
110128 } ) ;
129+ } ) ;
111130
112- it ( 'navigates to onboarding root when verify account button pressed' , ( ) => {
131+ describe ( 'Interactions' , ( ) => {
132+ it ( 'navigates to wallet home when "Not Now" is pressed' , ( ) => {
133+ store = createTestStore ( ) ;
113134 const { getByTestId } = render (
114135 < Provider store = { store } >
115136 < CardWelcome />
116137 </ Provider > ,
117138 ) ;
118139
119- fireEvent . press ( getByTestId ( CardWelcomeSelectors . VERIFY_ACCOUNT_BUTTON ) ) ;
140+ fireEvent . press ( getByTestId ( 'predict-gtm-not-now-button' ) ) ;
120141
121- expect ( mockNavigate ) . toHaveBeenCalledTimes ( 1 ) ;
122- expect ( mockNavigate ) . toHaveBeenCalledWith ( Routes . CARD . ONBOARDING . ROOT ) ;
142+ expect ( mockNavigate ) . toHaveBeenCalledWith ( Routes . WALLET . HOME ) ;
123143 } ) ;
124144 } ) ;
125145
126- describe ( 'Cardholder flow' , ( ) => {
127- beforeEach ( ( ) => {
128- store = createTestStore ( {
129- cardholderAccounts : [ '0x1234567890abcdef' ] ,
130- } ) ;
131- } ) ;
132-
133- it ( 'displays cardholder title when cardholder accounts exist' , ( ) => {
146+ describe ( 'Navigation Flow' , ( ) => {
147+ it ( 'navigates to onboarding root when verify account button pressed (Non-cardholder)' , ( ) => {
148+ store = createTestStore ( { cardholderAccounts : [ ] } ) ;
134149 const { getByTestId } = render (
135150 < Provider store = { store } >
136151 < CardWelcome />
137152 </ Provider > ,
138153 ) ;
139154
140- expect (
141- getByTestId ( CardWelcomeSelectors . WELCOME_TO_CARD_TITLE_TEXT ) ,
142- ) . toHaveTextContent ( strings ( 'card.card_onboarding.title' ) ) ;
143- } ) ;
155+ fireEvent . press ( getByTestId ( CardWelcomeSelectors . VERIFY_ACCOUNT_BUTTON ) ) ;
144156
145- it ( 'displays cardholder description when cardholder accounts exist' , ( ) => {
146- const { getByTestId } = render (
147- < Provider store = { store } >
148- < CardWelcome />
149- </ Provider > ,
157+ expect ( mockNavigate ) . toHaveBeenCalledWith ( Routes . CARD . ONBOARDING . ROOT ) ;
158+ expect ( mockCreateEventBuilder ) . toHaveBeenCalledWith (
159+ MetaMetricsEvents . CARD_BUTTON_CLICKED ,
150160 ) ;
151-
152- expect (
153- getByTestId ( CardWelcomeSelectors . WELCOME_TO_CARD_DESCRIPTION_TEXT ) ,
154- ) . toHaveTextContent ( strings ( 'card.card_onboarding.description' ) ) ;
155161 } ) ;
156162
157- it ( 'navigates to authentication when verify account button pressed' , ( ) => {
163+ it ( 'navigates to authentication when verify account button pressed (Cardholder)' , ( ) => {
164+ store = createTestStore ( {
165+ cardholderAccounts : [ '0x1234567890abcdef' ] ,
166+ } ) ;
158167 const { getByTestId } = render (
159168 < Provider store = { store } >
160169 < CardWelcome />
@@ -163,8 +172,10 @@ describe('CardWelcome', () => {
163172
164173 fireEvent . press ( getByTestId ( CardWelcomeSelectors . VERIFY_ACCOUNT_BUTTON ) ) ;
165174
166- expect ( mockNavigate ) . toHaveBeenCalledTimes ( 1 ) ;
167175 expect ( mockNavigate ) . toHaveBeenCalledWith ( Routes . CARD . AUTHENTICATION ) ;
176+ expect ( mockCreateEventBuilder ) . toHaveBeenCalledWith (
177+ MetaMetricsEvents . CARD_BUTTON_CLICKED ,
178+ ) ;
168179 } ) ;
169180 } ) ;
170181} ) ;
0 commit comments