3
3
/* eslint-disable sonarjs/no-identical-functions */
4
4
/* eslint-disable @typescript-eslint/no-explicit-any */
5
5
/* eslint-disable import/imports-first */
6
- const mockUseMaxAda = jest . fn ( ) ;
6
+ const mockUseHasEnoughCollateral = jest . fn ( ) ;
7
7
const mockUseBuitTxState = jest . fn ( ) ;
8
8
const mockUseSyncingTheFirstTime = jest . fn ( ) ;
9
9
const mockCreateTxBuilder = jest . fn ( ) ;
@@ -13,11 +13,10 @@ import { BehaviorSubject } from 'rxjs';
13
13
import { cleanup , renderHook } from '@testing-library/react-hooks' ;
14
14
import { AppSettingsProvider } from '@providers' ;
15
15
import { StoreProvider } from '@src/stores' ;
16
- import { COLLATERAL_ADA_AMOUNT , COLLATERAL_AMOUNT_LOVELACES , useCollateral } from '@hooks' ;
17
- import { APP_MODE_BROWSER } from '@src/utils/constants' ;
16
+ import { useCollateral } from '@hooks' ;
17
+ import { APP_MODE_BROWSER , COLLATERAL_AMOUNT_LOVELACES } from '@src/utils/constants' ;
18
18
import { I18nextProvider } from 'react-i18next' ;
19
19
import { i18n } from '@lace/translation' ;
20
- import { Wallet } from '@lace/cardano' ;
21
20
import { act } from 'react-dom/test-utils' ;
22
21
import { waitFor } from '@testing-library/react' ;
23
22
import { TxInspection } from '@cardano-sdk/tx-construction' ;
@@ -59,9 +58,9 @@ jest.mock('@src/views/browser-view/features/send-transaction', () => {
59
58
} ;
60
59
} ) ;
61
60
62
- jest . mock ( '@hooks/useMaxAda ' , ( ) => ( {
63
- ...jest . requireActual < any > ( '@hooks/useMaxAda ' ) ,
64
- useMaxAda : mockUseMaxAda
61
+ jest . mock ( '@hooks/useHasEnoughCollateral ' , ( ) => ( {
62
+ ...jest . requireActual < any > ( '@hooks/useHasEnoughCollateral ' ) ,
63
+ useHasEnoughCollateral : mockUseHasEnoughCollateral
65
64
} ) ) ;
66
65
67
66
jest . mock ( '@hooks/useSyncingTheFirstTime' , ( ) => ( {
@@ -91,7 +90,7 @@ describe('Testing useCollateral hook', () => {
91
90
} ) ;
92
91
test ( 'should return proper initial states' , async ( ) => {
93
92
mockUseBuitTxState . mockReturnValue ( { } ) ;
94
- mockUseMaxAda . mockReturnValue ( '' ) ;
93
+ mockUseHasEnoughCollateral . mockReturnValue ( false ) ;
95
94
const hook = renderHook ( ( ) => useCollateral ( ) , { wrapper : getWrapper ( ) } ) ;
96
95
await waitFor ( ( ) => {
97
96
expect ( hook . result . current . isInitializing ) . toBe ( false ) ;
@@ -106,21 +105,21 @@ describe('Testing useCollateral hook', () => {
106
105
107
106
test ( 'should return proper hasEnoughAda value' , async ( ) => {
108
107
mockUseBuitTxState . mockReturnValue ( { } ) ;
109
- mockUseMaxAda . mockReturnValue ( BigInt ( Wallet . util . adaToLovelacesString ( String ( COLLATERAL_ADA_AMOUNT + 1 ) ) ) ) ;
108
+ mockUseHasEnoughCollateral . mockReturnValue ( true ) ;
110
109
111
110
const hook = renderHook ( ( ) => useCollateral ( ) , { wrapper : getWrapper ( ) } ) ;
112
111
113
112
expect ( hook . result . current . hasEnoughAda ) . toBe ( true ) ;
114
113
115
- mockUseMaxAda . mockReset ( ) ;
116
- mockUseMaxAda . mockReturnValue ( BigInt ( Wallet . util . adaToLovelacesString ( String ( COLLATERAL_ADA_AMOUNT - 1 ) ) ) ) ;
114
+ mockUseHasEnoughCollateral . mockReset ( ) ;
115
+ mockUseHasEnoughCollateral . mockReturnValue ( false ) ;
117
116
hook . rerender ( ) ;
118
117
await waitFor ( ( ) => {
119
118
expect ( hook . result . current . hasEnoughAda ) . toBe ( false ) ;
120
119
} ) ;
121
120
122
- mockUseMaxAda . mockReset ( ) ;
123
- mockUseMaxAda . mockReturnValue ( BigInt ( Wallet . util . adaToLovelacesString ( String ( COLLATERAL_ADA_AMOUNT ) ) ) ) ;
121
+ mockUseHasEnoughCollateral . mockReset ( ) ;
122
+ mockUseHasEnoughCollateral . mockReturnValue ( true ) ;
124
123
hook . rerender ( ) ;
125
124
await waitFor ( ( ) => {
126
125
expect ( hook . result . current . hasEnoughAda ) . toBe ( true ) ;
@@ -181,7 +180,7 @@ describe('Testing useCollateral hook', () => {
181
180
182
181
describe ( 'testing initializeCollateralTx' , ( ) => {
183
182
test ( 'should exit early in case there is not enough ada or the wallet is syncing for the first time' , async ( ) => {
184
- mockUseMaxAda . mockReturnValue ( BigInt ( Wallet . util . adaToLovelacesString ( String ( COLLATERAL_ADA_AMOUNT - 1 ) ) ) ) ;
183
+ mockUseHasEnoughCollateral . mockReturnValue ( false ) ;
185
184
mockUseSyncingTheFirstTime . mockReturnValue ( false ) ;
186
185
const hook = renderHook ( ( ) => useCollateral ( ) , { wrapper : getWrapper ( ) } ) ;
187
186
@@ -196,8 +195,8 @@ describe('Testing useCollateral hook', () => {
196
195
expect ( inspect ) . not . toHaveBeenCalled ( ) ;
197
196
} ) ;
198
197
199
- mockUseMaxAda . mockReset ( ) ;
200
- mockUseMaxAda . mockReturnValue ( BigInt ( Wallet . util . adaToLovelacesString ( String ( COLLATERAL_ADA_AMOUNT ) ) ) ) ;
198
+ mockUseHasEnoughCollateral . mockReset ( ) ;
199
+ mockUseHasEnoughCollateral . mockReturnValue ( true ) ;
201
200
mockUseSyncingTheFirstTime . mockReturnValue ( true ) ;
202
201
hook . rerender ( ) ;
203
202
act ( ( ) => {
@@ -220,7 +219,7 @@ describe('Testing useCollateral hook', () => {
220
219
coins : COLLATERAL_AMOUNT_LOVELACES
221
220
}
222
221
} ;
223
- mockUseMaxAda . mockReturnValue ( BigInt ( Wallet . util . adaToLovelacesString ( String ( COLLATERAL_ADA_AMOUNT + 1 ) ) ) ) ;
222
+ mockUseHasEnoughCollateral . mockReturnValue ( true ) ;
224
223
mockUseSyncingTheFirstTime . mockReturnValue ( false ) ;
225
224
const hook = renderHook ( ( ) => useCollateral ( ) , { wrapper : getWrapper ( ) } ) ;
226
225
act ( ( ) => {
@@ -239,7 +238,7 @@ describe('Testing useCollateral hook', () => {
239
238
} ) ;
240
239
describe ( 'testing submitCollateralTx' , ( ) => {
241
240
test ( 'should exit early in case txBuilder is not set' , async ( ) => {
242
- mockUseMaxAda . mockReturnValue ( BigInt ( Wallet . util . adaToLovelacesString ( String ( COLLATERAL_ADA_AMOUNT - 1 ) ) ) ) ;
241
+ mockUseHasEnoughCollateral . mockReturnValue ( false ) ;
243
242
mockUseSyncingTheFirstTime . mockReturnValue ( false ) ;
244
243
const hook = renderHook ( ( ) => useCollateral ( ) , { wrapper : getWrapper ( ) } ) ;
245
244
@@ -256,8 +255,8 @@ describe('Testing useCollateral hook', () => {
256
255
expect ( mockSetBuiltTxData ) . not . toHaveBeenCalled ( ) ;
257
256
} ) ;
258
257
259
- mockUseMaxAda . mockReset ( ) ;
260
- mockUseMaxAda . mockReturnValue ( BigInt ( Wallet . util . adaToLovelacesString ( String ( COLLATERAL_ADA_AMOUNT ) ) ) ) ;
258
+ mockUseHasEnoughCollateral . mockReset ( ) ;
259
+ mockUseHasEnoughCollateral . mockReturnValue ( true ) ;
261
260
mockUseSyncingTheFirstTime . mockReturnValue ( true ) ;
262
261
hook . rerender ( ) ;
263
262
await act ( async ( ) => {
@@ -290,7 +289,7 @@ describe('Testing useCollateral hook', () => {
290
289
isInMemoryWallet : true
291
290
} ) ;
292
291
293
- mockUseMaxAda . mockReturnValue ( BigInt ( Wallet . util . adaToLovelacesString ( String ( COLLATERAL_ADA_AMOUNT + 1 ) ) ) ) ;
292
+ mockUseHasEnoughCollateral . mockReturnValue ( true ) ;
294
293
mockUseSyncingTheFirstTime . mockReturnValue ( false ) ;
295
294
const hook = renderHook ( ( ) => useCollateral ( ) , { wrapper : getWrapper ( ) } ) ;
296
295
@@ -309,8 +308,8 @@ describe('Testing useCollateral hook', () => {
309
308
test ( 'should submit the tx and set the colateral for HW (not in memory wallet)' , async ( ) => {
310
309
mockSubmitTx . mockReset ( ) ;
311
310
312
- mockUseMaxAda . mockReset ( ) ;
313
- mockUseMaxAda . mockReturnValue ( BigInt ( Wallet . util . adaToLovelacesString ( String ( COLLATERAL_ADA_AMOUNT + 1 ) ) ) ) ;
311
+ mockUseHasEnoughCollateral . mockReset ( ) ;
312
+ mockUseHasEnoughCollateral . mockReturnValue ( true ) ;
314
313
mockUseSyncingTheFirstTime . mockReset ( ) ;
315
314
mockUseSyncingTheFirstTime . mockReturnValue ( false ) ;
316
315
const hook = renderHook ( ( ) => useCollateral ( ) , { wrapper : getWrapper ( ) } ) ;
0 commit comments