11import React from 'react' ;
2- import { render } from '@testing-library/react-native' ;
2+ import { render , userEvent } from '@testing-library/react-native' ;
33import Price from './Price' ;
44import { TokenI } from '../../Tokens/types' ;
55import {
@@ -8,6 +8,16 @@ import {
88} from '../../../../components/hooks/useTokenHistoricalPrices' ;
99import { AssetConversion } from '@metamask/snaps-sdk' ;
1010import { CaipAssetId } from '@metamask/utils' ;
11+ import PriceChart from '../PriceChart/PriceChart' ;
12+ import Button , {
13+ ButtonVariants ,
14+ } from '../../../../component-library/components/Buttons/Button' ;
15+
16+ jest . mock ( '../PriceChart/PriceChart' , ( ) => ( {
17+ ...jest . requireActual ( '../PriceChart/PriceChart' ) ,
18+ __esModule : true ,
19+ default : jest . fn ( ) . mockImplementation ( ( ) => null ) ,
20+ } ) ) ;
1121
1222const mockAsset : TokenI = {
1323 name : 'Ethereum' ,
@@ -102,4 +112,28 @@ describe('Price Component', () => {
102112
103113 expect ( getByTestId ( 'loading-price-diff' ) ) . toBeTruthy ( ) ;
104114 } ) ;
115+
116+ it ( 'renders price at selected date' , async ( ) => {
117+ jest
118+ . mocked ( PriceChart )
119+ . mockImplementation ( ( { onChartIndexChange } ) => (
120+ < Button
121+ testID = "mock-price-chart"
122+ variant = { ButtonVariants . Primary }
123+ label = "TEST BUTTON"
124+ onPress = { ( ) => onChartIndexChange ( 1 ) }
125+ />
126+ ) ) ;
127+
128+ const { getByTestId } = render ( < Price { ...{ ...mockProps } } /> ) ;
129+
130+ // No item selected - assert label
131+ expect ( getByTestId ( 'price-label' ) ) . toHaveTextContent ( 'Today' ) ;
132+
133+ // Act - click mock button to change chart index
134+ await userEvent . press ( getByTestId ( 'mock-price-chart' ) ) ;
135+
136+ // A date has been selected, show correct mock date
137+ expect ( getByTestId ( 'price-label' ) ) . toHaveTextContent ( 'Jan 13 at 4:40 am' ) ;
138+ } ) ;
105139} ) ;
0 commit comments