1+ /* eslint-disable no-magic-numbers */
12/* eslint-disable sonarjs/no-identical-functions */
23/* eslint-disable unicorn/no-null */
34/* eslint-disable @typescript-eslint/no-explicit-any */
45/* eslint-disable import/imports-first */
56import * as CurrencyProvider from '@providers/currency' ;
67import * as UseFetchCoinPrice from '@hooks/useFetchCoinPrice' ;
8+ import * as UseComputeTxCollateral from '@hooks/useComputeTxCollateral' ;
9+ import * as GetAssetsInformation from '@src/utils/get-assets-information' ;
710
811const mockSkeleton = jest . fn ( ( ) => < span data-testid = "skeleton" /> ) ;
912const mockUseWalletStore = jest . fn ( ) ;
1013const t = jest . fn ( ) . mockImplementation ( ( res ) => res ) ;
1114const mockUseTranslation = jest . fn ( ( ) => ( { t } ) ) ;
1215const mockDappTransaction = jest . fn ( ) ;
13- const mockUseCreateAssetList = jest . fn ( ) ;
14- const mockUseCreateMintedAssetList = jest . fn ( ) ;
1516const mockUseViewsFlowContext = jest . fn ( ) ;
17+ const mockGetAssetsInformation = jest . fn ( ) . mockReturnValue ( Promise . resolve ( new Map ( ) ) ) ;
1618const mockWithAddressBookContext = jest . fn ( ( children ) => children ) ;
1719const mockUseCurrencyStore = jest . fn ( ) . mockReturnValue ( { fiatCurrency : { code : 'usd' , symbol : '$' } } ) ;
1820const mockUseFetchCoinPrice = jest . fn ( ) . mockReturnValue ( { priceResult : { cardano : { price : 2 } , tokens : new Map ( ) } } ) ;
21+ const mockUseComputeTxCollateral = jest . fn ( ) . mockReturnValue ( BigInt ( 1_000_000 ) ) ;
1922import * as React from 'react' ;
2023import { cleanup , render } from '@testing-library/react' ;
2124import { DappTransactionContainer } from '../DappTransactionContainer' ;
@@ -27,11 +30,17 @@ import { Wallet } from '@lace/cardano';
2730import { SignTxData } from '../types' ;
2831import { getWrapper } from '../testing.utils' ;
2932import { TransactionWitnessRequest } from '@cardano-sdk/web-extension' ;
33+ import { cardanoCoin } from '@src/utils/constants' ;
3034
3135const { Cardano, Crypto } = Wallet ;
3236
33- const assetProvider = 'assetProvider' ;
34- const walletInfo = 'walletInfo' ;
37+ const assetProvider = {
38+ getAssets : jest . fn ( ( ) => [ 'assets' ] )
39+ } ;
40+ const walletInfo = {
41+ name : 'wall' ,
42+ addresses : [ { address : 'address' } ]
43+ } ;
3544const mockedAssetsInfo = new Map ( [ [ 'id' , 'data' ] ] ) ;
3645const assetInfo$ = new BehaviorSubject ( mockedAssetsInfo ) ;
3746const available$ = new BehaviorSubject ( [ ] ) ;
@@ -49,10 +58,22 @@ jest.mock('@src/stores', () => ({
4958 ...jest . requireActual < any > ( '@src/stores' ) ,
5059 useWalletStore : mockUseWalletStore
5160} ) ) ;
61+
5262jest . mock ( '@hooks/useFetchCoinPrice' , ( ) : typeof UseFetchCoinPrice => ( {
5363 ...jest . requireActual < typeof UseFetchCoinPrice > ( '@hooks/useFetchCoinPrice' ) ,
5464 useFetchCoinPrice : mockUseFetchCoinPrice
5565} ) ) ;
66+
67+ jest . mock ( '@hooks/useComputeTxCollateral' , ( ) : typeof UseComputeTxCollateral => ( {
68+ ...jest . requireActual < typeof UseComputeTxCollateral > ( '@hooks/useComputeTxCollateral' ) ,
69+ useComputeTxCollateral : mockUseComputeTxCollateral
70+ } ) ) ;
71+
72+ jest . mock ( '@src/utils/get-assets-information' , ( ) : typeof GetAssetsInformation => ( {
73+ ...jest . requireActual < typeof GetAssetsInformation > ( '@src/utils/get-assets-information' ) ,
74+ getAssetsInformation : mockGetAssetsInformation
75+ } ) ) ;
76+
5677jest . mock ( '@providers/currency' , ( ) : typeof CurrencyProvider => ( {
5778 ...jest . requireActual < typeof CurrencyProvider > ( '@providers/currency' ) ,
5879 useCurrencyStore : mockUseCurrencyStore
@@ -76,17 +97,7 @@ jest.mock('react-i18next', () => {
7697 } ;
7798} ) ;
7899
79- jest . mock ( '../hooks.ts' , ( ) => {
80- const original = jest . requireActual ( '../hooks.ts' ) ;
81- return {
82- __esModule : true ,
83- ...original ,
84- useCreateAssetList : mockUseCreateAssetList ,
85- useCreateMintedAssetList : mockUseCreateMintedAssetList
86- } ;
87- } ) ;
88-
89- const addressList = 'addressList' ;
100+ const addressList = [ 'addressList' ] ;
90101jest . mock ( '@src/features/address-book/context' , ( ) => ( {
91102 // eslint-disable-next-line @typescript-eslint/no-explicit-any
92103 ...jest . requireActual < any > ( '@src/features/address-book/context' ) ,
@@ -143,7 +154,7 @@ describe('Testing DappTransactionContainer component', () => {
143154 inMemoryWallet,
144155 blockchainProvider : { assetProvider } ,
145156 walletInfo,
146- walletUI : { cardanoCoin : { } }
157+ walletUI : { cardanoCoin }
147158 } ) ) ;
148159 mockDappTransaction . mockReset ( ) ;
149160 mockDappTransaction . mockReturnValue ( < span data-testid = "DappTransaction" /> ) ;
@@ -172,13 +183,67 @@ describe('Testing DappTransactionContainer component', () => {
172183 const errorMessage = 'errorMessage' ;
173184 const props = { errorMessage } ;
174185
175- const txSummary = 'txSummary' ;
176- const createAssetList = 'createAssetList' ;
177- mockUseCreateAssetList . mockReset ( ) ;
178- mockUseCreateAssetList . mockReturnValue ( createAssetList ) ;
179- const createMintedAssetList = 'createMintedAssetList' ;
180- mockUseCreateMintedAssetList . mockReset ( ) ;
181- mockUseCreateMintedAssetList . mockReturnValue ( createMintedAssetList ) ;
186+ const txSummary = {
187+ burnedAssets : [ ] ,
188+ collateral : '1.00' ,
189+ fee : '0.17' ,
190+ mintedAssets : [
191+ {
192+ amount : '3' ,
193+ name : 'asset1rqluyux4nxv6kjashz626c8usp8g88unmqwnyh' ,
194+ ticker : 'asset1rqluyux4nxv6kjashz626c8usp8g88unmqwnyh'
195+ }
196+ ] ,
197+ outputs : [
198+ {
199+ coins : '5.00' ,
200+ recipient :
201+ 'addr_test1qpfhhfy2qgls50r9u4yh0l7z67xpg0a5rrhkmvzcuqrd0znuzcjqw982pcftgx53fu5527z2cj2tkx2h8ux2vxsg475q9gw0lz'
202+ } ,
203+ {
204+ assets : [
205+ {
206+ amount : '3' ,
207+ name : '659f2917fb63f12b33667463ee575eeac1845bbc736b9c0bbc40ba8254534c41' ,
208+ ticker : undefined
209+ } ,
210+ {
211+ amount : '4' ,
212+ name : '6b8d07d69639e9413dd637a1a815a7323c69c86abbafb66dbfdb1aa7' ,
213+ ticker : undefined
214+ }
215+ ] ,
216+ coins : '2.00' ,
217+ recipient :
218+ 'addr_test1qpfhhfy2qgls50r9u4yh0l7z67xpg0a5rrhkmvzcuqrd0znuzcjqw982pcftgx53fu5527z2cj2tkx2h8ux2vxsg475q9gw0lz'
219+ } ,
220+ {
221+ assets : [
222+ {
223+ amount : '6' ,
224+ name : '659f2917fb63f12b33667463ee575eeac1845bbc736b9c0bbc40ba8254534c41' ,
225+ ticker : undefined
226+ }
227+ ] ,
228+ coins : '2.00' ,
229+ recipient :
230+ 'addr_test1qpfhhfy2qgls50r9u4yh0l7z67xpg0a5rrhkmvzcuqrd0znuzcjqw982pcftgx53fu5527z2cj2tkx2h8ux2vxsg475q9gw0lz'
231+ } ,
232+ {
233+ assets : [
234+ {
235+ amount : '1' ,
236+ name : '659f2917fb63f12b33667463ee575eeac1845bbc736b9c0bbc40ba8254534c41' ,
237+ ticker : undefined
238+ }
239+ ] ,
240+ coins : '2.00' ,
241+ recipient :
242+ 'addr_test1qq585l3hyxgj3nas2v3xymd23vvartfhceme6gv98aaeg9muzcjqw982pcftgx53fu5527z2cj2tkx2h8ux2vxsg475q2g7k3g'
243+ }
244+ ] ,
245+ type : 'Mint'
246+ } as Wallet . Cip30SignTxSummary ;
182247
183248 await act ( async ( ) => {
184249 ( { queryByTestId } = render ( < DappTransactionContainer { ...props } /> , {
@@ -187,25 +252,14 @@ describe('Testing DappTransactionContainer component', () => {
187252 } ) ;
188253
189254 expect ( queryByTestId ( 'DappTransaction' ) ) . toBeInTheDocument ( ) ;
190- expect ( mockUseCreateAssetList ) . toHaveBeenLastCalledWith ( {
191- outputs : tx . body . outputs ,
192- assets : mockedAssetsInfo ,
193- assetProvider
194- } ) ;
195- expect ( mockUseCreateMintedAssetList ) . toHaveBeenLastCalledWith ( {
196- outputs : tx . body . outputs ,
197- assets : mockedAssetsInfo ,
198- assetProvider,
199- metadata : tx . auxiliaryData . blob ,
200- mint : tx . body . mint
201- } ) ;
202255 expect ( mockDappTransaction ) . toHaveBeenLastCalledWith (
203256 {
204257 dappInfo,
205258 transaction : txSummary ,
206259 fiatCurrencyCode : 'usd' ,
207260 fiatCurrencyPrice : 2 ,
208- errorMessage
261+ errorMessage,
262+ coinSymbol : 'ADA'
209263 } ,
210264 { }
211265 ) ;
0 commit comments