2021-11-23 17:52:50 +01:00
import React from 'react' ;
2022-03-11 19:59:58 +01:00
import { renderWithProvider , screen } from '../../../../../test/jest' ;
2021-11-23 17:52:50 +01:00
import configureStore from '../../../../store/store' ;
2022-03-11 19:59:58 +01:00
import { GasFeeContext } from '../../../../contexts/gasFee' ;
2021-12-06 17:02:23 +01:00
import NetworkStatistics from './network-statistics' ;
2021-11-23 17:52:50 +01:00
2022-03-11 19:59:58 +01:00
const renderComponent = ( { gasFeeContext = { } , state = { } } = { } ) => {
const store = configureStore ( state ) ;
2021-11-23 17:52:50 +01:00
return renderWithProvider (
2022-03-11 19:59:58 +01:00
< GasFeeContext . Provider value = { gasFeeContext } >
2021-12-06 17:02:23 +01:00
< NetworkStatistics / >
2021-12-18 00:00:25 +01:00
< / G a s F e e C o n t e x t . P r o v i d e r > ,
2021-11-23 17:52:50 +01:00
store ,
) ;
} ;
2021-12-06 17:02:23 +01:00
describe ( 'NetworkStatistics' , ( ) => {
2022-03-11 19:59:58 +01:00
it ( 'should render the latest base fee rounded to no decimal places' , ( ) => {
renderComponent ( {
gasFeeContext : {
gasFeeEstimates : {
estimatedBaseFee : '50.0112' ,
} ,
} ,
} ) ;
expect ( screen . getByText ( '50 GWEI' ) ) . toBeInTheDocument ( ) ;
} ) ;
it ( 'should not render the latest base fee if it is not present' , ( ) => {
renderComponent ( {
gasFeeContext : {
gasFeeEstimates : {
estimatedBaseFee : null ,
} ,
} ,
} ) ;
expect (
screen . queryByTestId ( 'formatted-latest-base-fee' ) ,
) . not . toBeInTheDocument ( ) ;
} ) ;
it ( 'should not render the latest base fee if no gas fee estimates are available' , ( ) => {
renderComponent ( {
gasFeeContext : {
gasFeeEstimates : null ,
} ,
} ) ;
expect (
screen . queryByTestId ( 'formatted-latest-base-fee' ) ,
) . not . toBeInTheDocument ( ) ;
} ) ;
it ( 'should render the latest priority fee range, with the low end of the range rounded to 1 decimal place and the high end rounded to no decimal places' , ( ) => {
renderComponent ( {
gasFeeContext : {
gasFeeEstimates : {
latestPriorityFeeRange : [ '1.100001668' , '2.5634234' ] ,
} ,
} ,
} ) ;
expect ( screen . getByText ( '1.1 - 3 GWEI' ) ) . toBeInTheDocument ( ) ;
} ) ;
it ( 'should not render the latest priority fee range if it is not present' , ( ) => {
renderComponent ( {
gasFeeContext : {
gasFeeEstimates : {
latestPriorityFeeRange : null ,
} ,
} ,
} ) ;
expect (
screen . queryByTestId ( 'formatted-latest-priority-fee-range' ) ,
) . not . toBeInTheDocument ( ) ;
} ) ;
it ( 'should not render the latest priority fee range if no gas fee estimates are available' , ( ) => {
renderComponent ( {
gasFeeContext : {
gasFeeEstimates : null ,
} ,
} ) ;
expect (
screen . queryByTestId ( 'formatted-latest-priority-fee-range' ) ,
) . not . toBeInTheDocument ( ) ;
} ) ;
it ( 'should render the network status slider' , ( ) => {
renderComponent ( {
gasFeeContext : {
gasFeeEstimates : {
networkCongestion : 0.5 ,
} ,
} ,
} ) ;
expect ( screen . getByText ( 'Stable' ) ) . toBeInTheDocument ( ) ;
} ) ;
it ( 'should not render the network status slider if the network congestion is not available' , ( ) => {
renderComponent ( {
gasFeeContext : {
gasFeeEstimates : {
networkCongestion : null ,
} ,
} ,
2021-12-18 00:00:25 +01:00
} ) ;
2022-03-11 19:59:58 +01:00
expect ( screen . queryByTestId ( 'status-slider-label' ) ) . not . toBeInTheDocument ( ) ;
2021-11-23 17:52:50 +01:00
} ) ;
2022-03-11 19:59:58 +01:00
it ( 'should not render the network status slider if no gas fee estimates are available' , ( ) => {
renderComponent ( {
gasFeeContext : {
gasFeeEstimates : null ,
} ,
2021-12-18 00:00:25 +01:00
} ) ;
2022-03-11 19:59:58 +01:00
expect ( screen . queryByTestId ( 'status-slider-label' ) ) . not . toBeInTheDocument ( ) ;
2021-11-23 17:52:50 +01:00
} ) ;
} ) ;