1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-01 21:57:06 +01:00
metamask-extension/ui/components/app/gas-customization/gas-modal-page-container/basic-tab-content/basic-tab-content-component.test.js

104 lines
3.2 KiB
JavaScript
Raw Normal View History

import React from 'react';
import GasPriceButtonGroup from '../../gas-price-button-group';
import Loading from '../../../../ui/loading-screen';
import { GAS_ESTIMATE_TYPES } from '../../../../../helpers/constants/common';
import { shallowWithContext } from '../../../../../../test/lib/render-helpers';
import BasicTabContent from './basic-tab-content.component';
const mockGasPriceButtonGroupProps = {
buttonDataLoading: false,
className: 'gas-price-button-group',
gasButtonInfo: [
{
feeInPrimaryCurrency: '$0.52',
feeInSecondaryCurrency: '0.0048 ETH',
timeEstimate: '~ 1 min 0 sec',
priceInHexWei: '0xa1b2c3f',
gasEstimateType: GAS_ESTIMATE_TYPES.AVERAGE,
},
{
feeInPrimaryCurrency: '$0.39',
feeInSecondaryCurrency: '0.004 ETH',
timeEstimate: '~ 1 min 30 sec',
priceInHexWei: '0xa1b2c39',
gasEstimateType: GAS_ESTIMATE_TYPES.AVERAGE,
},
{
feeInPrimaryCurrency: '$0.30',
feeInSecondaryCurrency: '0.00354 ETH',
timeEstimate: '~ 2 min 1 sec',
priceInHexWei: '0xa1b2c30',
gasEstimateType: GAS_ESTIMATE_TYPES.AVERAGE,
},
],
2020-11-13 01:41:01 +01:00
handleGasPriceSelection: ({ gasPrice }) =>
console.log('NewPrice: ', gasPrice),
noButtonActiveByDefault: true,
showCheck: true,
};
describe('BasicTabContent Component', () => {
describe('render', () => {
let wrapper;
beforeEach(() => {
wrapper = shallowWithContext(
<BasicTabContent
gasPriceButtonGroupProps={mockGasPriceButtonGroupProps}
2020-11-03 00:41:28 +01:00
/>,
);
});
it('should have a title', () => {
expect(
2020-11-03 00:41:28 +01:00
wrapper
.find('.basic-tab-content')
.childAt(0)
.hasClass('basic-tab-content__title'),
).toStrictEqual(true);
});
it('should render a GasPriceButtonGroup compenent', () => {
expect(wrapper.find(GasPriceButtonGroup)).toHaveLength(1);
});
it('should pass correct props to GasPriceButtonGroup', () => {
const {
buttonDataLoading,
className,
gasButtonInfo,
handleGasPriceSelection,
noButtonActiveByDefault,
showCheck,
} = wrapper.find(GasPriceButtonGroup).props();
expect(wrapper.find(GasPriceButtonGroup)).toHaveLength(1);
expect(buttonDataLoading).toStrictEqual(
2020-11-03 00:41:28 +01:00
mockGasPriceButtonGroupProps.buttonDataLoading,
);
expect(className).toStrictEqual(mockGasPriceButtonGroupProps.className);
expect(noButtonActiveByDefault).toStrictEqual(
2020-11-03 00:41:28 +01:00
mockGasPriceButtonGroupProps.noButtonActiveByDefault,
);
expect(showCheck).toStrictEqual(mockGasPriceButtonGroupProps.showCheck);
expect(gasButtonInfo).toStrictEqual(
2020-11-03 00:41:28 +01:00
mockGasPriceButtonGroupProps.gasButtonInfo,
);
expect(handleGasPriceSelection).toStrictEqual(
mockGasPriceButtonGroupProps.handleGasPriceSelection,
);
});
it('should render a loading component instead of the GasPriceButtonGroup if gasPriceButtonGroupProps.loading is true', () => {
wrapper.setProps({
2020-11-03 00:41:28 +01:00
gasPriceButtonGroupProps: {
...mockGasPriceButtonGroupProps,
loading: true,
},
});
expect(wrapper.find(GasPriceButtonGroup)).toHaveLength(0);
expect(wrapper.find(Loading)).toHaveLength(1);
});
});
});