2021-02-04 19:15:23 +01:00
|
|
|
import React from 'react';
|
|
|
|
import sinon from 'sinon';
|
2021-04-28 21:53:59 +02:00
|
|
|
import { shallowWithContext } from '../../../../../test/lib/render-helpers';
|
2021-07-16 18:06:32 +02:00
|
|
|
import { getGasFeeEstimatesAndStartPolling } from '../../../../store/actions';
|
2018-07-31 04:28:05 +02:00
|
|
|
|
2021-03-16 22:00:08 +01:00
|
|
|
import PageContainer from '../../../ui/page-container';
|
2018-08-09 18:14:03 +02:00
|
|
|
|
2021-03-16 22:00:08 +01:00
|
|
|
import { Tab } from '../../../ui/tabs';
|
|
|
|
import GasModalPageContainer from './gas-modal-page-container.component';
|
2018-07-31 04:28:05 +02:00
|
|
|
|
2021-07-16 18:06:32 +02:00
|
|
|
jest.mock('../../../../store/actions', () => ({
|
|
|
|
disconnectGasFeeEstimatePoller: jest.fn(),
|
|
|
|
getGasFeeEstimatesAndStartPolling: jest
|
|
|
|
.fn()
|
|
|
|
.mockImplementation(() => Promise.resolve()),
|
|
|
|
}));
|
2018-11-13 17:36:52 +01:00
|
|
|
|
2018-07-31 04:28:05 +02:00
|
|
|
const propsMethodSpies = {
|
2018-09-20 18:06:23 +02:00
|
|
|
cancelAndClose: sinon.spy(),
|
2018-09-13 10:47:05 +02:00
|
|
|
onSubmit: sinon.spy(),
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-07-31 04:28:05 +02:00
|
|
|
|
2018-08-09 18:14:03 +02:00
|
|
|
const mockGasPriceButtonGroupProps = {
|
|
|
|
buttonDataLoading: false,
|
|
|
|
className: 'gas-price-button-group',
|
|
|
|
gasButtonInfo: [
|
|
|
|
{
|
|
|
|
feeInPrimaryCurrency: '$0.52',
|
|
|
|
feeInSecondaryCurrency: '0.0048 ETH',
|
|
|
|
timeEstimate: '~ 1 min 0 sec',
|
|
|
|
priceInHexWei: '0xa1b2c3f',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
feeInPrimaryCurrency: '$0.39',
|
|
|
|
feeInSecondaryCurrency: '0.004 ETH',
|
|
|
|
timeEstimate: '~ 1 min 30 sec',
|
|
|
|
priceInHexWei: '0xa1b2c39',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
feeInPrimaryCurrency: '$0.30',
|
|
|
|
feeInSecondaryCurrency: '0.00354 ETH',
|
|
|
|
timeEstimate: '~ 2 min 1 sec',
|
|
|
|
priceInHexWei: '0xa1b2c30',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
handleGasPriceSelection: 'mockSelectionFunction',
|
|
|
|
noButtonActiveByDefault: true,
|
|
|
|
showCheck: true,
|
2018-09-20 18:06:23 +02:00
|
|
|
newTotalFiat: 'mockNewTotalFiat',
|
|
|
|
newTotalEth: 'mockNewTotalEth',
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-09-13 10:47:05 +02:00
|
|
|
const mockInfoRowProps = {
|
|
|
|
originalTotalFiat: 'mockOriginalTotalFiat',
|
|
|
|
originalTotalEth: 'mockOriginalTotalEth',
|
|
|
|
newTotalFiat: 'mockNewTotalFiat',
|
|
|
|
newTotalEth: 'mockNewTotalEth',
|
2018-09-20 18:06:23 +02:00
|
|
|
sendAmount: 'mockSendAmount',
|
|
|
|
transactionFee: 'mockTransactionFee',
|
2020-10-06 20:28:38 +02:00
|
|
|
extraInfoRow: { label: 'mockLabel', value: 'mockValue' },
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-08-09 18:14:03 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const GP = GasModalPageContainer.prototype;
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('GasModalPageContainer Component', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
let wrapper;
|
2018-07-31 04:28:05 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
beforeEach(() => {
|
2021-04-28 21:53:59 +02:00
|
|
|
wrapper = shallowWithContext(
|
2019-12-03 17:35:44 +01:00
|
|
|
<GasModalPageContainer
|
|
|
|
cancelAndClose={propsMethodSpies.cancelAndClose}
|
|
|
|
onSubmit={propsMethodSpies.onSubmit}
|
|
|
|
updateCustomGasPrice={() => 'mockupdateCustomGasPrice'}
|
|
|
|
updateCustomGasLimit={() => 'mockupdateCustomGasLimit'}
|
|
|
|
gasPriceButtonGroupProps={mockGasPriceButtonGroupProps}
|
|
|
|
infoRowProps={mockInfoRowProps}
|
|
|
|
customGasPriceInHex="mockCustomGasPriceInHex"
|
|
|
|
customGasLimitInHex="mockCustomGasLimitInHex"
|
|
|
|
insufficientBalance={false}
|
|
|
|
disableSave={false}
|
2021-05-20 20:28:25 +02:00
|
|
|
customPriceIsExcessive={false}
|
2020-11-03 00:41:28 +01:00
|
|
|
/>,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
});
|
2018-07-31 04:28:05 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
afterEach(() => {
|
2021-02-04 19:15:23 +01:00
|
|
|
propsMethodSpies.cancelAndClose.resetHistory();
|
2021-07-16 18:06:32 +02:00
|
|
|
jest.clearAllMocks();
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-07-31 04:28:05 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('componentDidMount', () => {
|
2021-07-16 18:06:32 +02:00
|
|
|
it('should call getGasFeeEstimatesAndStartPolling', () => {
|
|
|
|
jest.clearAllMocks();
|
|
|
|
expect(getGasFeeEstimatesAndStartPolling).not.toHaveBeenCalled();
|
2021-02-04 19:15:23 +01:00
|
|
|
wrapper.instance().componentDidMount();
|
2021-07-16 18:06:32 +02:00
|
|
|
expect(getGasFeeEstimatesAndStartPolling).toHaveBeenCalled();
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2018-11-13 17:36:52 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('render', () => {
|
|
|
|
it('should render a PageContainer compenent', () => {
|
|
|
|
expect(wrapper.find(PageContainer)).toHaveLength(1);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-07-31 04:28:05 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should pass correct props to PageContainer', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const { title, subtitle, disabled } = wrapper.find(PageContainer).props();
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(title).toStrictEqual('customGas');
|
|
|
|
expect(subtitle).toStrictEqual('customGasSubTitle');
|
|
|
|
expect(disabled).toStrictEqual(false);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-07-31 04:28:05 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should pass the correct onCancel and onClose methods to PageContainer', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const { onCancel, onClose } = wrapper.find(PageContainer).props();
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(propsMethodSpies.cancelAndClose.callCount).toStrictEqual(0);
|
2021-02-04 19:15:23 +01:00
|
|
|
onCancel();
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(propsMethodSpies.cancelAndClose.callCount).toStrictEqual(1);
|
2021-02-04 19:15:23 +01:00
|
|
|
onClose();
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(propsMethodSpies.cancelAndClose.callCount).toStrictEqual(2);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-07-31 04:28:05 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should pass the correct renderTabs property to PageContainer', () => {
|
2021-07-16 18:06:32 +02:00
|
|
|
jest
|
|
|
|
.spyOn(GasModalPageContainer.prototype, 'renderTabs')
|
|
|
|
.mockImplementation(() => 'mockTabs');
|
2021-04-28 21:53:59 +02:00
|
|
|
const renderTabsWrapperTester = shallowWithContext(
|
2021-07-16 18:06:32 +02:00
|
|
|
<GasModalPageContainer customPriceIsExcessive={false} />,
|
2020-11-03 00:41:28 +01:00
|
|
|
{ context: { t: (str1, str2) => (str2 ? str1 + str2 : str1) } },
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-11-03 00:41:28 +01:00
|
|
|
const { tabsComponent } = renderTabsWrapperTester
|
|
|
|
.find(PageContainer)
|
2021-02-04 19:15:23 +01:00
|
|
|
.props();
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(tabsComponent).toStrictEqual('mockTabs');
|
2021-07-16 18:06:32 +02:00
|
|
|
GasModalPageContainer.prototype.renderTabs.mockClear();
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2018-07-31 04:28:05 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('renderTabs', () => {
|
|
|
|
beforeEach(() => {
|
2021-02-04 19:15:23 +01:00
|
|
|
sinon.spy(GP, 'renderBasicTabContent');
|
|
|
|
sinon.spy(GP, 'renderAdvancedTabContent');
|
|
|
|
sinon.spy(GP, 'renderInfoRows');
|
|
|
|
});
|
2018-09-13 10:47:05 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
afterEach(() => {
|
2021-02-04 19:15:23 +01:00
|
|
|
GP.renderBasicTabContent.restore();
|
|
|
|
GP.renderAdvancedTabContent.restore();
|
|
|
|
GP.renderInfoRows.restore();
|
|
|
|
});
|
2018-09-13 10:47:05 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should render a Tabs component with "Basic" and "Advanced" tabs', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const renderTabsResult = wrapper.instance().renderTabs();
|
2021-04-28 21:53:59 +02:00
|
|
|
const renderedTabs = shallowWithContext(renderTabsResult);
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(renderedTabs.props().className).toStrictEqual('tabs');
|
2018-07-31 04:28:05 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const tabs = renderedTabs.find(Tab);
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(tabs).toHaveLength(2);
|
2018-07-31 04:28:05 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(tabs.at(0).props().name).toStrictEqual('basic');
|
|
|
|
expect(tabs.at(1).props().name).toStrictEqual('advanced');
|
2018-07-31 04:28:05 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(tabs.at(0).childAt(0).props().className).toStrictEqual(
|
2020-12-03 16:46:22 +01:00
|
|
|
'gas-modal-content',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(tabs.at(1).childAt(0).props().className).toStrictEqual(
|
2020-12-03 16:46:22 +01:00
|
|
|
'gas-modal-content',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
});
|
2018-07-31 04:28:05 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should call renderInfoRows with the expected props', () => {
|
|
|
|
expect(GP.renderInfoRows.callCount).toStrictEqual(0);
|
2018-07-31 04:28:05 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
wrapper.instance().renderTabs();
|
2018-07-31 04:28:05 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(GP.renderInfoRows.callCount).toStrictEqual(2);
|
2018-07-31 04:28:05 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(GP.renderInfoRows.getCall(0).args).toStrictEqual([
|
2020-11-03 00:41:28 +01:00
|
|
|
'mockNewTotalFiat',
|
|
|
|
'mockNewTotalEth',
|
|
|
|
'mockSendAmount',
|
|
|
|
'mockTransactionFee',
|
2021-02-04 19:15:23 +01:00
|
|
|
]);
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(GP.renderInfoRows.getCall(1).args).toStrictEqual([
|
2020-11-03 00:41:28 +01:00
|
|
|
'mockNewTotalFiat',
|
|
|
|
'mockNewTotalEth',
|
|
|
|
'mockSendAmount',
|
|
|
|
'mockTransactionFee',
|
2021-02-04 19:15:23 +01:00
|
|
|
]);
|
|
|
|
});
|
2018-09-20 06:16:43 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should not render the basic tab if hideBasic is true', () => {
|
2021-04-28 21:53:59 +02:00
|
|
|
wrapper = shallowWithContext(
|
2019-12-03 17:35:44 +01:00
|
|
|
<GasModalPageContainer
|
|
|
|
cancelAndClose={propsMethodSpies.cancelAndClose}
|
|
|
|
onSubmit={propsMethodSpies.onSubmit}
|
|
|
|
updateCustomGasPrice={() => 'mockupdateCustomGasPrice'}
|
|
|
|
updateCustomGasLimit={() => 'mockupdateCustomGasLimit'}
|
|
|
|
gasPriceButtonGroupProps={mockGasPriceButtonGroupProps}
|
|
|
|
infoRowProps={mockInfoRowProps}
|
|
|
|
customGasPriceInHex="mockCustomGasPriceInHex"
|
|
|
|
customGasLimitInHex="mockCustomGasLimitInHex"
|
|
|
|
insufficientBalance={false}
|
|
|
|
disableSave={false}
|
2021-05-20 20:28:25 +02:00
|
|
|
customPriceIsExcessive={false}
|
2019-12-03 17:35:44 +01:00
|
|
|
hideBasic
|
2020-11-03 00:41:28 +01:00
|
|
|
/>,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
const renderTabsResult = wrapper.instance().renderTabs();
|
2018-09-20 06:16:43 +02:00
|
|
|
|
2021-04-28 21:53:59 +02:00
|
|
|
const renderedTabs = shallowWithContext(renderTabsResult);
|
2021-02-04 19:15:23 +01:00
|
|
|
const tabs = renderedTabs.find(Tab);
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(tabs).toHaveLength(1);
|
|
|
|
expect(tabs.at(0).props().name).toStrictEqual('advanced');
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2018-07-31 04:28:05 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('renderBasicTabContent', () => {
|
|
|
|
it('should render', () => {
|
2020-11-03 00:41:28 +01:00
|
|
|
const renderBasicTabContentResult = wrapper
|
|
|
|
.instance()
|
2021-02-04 19:15:23 +01:00
|
|
|
.renderBasicTabContent(mockGasPriceButtonGroupProps);
|
2018-08-09 18:14:03 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(
|
2018-08-09 18:14:03 +02:00
|
|
|
renderBasicTabContentResult.props.gasPriceButtonGroupProps,
|
2021-04-15 20:01:46 +02:00
|
|
|
).toStrictEqual(mockGasPriceButtonGroupProps);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2018-07-31 04:28:05 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('renderInfoRows', () => {
|
|
|
|
it('should render the info rows with the passed data', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const baseClassName = 'gas-modal-content__info-row';
|
2021-04-28 21:53:59 +02:00
|
|
|
const renderedInfoRowsContainer = shallowWithContext(
|
2020-11-03 00:41:28 +01:00
|
|
|
wrapper
|
|
|
|
.instance()
|
|
|
|
.renderInfoRows(
|
|
|
|
'mockNewTotalFiat',
|
|
|
|
' mockNewTotalEth',
|
|
|
|
' mockSendAmount',
|
|
|
|
' mockTransactionFee',
|
|
|
|
),
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2018-09-20 18:06:23 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(
|
|
|
|
renderedInfoRowsContainer.childAt(0).hasClass(baseClassName),
|
|
|
|
).toStrictEqual(true);
|
2018-09-20 18:06:23 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const renderedInfoRows = renderedInfoRowsContainer.childAt(0).children();
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(renderedInfoRows).toHaveLength(4);
|
|
|
|
expect(
|
|
|
|
renderedInfoRows.at(0).hasClass(`${baseClassName}__send-info`),
|
|
|
|
).toStrictEqual(true);
|
|
|
|
expect(
|
2020-11-03 00:41:28 +01:00
|
|
|
renderedInfoRows.at(1).hasClass(`${baseClassName}__transaction-info`),
|
2021-04-15 20:01:46 +02:00
|
|
|
).toStrictEqual(true);
|
|
|
|
expect(
|
|
|
|
renderedInfoRows.at(2).hasClass(`${baseClassName}__total-info`),
|
|
|
|
).toStrictEqual(true);
|
|
|
|
expect(
|
2020-11-03 00:41:28 +01:00
|
|
|
renderedInfoRows.at(3).hasClass(`${baseClassName}__fiat-total-info`),
|
2021-04-15 20:01:46 +02:00
|
|
|
).toStrictEqual(true);
|
2018-09-20 18:06:23 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(renderedInfoRows.at(0).text()).toStrictEqual(
|
2020-12-03 16:46:22 +01:00
|
|
|
'sendAmount mockSendAmount',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(renderedInfoRows.at(1).text()).toStrictEqual(
|
2020-11-03 00:41:28 +01:00
|
|
|
'transactionFee mockTransactionFee',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(renderedInfoRows.at(2).text()).toStrictEqual(
|
2020-12-03 16:46:22 +01:00
|
|
|
'newTotal mockNewTotalEth',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(renderedInfoRows.at(3).text()).toStrictEqual('mockNewTotalFiat');
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|