1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-10-23 11:46:13 +02:00
metamask-extension/ui/app/pages/send/send-content/send-gas-row/tests/send-gas-row-container.test.js
Mark Stacey 49a525b9f8
Add react/no-unused-prop-types ESLint rule (#7655)
* Add `react/no-unused-prop-types` rule

All detected unused prop types have been removed. I have attempted to
ensure these props are no longer passed in either.

* Update handling of props to avoid false positive lint errors

These cases were detected by `react/no-unused-prop-types` as being
unused props, even though they were used. These minor adjustments
prevent them from being flagged as errors.

* Update unit tests

Many of these tests were just checking that specific props were passed
from containers or to a child component. These were deleted, as I can't
imagine how they'd be useful.

* Disable `react/no-unused-prop-types` in `componentWillReceiveProps

The rule `react/no-unused-prop-types` doesn't seem to be detecting
props used within `UNSAFE_componentWillReceiveProps`. The two cases
have been disabled temporarily until we can replace these unsafe
lifecycle functions.
2019-12-07 23:10:47 -04:00

154 lines
4.7 KiB
JavaScript

import assert from 'assert'
import proxyquire from 'proxyquire'
import sinon from 'sinon'
let mapDispatchToProps
let mergeProps
const actionSpies = {
showModal: sinon.spy(),
setGasPrice: sinon.spy(),
setGasTotal: sinon.spy(),
setGasLimit: sinon.spy(),
}
const sendDuckSpies = {
showGasButtonGroup: sinon.spy(),
}
const gasDuckSpies = {
resetCustomData: sinon.spy(),
setCustomGasPrice: sinon.spy(),
setCustomGasLimit: sinon.spy(),
}
proxyquire('../send-gas-row.container.js', {
'react-redux': {
connect: (_, md, mp) => {
mapDispatchToProps = md
mergeProps = mp
return () => ({})
},
},
'../send-amount-row/amount-max-button/amount-max-button.selectors': {
getMaxModeOn: (s) => `mockMaxModeOn:${s}`,
},
'../../send.utils.js': {
isBalanceSufficient: ({
amount,
gasTotal,
balance,
conversionRate,
}) => `${amount}:${gasTotal}:${balance}:${conversionRate}`,
calcGasTotal: (gasLimit, gasPrice) => gasLimit + gasPrice,
},
'../../../../store/actions': actionSpies,
'../../../../ducks/send/send.duck': sendDuckSpies,
'../../../../ducks/gas/gas.duck': gasDuckSpies,
})
describe('send-gas-row container', () => {
describe('mapDispatchToProps()', () => {
let dispatchSpy
let mapDispatchToPropsObject
beforeEach(() => {
dispatchSpy = sinon.spy()
mapDispatchToPropsObject = mapDispatchToProps(dispatchSpy)
actionSpies.setGasTotal.resetHistory()
})
describe('showCustomizeGasModal()', () => {
it('should dispatch an action', () => {
mapDispatchToPropsObject.showCustomizeGasModal()
assert(dispatchSpy.calledOnce)
assert.deepEqual(
actionSpies.showModal.getCall(0).args[0],
{ name: 'CUSTOMIZE_GAS', hideBasic: true }
)
})
})
describe('setGasPrice()', () => {
it('should dispatch an action', () => {
mapDispatchToPropsObject.setGasPrice('mockNewPrice', 'mockLimit')
assert(dispatchSpy.calledThrice)
assert(actionSpies.setGasPrice.calledOnce)
assert.equal(actionSpies.setGasPrice.getCall(0).args[0], 'mockNewPrice')
assert.equal(gasDuckSpies.setCustomGasPrice.getCall(0).args[0], 'mockNewPrice')
assert(actionSpies.setGasTotal.calledOnce)
assert.equal(actionSpies.setGasTotal.getCall(0).args[0], 'mockLimitmockNewPrice')
})
})
describe('setGasLimit()', () => {
it('should dispatch an action', () => {
mapDispatchToPropsObject.setGasLimit('mockNewLimit', 'mockPrice')
assert(dispatchSpy.calledThrice)
assert(actionSpies.setGasLimit.calledOnce)
assert.equal(actionSpies.setGasLimit.getCall(0).args[0], 'mockNewLimit')
assert.equal(gasDuckSpies.setCustomGasLimit.getCall(0).args[0], 'mockNewLimit')
assert(actionSpies.setGasTotal.calledOnce)
assert.equal(actionSpies.setGasTotal.getCall(0).args[0], 'mockNewLimitmockPrice')
})
})
describe('showGasButtonGroup()', () => {
it('should dispatch an action', () => {
mapDispatchToPropsObject.showGasButtonGroup()
assert(dispatchSpy.calledOnce)
assert(sendDuckSpies.showGasButtonGroup.calledOnce)
})
})
describe('resetCustomData()', () => {
it('should dispatch an action', () => {
mapDispatchToPropsObject.resetCustomData()
assert(dispatchSpy.calledOnce)
assert(gasDuckSpies.resetCustomData.calledOnce)
})
})
})
describe('mergeProps', () => {
let stateProps
let dispatchProps
let ownProps
beforeEach(() => {
stateProps = {
gasPriceButtonGroupProps: {
someGasPriceButtonGroupProp: 'foo',
anotherGasPriceButtonGroupProp: 'bar',
},
someOtherStateProp: 'baz',
}
dispatchProps = {
setGasPrice: sinon.spy(),
someOtherDispatchProp: sinon.spy(),
}
ownProps = { someOwnProp: 123 }
})
it('should return the expected props when isConfirm is true', () => {
const result = mergeProps(stateProps, dispatchProps, ownProps)
assert.equal(result.someOtherStateProp, 'baz')
assert.equal(result.gasPriceButtonGroupProps.someGasPriceButtonGroupProp, 'foo')
assert.equal(result.gasPriceButtonGroupProps.anotherGasPriceButtonGroupProp, 'bar')
assert.equal(result.someOwnProp, 123)
assert.equal(dispatchProps.setGasPrice.callCount, 0)
result.gasPriceButtonGroupProps.handleGasPriceSelection()
assert.equal(dispatchProps.setGasPrice.callCount, 1)
assert.equal(dispatchProps.someOtherDispatchProp.callCount, 0)
result.someOtherDispatchProp()
assert.equal(dispatchProps.someOtherDispatchProp.callCount, 1)
})
})
})