2018-07-31 04:28:05 +02:00
|
|
|
import React from 'react'
|
|
|
|
import assert from 'assert'
|
2018-08-08 15:51:06 +02:00
|
|
|
import shallow from '../../../../../lib/shallow-with-context'
|
2018-07-31 04:28:05 +02:00
|
|
|
import sinon from 'sinon'
|
|
|
|
import GasModalPageContainer from '../gas-modal-page-container.component.js'
|
2018-11-13 17:36:52 +01:00
|
|
|
import timeout from '../../../../../lib/test-timeout'
|
2018-07-31 04:28:05 +02:00
|
|
|
|
|
|
|
import PageContainer from '../../../page-container'
|
2018-08-09 18:14:03 +02:00
|
|
|
|
2018-07-31 04:28:05 +02:00
|
|
|
import { Tab } from '../../../tabs'
|
|
|
|
|
2018-11-13 17:36:52 +01:00
|
|
|
const mockBasicGasEstimates = {
|
|
|
|
blockTime: 'mockBlockTime',
|
|
|
|
}
|
|
|
|
|
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(),
|
2018-11-13 17:36:52 +01:00
|
|
|
fetchBasicGasAndTimeEstimates: sinon.stub().returns(Promise.resolve(mockBasicGasEstimates)),
|
|
|
|
fetchGasEstimates: sinon.spy(),
|
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',
|
2018-08-09 18:14:03 +02: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',
|
2018-09-13 10:47:05 +02:00
|
|
|
}
|
2018-08-09 18:14:03 +02:00
|
|
|
|
2018-09-13 10:47:05 +02:00
|
|
|
const GP = GasModalPageContainer.prototype
|
2018-07-31 04:28:05 +02:00
|
|
|
describe('GasModalPageContainer Component', function () {
|
|
|
|
let wrapper
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
wrapper = shallow(<GasModalPageContainer
|
2018-09-20 18:06:23 +02:00
|
|
|
cancelAndClose={propsMethodSpies.cancelAndClose}
|
2018-09-13 10:47:05 +02:00
|
|
|
onSubmit={propsMethodSpies.onSubmit}
|
2018-11-13 17:36:52 +01:00
|
|
|
fetchBasicGasAndTimeEstimates={propsMethodSpies.fetchBasicGasAndTimeEstimates}
|
|
|
|
fetchGasEstimates={propsMethodSpies.fetchGasEstimates}
|
2018-08-08 15:51:06 +02:00
|
|
|
updateCustomGasPrice={() => 'mockupdateCustomGasPrice'}
|
|
|
|
updateCustomGasLimit={() => 'mockupdateCustomGasLimit'}
|
|
|
|
customGasPrice={21}
|
|
|
|
customGasLimit={54321}
|
2018-08-09 18:14:03 +02:00
|
|
|
gasPriceButtonGroupProps={mockGasPriceButtonGroupProps}
|
2018-09-13 10:47:05 +02:00
|
|
|
infoRowProps={mockInfoRowProps}
|
2018-10-10 18:06:38 +02:00
|
|
|
currentTimeEstimate={'1 min 31 sec'}
|
2018-09-13 10:47:05 +02:00
|
|
|
customGasPriceInHex={'mockCustomGasPriceInHex'}
|
|
|
|
customGasLimitInHex={'mockCustomGasLimitInHex'}
|
2018-10-26 07:50:36 +02:00
|
|
|
insufficientBalance={false}
|
2018-12-10 22:51:00 +01:00
|
|
|
disableSave={false}
|
2018-07-31 04:28:05 +02:00
|
|
|
/>, { context: { t: (str1, str2) => str2 ? str1 + str2 : str1 } })
|
|
|
|
})
|
|
|
|
|
|
|
|
afterEach(() => {
|
2018-09-20 18:06:23 +02:00
|
|
|
propsMethodSpies.cancelAndClose.resetHistory()
|
2018-07-31 04:28:05 +02:00
|
|
|
})
|
|
|
|
|
2018-11-13 17:36:52 +01:00
|
|
|
describe('componentDidMount', () => {
|
|
|
|
it('should call props.fetchBasicGasAndTimeEstimates', () => {
|
|
|
|
propsMethodSpies.fetchBasicGasAndTimeEstimates.resetHistory()
|
|
|
|
assert.equal(propsMethodSpies.fetchBasicGasAndTimeEstimates.callCount, 0)
|
|
|
|
wrapper.instance().componentDidMount()
|
|
|
|
assert.equal(propsMethodSpies.fetchBasicGasAndTimeEstimates.callCount, 1)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should call props.fetchGasEstimates with the block time returned by fetchBasicGasAndTimeEstimates', async () => {
|
|
|
|
propsMethodSpies.fetchGasEstimates.resetHistory()
|
|
|
|
assert.equal(propsMethodSpies.fetchGasEstimates.callCount, 0)
|
|
|
|
wrapper.instance().componentDidMount()
|
|
|
|
await timeout(250)
|
|
|
|
assert.equal(propsMethodSpies.fetchGasEstimates.callCount, 1)
|
|
|
|
assert.equal(propsMethodSpies.fetchGasEstimates.getCall(0).args[0], 'mockBlockTime')
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2018-07-31 04:28:05 +02:00
|
|
|
describe('render', () => {
|
|
|
|
it('should render a PageContainer compenent', () => {
|
|
|
|
assert.equal(wrapper.find(PageContainer).length, 1)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should pass correct props to PageContainer', () => {
|
|
|
|
const {
|
|
|
|
title,
|
|
|
|
subtitle,
|
|
|
|
disabled,
|
|
|
|
} = wrapper.find(PageContainer).props()
|
|
|
|
assert.equal(title, 'customGas')
|
2018-08-06 16:34:06 +02:00
|
|
|
assert.equal(subtitle, 'customGasSubTitle')
|
2018-07-31 04:28:05 +02:00
|
|
|
assert.equal(disabled, false)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should pass the correct onCancel and onClose methods to PageContainer', () => {
|
|
|
|
const {
|
|
|
|
onCancel,
|
|
|
|
onClose,
|
|
|
|
} = wrapper.find(PageContainer).props()
|
2018-09-20 18:06:23 +02:00
|
|
|
assert.equal(propsMethodSpies.cancelAndClose.callCount, 0)
|
2018-07-31 04:28:05 +02:00
|
|
|
onCancel()
|
2018-09-20 18:06:23 +02:00
|
|
|
assert.equal(propsMethodSpies.cancelAndClose.callCount, 1)
|
2018-07-31 04:28:05 +02:00
|
|
|
onClose()
|
2018-09-20 18:06:23 +02:00
|
|
|
assert.equal(propsMethodSpies.cancelAndClose.callCount, 2)
|
2018-07-31 04:28:05 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should pass the correct renderTabs property to PageContainer', () => {
|
2018-09-13 10:47:05 +02:00
|
|
|
sinon.stub(GP, 'renderTabs').returns('mockTabs')
|
2018-11-13 17:36:52 +01:00
|
|
|
const renderTabsWrapperTester = shallow(<GasModalPageContainer
|
|
|
|
fetchBasicGasAndTimeEstimates={propsMethodSpies.fetchBasicGasAndTimeEstimates}
|
|
|
|
fetchGasEstimates={propsMethodSpies.fetchGasEstimates}
|
|
|
|
/>, { context: { t: (str1, str2) => str2 ? str1 + str2 : str1 } })
|
2018-07-31 04:28:05 +02:00
|
|
|
const { tabsComponent } = renderTabsWrapperTester.find(PageContainer).props()
|
|
|
|
assert.equal(tabsComponent, 'mockTabs')
|
|
|
|
GasModalPageContainer.prototype.renderTabs.restore()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('renderTabs', () => {
|
2018-09-13 10:47:05 +02:00
|
|
|
beforeEach(() => {
|
|
|
|
sinon.spy(GP, 'renderBasicTabContent')
|
|
|
|
sinon.spy(GP, 'renderAdvancedTabContent')
|
|
|
|
sinon.spy(GP, 'renderInfoRows')
|
|
|
|
})
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
GP.renderBasicTabContent.restore()
|
|
|
|
GP.renderAdvancedTabContent.restore()
|
|
|
|
GP.renderInfoRows.restore()
|
|
|
|
})
|
|
|
|
|
2018-07-31 04:28:05 +02:00
|
|
|
it('should render a Tabs component with "Basic" and "Advanced" tabs', () => {
|
2018-09-13 10:47:05 +02:00
|
|
|
const renderTabsResult = wrapper.instance().renderTabs(mockInfoRowProps, {
|
|
|
|
gasPriceButtonGroupProps: mockGasPriceButtonGroupProps,
|
|
|
|
otherProps: 'mockAdvancedTabProps',
|
|
|
|
})
|
2018-07-31 04:28:05 +02:00
|
|
|
const renderedTabs = shallow(renderTabsResult)
|
|
|
|
assert.equal(renderedTabs.props().className, 'tabs')
|
|
|
|
|
|
|
|
const tabs = renderedTabs.find(Tab)
|
|
|
|
assert.equal(tabs.length, 2)
|
|
|
|
|
|
|
|
assert.equal(tabs.at(0).props().name, 'basic')
|
|
|
|
assert.equal(tabs.at(1).props().name, 'advanced')
|
|
|
|
|
|
|
|
assert.equal(tabs.at(0).childAt(0).props().className, 'gas-modal-content')
|
|
|
|
assert.equal(tabs.at(1).childAt(0).props().className, 'gas-modal-content')
|
|
|
|
})
|
|
|
|
|
2018-09-13 10:47:05 +02:00
|
|
|
it('should call renderBasicTabContent and renderAdvancedTabContent with the expected props', () => {
|
|
|
|
assert.equal(GP.renderBasicTabContent.callCount, 0)
|
|
|
|
assert.equal(GP.renderAdvancedTabContent.callCount, 0)
|
2018-07-31 04:28:05 +02:00
|
|
|
|
2018-09-13 10:47:05 +02:00
|
|
|
wrapper.instance().renderTabs(mockInfoRowProps, { gasPriceButtonGroupProps: mockGasPriceButtonGroupProps, otherProps: 'mockAdvancedTabProps' })
|
2018-07-31 04:28:05 +02:00
|
|
|
|
2018-09-13 10:47:05 +02:00
|
|
|
assert.equal(GP.renderBasicTabContent.callCount, 1)
|
|
|
|
assert.equal(GP.renderAdvancedTabContent.callCount, 1)
|
2018-07-31 04:28:05 +02:00
|
|
|
|
2018-09-13 10:47:05 +02:00
|
|
|
assert.deepEqual(GP.renderBasicTabContent.getCall(0).args[0], mockGasPriceButtonGroupProps)
|
|
|
|
assert.deepEqual(GP.renderAdvancedTabContent.getCall(0).args[0], { otherProps: 'mockAdvancedTabProps' })
|
2018-07-31 04:28:05 +02:00
|
|
|
})
|
|
|
|
|
2018-09-13 10:47:05 +02:00
|
|
|
it('should call renderInfoRows with the expected props', () => {
|
|
|
|
assert.equal(GP.renderInfoRows.callCount, 0)
|
2018-07-31 04:28:05 +02:00
|
|
|
|
2018-09-13 10:47:05 +02:00
|
|
|
wrapper.instance().renderTabs(mockInfoRowProps, { gasPriceButtonGroupProps: mockGasPriceButtonGroupProps, otherProps: 'mockAdvancedTabProps' })
|
2018-07-31 04:28:05 +02:00
|
|
|
|
2018-09-13 10:47:05 +02:00
|
|
|
assert.equal(GP.renderInfoRows.callCount, 2)
|
2018-07-31 04:28:05 +02:00
|
|
|
|
2018-09-20 18:06:23 +02:00
|
|
|
assert.deepEqual(GP.renderInfoRows.getCall(0).args, ['mockNewTotalFiat', 'mockNewTotalEth', 'mockSendAmount', 'mockTransactionFee'])
|
|
|
|
assert.deepEqual(GP.renderInfoRows.getCall(1).args, ['mockNewTotalFiat', 'mockNewTotalEth', 'mockSendAmount', 'mockTransactionFee'])
|
2018-07-31 04:28:05 +02:00
|
|
|
})
|
2018-09-20 06:16:43 +02:00
|
|
|
|
|
|
|
it('should not render the basic tab if hideBasic is true', () => {
|
|
|
|
const renderTabsResult = wrapper.instance().renderTabs(mockInfoRowProps, {
|
|
|
|
gasPriceButtonGroupProps: mockGasPriceButtonGroupProps,
|
|
|
|
otherProps: 'mockAdvancedTabProps',
|
|
|
|
hideBasic: true,
|
|
|
|
})
|
|
|
|
|
|
|
|
const renderedTabs = shallow(renderTabsResult)
|
|
|
|
const tabs = renderedTabs.find(Tab)
|
|
|
|
assert.equal(tabs.length, 1)
|
|
|
|
assert.equal(tabs.at(0).props().name, 'advanced')
|
|
|
|
})
|
2018-07-31 04:28:05 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
describe('renderBasicTabContent', () => {
|
|
|
|
it('should render', () => {
|
2018-09-13 10:47:05 +02:00
|
|
|
const renderBasicTabContentResult = wrapper.instance().renderBasicTabContent(mockGasPriceButtonGroupProps)
|
2018-08-09 18:14:03 +02:00
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
renderBasicTabContentResult.props.gasPriceButtonGroupProps,
|
|
|
|
mockGasPriceButtonGroupProps
|
|
|
|
)
|
2018-07-31 04:28:05 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('renderAdvancedTabContent', () => {
|
2018-08-08 15:51:06 +02:00
|
|
|
it('should render with the correct props', () => {
|
2018-09-13 10:47:05 +02:00
|
|
|
const renderAdvancedTabContentResult = wrapper.instance().renderAdvancedTabContent({
|
|
|
|
convertThenUpdateCustomGasPrice: () => 'mockConvertThenUpdateCustomGasPrice',
|
|
|
|
convertThenUpdateCustomGasLimit: () => 'mockConvertThenUpdateCustomGasLimit',
|
|
|
|
customGasPrice: 123,
|
|
|
|
customGasLimit: 456,
|
|
|
|
newTotalFiat: '$0.30',
|
2018-10-10 18:06:38 +02:00
|
|
|
currentTimeEstimate: '1 min 31 sec',
|
2018-11-13 18:02:04 +01:00
|
|
|
gasEstimatesLoading: 'mockGasEstimatesLoading',
|
2018-09-13 10:47:05 +02:00
|
|
|
})
|
2018-08-08 15:51:06 +02:00
|
|
|
const advancedTabContentProps = renderAdvancedTabContentResult.props
|
2018-09-13 10:47:05 +02:00
|
|
|
assert.equal(advancedTabContentProps.updateCustomGasPrice(), 'mockConvertThenUpdateCustomGasPrice')
|
|
|
|
assert.equal(advancedTabContentProps.updateCustomGasLimit(), 'mockConvertThenUpdateCustomGasLimit')
|
|
|
|
assert.equal(advancedTabContentProps.customGasPrice, 123)
|
|
|
|
assert.equal(advancedTabContentProps.customGasLimit, 456)
|
2018-09-20 18:06:23 +02:00
|
|
|
assert.equal(advancedTabContentProps.timeRemaining, '1 min 31 sec')
|
2018-08-08 15:51:06 +02:00
|
|
|
assert.equal(advancedTabContentProps.totalFee, '$0.30')
|
2018-11-13 18:02:04 +01:00
|
|
|
assert.equal(advancedTabContentProps.gasEstimatesLoading, 'mockGasEstimatesLoading')
|
2018-07-31 04:28:05 +02:00
|
|
|
})
|
|
|
|
})
|
2018-09-20 18:06:23 +02:00
|
|
|
|
|
|
|
describe('renderInfoRows', () => {
|
|
|
|
it('should render the info rows with the passed data', () => {
|
|
|
|
const baseClassName = 'gas-modal-content__info-row'
|
|
|
|
const renderedInfoRowsContainer = shallow(wrapper.instance().renderInfoRows(
|
|
|
|
'mockNewTotalFiat',
|
|
|
|
' mockNewTotalEth',
|
|
|
|
' mockSendAmount',
|
|
|
|
' mockTransactionFee'
|
|
|
|
))
|
|
|
|
|
|
|
|
assert(renderedInfoRowsContainer.childAt(0).hasClass(baseClassName))
|
|
|
|
|
|
|
|
const renderedInfoRows = renderedInfoRowsContainer.childAt(0).children()
|
|
|
|
assert.equal(renderedInfoRows.length, 4)
|
|
|
|
assert(renderedInfoRows.at(0).hasClass(`${baseClassName}__send-info`))
|
|
|
|
assert(renderedInfoRows.at(1).hasClass(`${baseClassName}__transaction-info`))
|
|
|
|
assert(renderedInfoRows.at(2).hasClass(`${baseClassName}__total-info`))
|
|
|
|
assert(renderedInfoRows.at(3).hasClass(`${baseClassName}__fiat-total-info`))
|
|
|
|
|
2018-10-11 01:06:14 +02:00
|
|
|
assert.equal(renderedInfoRows.at(0).text(), 'sendAmount mockSendAmount')
|
|
|
|
assert.equal(renderedInfoRows.at(1).text(), 'transactionFee mockTransactionFee')
|
|
|
|
assert.equal(renderedInfoRows.at(2).text(), 'newTotal mockNewTotalEth')
|
2018-09-20 18:06:23 +02:00
|
|
|
assert.equal(renderedInfoRows.at(3).text(), 'mockNewTotalFiat')
|
|
|
|
})
|
|
|
|
})
|
2018-07-31 04:28:05 +02:00
|
|
|
})
|