-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(fiat-amount): test UsdPricesUpdater (#3091)
- Loading branch information
Showing
8 changed files
with
423 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
apps/cowswap-frontend/src/modules/usdAmount/hooks/useUsdAmount.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { createStore } from 'jotai/vanilla' | ||
import { ReactNode } from 'react' | ||
|
||
import { CurrencyAmount } from '@uniswap/sdk-core' | ||
|
||
import { renderHook } from '@testing-library/react-hooks' | ||
import { JotaiTestProvider } from 'test-utils' | ||
|
||
import { WETH_GNOSIS_CHAIN } from 'legacy/utils/gnosis_chain/constants' | ||
|
||
import { useUsdAmount } from './useUsdAmount' | ||
|
||
import { usdRawPricesAtom, UsdRawPriceState } from '../state/usdRawPricesAtom' | ||
|
||
const WETH_RAW_PRICE_STATE: UsdRawPriceState = { | ||
updatedAt: Date.now(), | ||
price: 1650, | ||
currency: WETH_GNOSIS_CHAIN, | ||
isLoading: false, | ||
} | ||
|
||
function getWrapper() { | ||
const store = createStore() | ||
const initialValues = [[usdRawPricesAtom, { [WETH_GNOSIS_CHAIN.address.toLowerCase()]: WETH_RAW_PRICE_STATE }]] | ||
|
||
return { | ||
store, | ||
TestComponent: function ({ children }: { children: ReactNode }) { | ||
return ( | ||
<JotaiTestProvider store={store} initialValues={initialValues}> | ||
{children} | ||
</JotaiTestProvider> | ||
) | ||
}, | ||
} | ||
} | ||
|
||
describe('useUsdAmount', () => { | ||
const ONE_WETH = CurrencyAmount.fromRawAmount(WETH_GNOSIS_CHAIN, 1 * 10 ** WETH_GNOSIS_CHAIN.decimals) | ||
|
||
it('USD amount for 1 WETH should be 1650', async () => { | ||
const { TestComponent } = getWrapper() | ||
const { result } = renderHook( | ||
() => { | ||
return useUsdAmount(ONE_WETH) | ||
}, | ||
{ wrapper: TestComponent } | ||
) | ||
|
||
expect(result.current.value?.toExact()).toBe(WETH_RAW_PRICE_STATE.price?.toString()) | ||
}) | ||
}) |
Oops, something went wrong.