1
1
import React from 'react' ;
2
2
import { screen , act , waitFor } from '@testing-library/react' ;
3
+ import configureMockStore from 'redux-mock-store' ;
4
+ import thunk from 'redux-thunk' ;
3
5
import { renderWithProvider } from '../../../../../test/jest' ;
4
- import configureStore , { MetaMaskReduxState } from '../../../../store/store' ;
6
+ import { MetaMaskReduxState } from '../../../../store/store' ;
5
7
import mockState from '../../../../../test/data/mock-state.json' ;
6
8
import { CHAIN_IDS } from '../../../../../shared/constants/network' ;
7
9
import { useIsOriginalNativeTokenSymbol } from '../../../../hooks/useIsOriginalNativeTokenSymbol' ;
10
+ import useMultiPolling from '../../../../hooks/useMultiPolling' ;
8
11
import { getTokenSymbol } from '../../../../store/actions' ;
9
12
import { getSelectedInternalAccountFromMockState } from '../../../../../test/jest/mocks' ;
10
13
import { mockNetworkState } from '../../../../../test/stub/networks' ;
@@ -64,11 +67,19 @@ jest.mock('../../../../hooks/useIsOriginalNativeTokenSymbol', () => {
64
67
jest . mock ( '../../../../store/actions' , ( ) => {
65
68
return {
66
69
getTokenSymbol : jest . fn ( ) ,
70
+ setTokenNetworkFilter : jest . fn ( ( ) => ( {
71
+ type : 'TOKEN_NETWORK_FILTER' ,
72
+ } ) ) ,
67
73
tokenBalancesStartPolling : jest . fn ( ) . mockResolvedValue ( 'pollingToken' ) ,
68
74
tokenBalancesStopPollingByPollingToken : jest . fn ( ) ,
69
75
} ;
70
76
} ) ;
71
77
78
+ jest . mock ( '../../../../hooks/useMultiPolling' , ( ) => ( {
79
+ __esModule : true ,
80
+ default : jest . fn ( ) ,
81
+ } ) ) ;
82
+
72
83
const mockSelectedInternalAccount = getSelectedInternalAccountFromMockState (
73
84
mockState as unknown as MetaMaskReduxState ,
74
85
) ;
@@ -103,14 +114,30 @@ const render = (balance = ETH_BALANCE, chainId = CHAIN_IDS.MAINNET) => {
103
114
} ,
104
115
} ,
105
116
} ;
106
- const store = configureStore ( state ) ;
117
+ const store = configureMockStore ( [ thunk ] ) ( state ) ;
107
118
return renderWithProvider (
108
119
< AssetList onClickAsset = { ( ) => undefined } showTokensLinks /> ,
109
120
store ,
110
121
) ;
111
122
} ;
112
123
113
124
describe ( 'AssetList' , ( ) => {
125
+ ( useMultiPolling as jest . Mock ) . mockClear ( ) ;
126
+
127
+ // Mock implementation for useMultiPolling
128
+ ( useMultiPolling as jest . Mock ) . mockImplementation ( ( { input } ) => {
129
+ // Mock startPolling and stopPollingByPollingToken for each input
130
+ const startPolling = jest . fn ( ) . mockResolvedValue ( 'mockPollingToken' ) ;
131
+ const stopPollingByPollingToken = jest . fn ( ) ;
132
+
133
+ input . forEach ( ( inputItem : string ) => {
134
+ const key = JSON . stringify ( inputItem ) ;
135
+ // Simulate returning a unique token for each input
136
+ startPolling . mockResolvedValueOnce ( `mockToken-${ key } ` ) ;
137
+ } ) ;
138
+
139
+ return { startPolling, stopPollingByPollingToken } ;
140
+ } ) ;
114
141
( useIsOriginalNativeTokenSymbol as jest . Mock ) . mockReturnValue ( true ) ;
115
142
116
143
( getTokenSymbol as jest . Mock ) . mockImplementation ( async ( address ) => {
@@ -126,13 +153,14 @@ describe('AssetList', () => {
126
153
return null ;
127
154
} ) ;
128
155
129
- it ( 'renders AssetList component and shows Refresh List text ' , async ( ) => {
156
+ it ( 'renders AssetList component and shows AssetList control bar ' , async ( ) => {
130
157
await act ( async ( ) => {
131
158
render ( ) ;
132
159
} ) ;
133
160
134
161
await waitFor ( ( ) => {
135
- expect ( screen . getByText ( 'Refresh list' ) ) . toBeInTheDocument ( ) ;
162
+ expect ( screen . getByTestId ( 'sort-by-popover-toggle' ) ) . toBeInTheDocument ( ) ;
163
+ expect ( screen . getByTestId ( 'import-token-button' ) ) . toBeInTheDocument ( ) ;
136
164
} ) ;
137
165
} ) ;
138
166
} ) ;
0 commit comments