2018-05-10 18:17:05 +02:00
|
|
|
import React from 'react'
|
|
|
|
import assert from 'assert'
|
|
|
|
import { shallow } from 'enzyme'
|
|
|
|
import sinon from 'sinon'
|
|
|
|
import SendGasRow from '../send-gas-row.component.js'
|
|
|
|
|
|
|
|
import SendRowWrapper from '../../send-row-wrapper/send-row-wrapper.component'
|
2018-06-21 08:43:48 +02:00
|
|
|
import GasFeeDisplay from '../gas-fee-display/gas-fee-display.component'
|
2019-04-17 21:15:13 +02:00
|
|
|
import GasPriceButtonGroup from '../../../../../components/app/gas-customization/gas-price-button-group'
|
2018-05-10 18:17:05 +02:00
|
|
|
|
|
|
|
const propsMethodSpies = {
|
|
|
|
showCustomizeGasModal: sinon.spy(),
|
2018-11-05 18:01:46 +01:00
|
|
|
resetGasButtons: sinon.spy(),
|
2018-05-10 18:17:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
describe('SendGasRow Component', function () {
|
|
|
|
let wrapper
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('render', function () {
|
|
|
|
beforeEach(function () {
|
|
|
|
wrapper = shallow((
|
|
|
|
<SendGasRow
|
|
|
|
conversionRate={20}
|
|
|
|
convertedCurrency="mockConvertedCurrency"
|
|
|
|
gasFeeError
|
|
|
|
gasLoadingError={false}
|
|
|
|
gasTotal="mockGasTotal"
|
|
|
|
gasButtonGroupShown={false}
|
|
|
|
showCustomizeGasModal={propsMethodSpies.showCustomizeGasModal}
|
|
|
|
resetGasButtons={propsMethodSpies.resetGasButtons}
|
|
|
|
gasPriceButtonGroupProps={{
|
|
|
|
someGasPriceButtonGroupProp: 'foo',
|
|
|
|
anotherGasPriceButtonGroupProp: 'bar',
|
|
|
|
}}
|
|
|
|
/>
|
2020-02-15 21:34:12 +01:00
|
|
|
), { context: { t: (str) => str + '_t', metricsEvent: () => ({}) } })
|
2020-02-11 17:51:13 +01:00
|
|
|
})
|
2018-05-10 18:17:05 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
afterEach(function () {
|
|
|
|
propsMethodSpies.resetGasButtons.resetHistory()
|
|
|
|
})
|
2018-05-10 18:17:05 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('should render a SendRowWrapper component', function () {
|
2018-05-10 18:17:05 +02:00
|
|
|
assert.equal(wrapper.find(SendRowWrapper).length, 1)
|
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('should pass the correct props to SendRowWrapper', function () {
|
2018-05-10 18:17:05 +02:00
|
|
|
const {
|
|
|
|
label,
|
2018-06-29 19:19:40 +02:00
|
|
|
showError,
|
|
|
|
errorType,
|
2018-05-10 18:17:05 +02:00
|
|
|
} = wrapper.find(SendRowWrapper).props()
|
|
|
|
|
2018-09-20 06:16:43 +02:00
|
|
|
assert.equal(label, 'transactionFee_t:')
|
2020-01-15 22:14:47 +01:00
|
|
|
assert.equal(showError, true)
|
2018-06-29 19:19:40 +02:00
|
|
|
assert.equal(errorType, 'gasFee')
|
2018-05-10 18:17:05 +02:00
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('should render a GasFeeDisplay as a child of the SendRowWrapper', function () {
|
2018-05-10 18:17:05 +02:00
|
|
|
assert(wrapper.find(SendRowWrapper).childAt(0).is(GasFeeDisplay))
|
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('should render the GasFeeDisplay', function () {
|
2018-05-10 18:17:05 +02:00
|
|
|
const {
|
|
|
|
gasLoadingError,
|
|
|
|
gasTotal,
|
2018-11-05 18:01:46 +01:00
|
|
|
onReset,
|
2018-05-10 18:17:05 +02:00
|
|
|
} = wrapper.find(SendRowWrapper).childAt(0).props()
|
|
|
|
assert.equal(gasLoadingError, false)
|
2018-05-14 11:31:41 +02:00
|
|
|
assert.equal(gasTotal, 'mockGasTotal')
|
2018-11-05 18:01:46 +01:00
|
|
|
assert.equal(propsMethodSpies.resetGasButtons.callCount, 0)
|
|
|
|
onReset()
|
|
|
|
assert.equal(propsMethodSpies.resetGasButtons.callCount, 1)
|
2018-05-10 18:17:05 +02:00
|
|
|
})
|
2018-09-20 06:16:43 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('should render the GasPriceButtonGroup if gasButtonGroupShown is true', function () {
|
2018-09-20 06:16:43 +02:00
|
|
|
wrapper.setProps({ gasButtonGroupShown: true })
|
|
|
|
const rendered = wrapper.find(SendRowWrapper).childAt(0)
|
|
|
|
assert.equal(rendered.children().length, 2)
|
|
|
|
|
|
|
|
const gasPriceButtonGroup = rendered.childAt(0)
|
|
|
|
assert(gasPriceButtonGroup.is(GasPriceButtonGroup))
|
|
|
|
assert(gasPriceButtonGroup.hasClass('gas-price-button-group--small'))
|
|
|
|
assert.equal(gasPriceButtonGroup.props().showCheck, false)
|
|
|
|
assert.equal(gasPriceButtonGroup.props().someGasPriceButtonGroupProp, 'foo')
|
|
|
|
assert.equal(gasPriceButtonGroup.props().anotherGasPriceButtonGroupProp, 'bar')
|
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('should render an advanced options button if gasButtonGroupShown is true', function () {
|
2018-09-20 06:16:43 +02:00
|
|
|
wrapper.setProps({ gasButtonGroupShown: true })
|
|
|
|
const rendered = wrapper.find(SendRowWrapper).childAt(0)
|
|
|
|
assert.equal(rendered.children().length, 2)
|
|
|
|
|
|
|
|
const advancedOptionsButton = rendered.childAt(1)
|
|
|
|
assert.equal(advancedOptionsButton.text(), 'advancedOptions_t')
|
|
|
|
|
|
|
|
assert.equal(propsMethodSpies.showCustomizeGasModal.callCount, 0)
|
|
|
|
advancedOptionsButton.props().onClick()
|
|
|
|
assert.equal(propsMethodSpies.showCustomizeGasModal.callCount, 1)
|
|
|
|
})
|
2018-05-10 18:17:05 +02:00
|
|
|
})
|
|
|
|
})
|