@@ -3,8 +3,6 @@ import { fireEvent, render, screen } from '@testing-library/react';
3
3
import type { ReactNode } from 'react' ;
4
4
import { beforeEach , describe , expect , it , vi } from 'vitest' ;
5
5
import { useAccount , useConnect } from 'wagmi' ;
6
- import { useAnalytics } from '../../core/analytics/hooks/useAnalytics' ;
7
- import { WalletEvent } from '../../core/analytics/types' ;
8
6
import { useOnchainKit } from '../../useOnchainKit' ;
9
7
import { ConnectWallet } from './ConnectWallet' ;
10
8
import { ConnectWalletText } from './ConnectWalletText' ;
@@ -45,13 +43,7 @@ vi.mock('@/useOnchainKit', () => ({
45
43
useOnchainKit : vi . fn ( ) ,
46
44
} ) ) ;
47
45
48
- vi . mock ( '../../core/analytics/hooks/useAnalytics' , ( ) => ( {
49
- useAnalytics : vi . fn ( ) ,
50
- } ) ) ;
51
-
52
46
describe ( 'ConnectWallet' , ( ) => {
53
- const mockSendAnalytics = vi . fn ( ) ;
54
-
55
47
beforeEach ( ( ) => {
56
48
Object . defineProperty ( window , 'matchMedia' , {
57
49
writable : true ,
@@ -84,9 +76,6 @@ describe('ConnectWallet', () => {
84
76
vi . mocked ( useOnchainKit ) . mockReturnValue ( {
85
77
config : { wallet : { display : undefined } } ,
86
78
} ) ;
87
- vi . mocked ( useAnalytics ) . mockReturnValue ( {
88
- sendAnalytics : mockSendAnalytics ,
89
- } ) ;
90
79
} ) ;
91
80
92
81
it ( 'should render connect button when disconnected' , ( ) => {
@@ -127,54 +116,22 @@ describe('ConnectWallet', () => {
127
116
128
117
it ( 'should call connect function when connect button is clicked' , ( ) => {
129
118
const connectMock = vi . fn ( ) ;
130
- const mockSendAnalytics = vi . fn ( ) ;
131
-
132
119
vi . mocked ( useConnect ) . mockReturnValue ( {
133
- connectors : [ { name : 'TestConnector' , id : 'mockConnector' } ] ,
120
+ connectors : [ { id : 'mockConnector' } ] ,
134
121
connect : connectMock ,
135
122
status : 'idle' ,
136
123
} ) ;
137
-
138
- vi . mocked ( useAnalytics ) . mockReturnValue ( {
139
- sendAnalytics : mockSendAnalytics ,
140
- } ) ;
141
-
142
124
render ( < ConnectWallet text = "Connect Wallet" /> ) ;
143
-
144
125
const button = screen . getByTestId ( 'ockConnectButton' ) ;
145
126
fireEvent . click ( button ) ;
146
-
147
- expect ( mockSendAnalytics ) . toHaveBeenCalledWith (
148
- WalletEvent . ConnectInitiated ,
127
+ expect ( connectMock ) . toHaveBeenCalledWith (
149
128
{
150
- component : 'ConnectWallet' ,
151
- walletProvider : 'TestConnector' ,
129
+ connector : { id : 'mockConnector' } ,
152
130
} ,
153
- ) ;
154
-
155
- expect ( connectMock ) . toHaveBeenCalledWith (
156
- { connector : { name : 'TestConnector' , id : 'mockConnector' } } ,
157
131
{
158
132
onSuccess : expect . any ( Function ) ,
159
- onError : expect . any ( Function ) ,
160
133
} ,
161
134
) ;
162
-
163
- connectMock . mock . calls [ 0 ] [ 1 ] . onSuccess ( ) ;
164
- expect ( mockSendAnalytics ) . toHaveBeenCalledWith ( WalletEvent . ConnectSuccess , {
165
- address : '' ,
166
- walletProvider : 'TestConnector' ,
167
- } ) ;
168
-
169
- const error = new Error ( 'Test error' ) ;
170
- connectMock . mock . calls [ 0 ] [ 1 ] . onError ( error ) ;
171
- expect ( mockSendAnalytics ) . toHaveBeenCalledWith ( WalletEvent . ConnectError , {
172
- error : 'Test error' ,
173
- metadata : {
174
- connector : 'TestConnector' ,
175
- component : 'ConnectWallet' ,
176
- } ,
177
- } ) ;
178
135
} ) ;
179
136
180
137
it ( 'should toggle wallet modal on button click when connected' , ( ) => {
@@ -344,10 +301,7 @@ describe('ConnectWallet', () => {
344
301
345
302
expect ( connectMock ) . toHaveBeenCalledWith (
346
303
{ connector : { id : 'mockConnector' } } ,
347
- {
348
- onSuccess : expect . any ( Function ) ,
349
- onError : expect . any ( Function ) ,
350
- } ,
304
+ { onSuccess : expect . any ( Function ) } ,
351
305
) ;
352
306
} ) ;
353
307
} ) ;
@@ -391,10 +345,7 @@ describe('ConnectWallet', () => {
391
345
392
346
expect ( connectMock ) . toHaveBeenCalledWith (
393
347
{ connector : { id : 'mockConnector' } } ,
394
- {
395
- onSuccess : expect . any ( Function ) ,
396
- onError : expect . any ( Function ) ,
397
- } ,
348
+ { onSuccess : expect . any ( Function ) } ,
398
349
) ;
399
350
400
351
connectMock . mock . calls [ 0 ] [ 1 ] . onSuccess ( ) ;
@@ -592,125 +543,4 @@ describe('ConnectWallet', () => {
592
543
expect ( onConnectMock ) . toHaveBeenCalledTimes ( 1 ) ;
593
544
} ) ;
594
545
} ) ;
595
-
596
- describe ( 'analytics' , ( ) => {
597
- it ( 'should send analytics when connect button is clicked in modal mode' , ( ) => {
598
- vi . mocked ( useOnchainKit ) . mockReturnValue ( {
599
- config : { wallet : { display : 'modal' } } ,
600
- } ) ;
601
-
602
- vi . mocked ( useConnect ) . mockReturnValue ( {
603
- connectors : [ { name : 'TestConnector' , id : 'mockConnector' } ] ,
604
- connect : vi . fn ( ) ,
605
- status : 'idle' ,
606
- } ) ;
607
-
608
- render ( < ConnectWallet text = "Connect Wallet" /> ) ;
609
-
610
- const button = screen . getByTestId ( 'ockConnectButton' ) ;
611
- fireEvent . click ( button ) ;
612
-
613
- expect ( mockSendAnalytics ) . toHaveBeenCalledWith (
614
- WalletEvent . ConnectInitiated ,
615
- {
616
- component : 'ConnectWallet' ,
617
- walletProvider : 'TestConnector' ,
618
- } ,
619
- ) ;
620
- } ) ;
621
-
622
- it ( 'should send analytics when direct connect is initiated' , ( ) => {
623
- const connectMock = vi . fn ( ) ;
624
- vi . mocked ( useConnect ) . mockReturnValue ( {
625
- connectors : [ { name : 'TestConnector' , id : 'mockConnector' } ] ,
626
- connect : connectMock ,
627
- status : 'idle' ,
628
- } ) ;
629
-
630
- render ( < ConnectWallet text = "Connect Wallet" /> ) ;
631
-
632
- const button = screen . getByTestId ( 'ockConnectButton' ) ;
633
- fireEvent . click ( button ) ;
634
-
635
- expect ( mockSendAnalytics ) . toHaveBeenCalledWith (
636
- WalletEvent . ConnectInitiated ,
637
- {
638
- component : 'ConnectWallet' ,
639
- walletProvider : 'TestConnector' ,
640
- } ,
641
- ) ;
642
- } ) ;
643
-
644
- it ( 'should send analytics on successful connection' , ( ) => {
645
- const connectMock = vi . fn ( ) ;
646
- vi . mocked ( useConnect ) . mockReturnValue ( {
647
- connectors : [ { name : 'TestConnector' , id : 'mockConnector' } ] ,
648
- connect : connectMock ,
649
- status : 'idle' ,
650
- } ) ;
651
-
652
- render ( < ConnectWallet text = "Connect Wallet" /> ) ;
653
-
654
- const button = screen . getByTestId ( 'ockConnectButton' ) ;
655
- fireEvent . click ( button ) ;
656
-
657
- connectMock . mock . calls [ 0 ] [ 1 ] . onSuccess ( ) ;
658
-
659
- expect ( mockSendAnalytics ) . toHaveBeenCalledWith (
660
- WalletEvent . ConnectSuccess ,
661
- {
662
- address : '' ,
663
- walletProvider : 'TestConnector' ,
664
- } ,
665
- ) ;
666
- } ) ;
667
-
668
- it ( 'should send analytics on connection error' , ( ) => {
669
- const connectMock = vi . fn ( ) ;
670
- vi . mocked ( useConnect ) . mockReturnValue ( {
671
- connectors : [ { name : 'TestConnector' , id : 'mockConnector' } ] ,
672
- connect : connectMock ,
673
- status : 'idle' ,
674
- } ) ;
675
-
676
- render ( < ConnectWallet text = "Connect Wallet" /> ) ;
677
-
678
- const button = screen . getByTestId ( 'ockConnectButton' ) ;
679
- fireEvent . click ( button ) ;
680
-
681
- connectMock . mock . calls [ 0 ] [ 1 ] . onError ( new Error ( 'Test error' ) ) ;
682
-
683
- expect ( mockSendAnalytics ) . toHaveBeenCalledWith ( WalletEvent . ConnectError , {
684
- error : 'Test error' ,
685
- metadata : {
686
- connector : 'TestConnector' ,
687
- component : 'ConnectWallet' ,
688
- } ,
689
- } ) ;
690
- } ) ;
691
-
692
- it ( 'should send analytics when account is connected with address' , ( ) => {
693
- const mockUseAccount = vi . mocked ( useAccount ) ;
694
- vi . mocked ( useConnect ) . mockReturnValue ( {
695
- connectors : [ { name : 'TestConnector' , id : 'mockConnector' } ] ,
696
- connect : vi . fn ( ) ,
697
- status : 'idle' ,
698
- } ) ;
699
-
700
- mockUseAccount . mockReturnValue ( {
701
- address : '0x123' ,
702
- status : 'connected' ,
703
- } ) ;
704
-
705
- render ( < ConnectWallet text = "Connect Wallet" /> ) ;
706
-
707
- expect ( mockSendAnalytics ) . toHaveBeenCalledWith (
708
- WalletEvent . ConnectSuccess ,
709
- {
710
- address : '0x123' ,
711
- walletProvider : 'TestConnector' ,
712
- } ,
713
- ) ;
714
- } ) ;
715
- } ) ;
716
546
} ) ;
0 commit comments