1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-24 11:01:41 +01:00
metamask-extension/ui/app/pages/send/tests/send-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

123 lines
3.4 KiB
JavaScript

import assert from 'assert'
import proxyquire from 'proxyquire'
import sinon from 'sinon'
let mapDispatchToProps
const actionSpies = {
updateSendTokenBalance: sinon.spy(),
updateGasData: sinon.spy(),
setGasTotal: sinon.spy(),
}
const duckActionSpies = {
updateSendErrors: sinon.spy(),
resetSendState: sinon.spy(),
}
proxyquire('../send.container.js', {
'react-redux': {
connect: (_, md) => {
mapDispatchToProps = md
return () => ({})
},
},
'react-router-dom': { withRouter: () => {} },
'recompose': { compose: (_, arg2) => () => arg2() },
'../../store/actions': actionSpies,
'../../ducks/send/send.duck': duckActionSpies,
'./send.utils.js': {
calcGasTotal: (gasLimit, gasPrice) => gasLimit + gasPrice,
},
})
describe('send container', () => {
describe('mapDispatchToProps()', () => {
let dispatchSpy
let mapDispatchToPropsObject
beforeEach(() => {
dispatchSpy = sinon.spy()
mapDispatchToPropsObject = mapDispatchToProps(dispatchSpy)
})
describe('updateAndSetGasLimit()', () => {
const mockProps = {
blockGasLimit: 'mockBlockGasLimit',
editingTransactionId: '0x2',
gasLimit: '0x3',
gasPrice: '0x4',
recentBlocks: ['mockBlock'],
selectedAddress: '0x4',
selectedToken: { address: '0x1' },
to: 'mockTo',
value: 'mockValue',
data: undefined,
}
it('should dispatch a setGasTotal action when editingTransactionId is truthy', () => {
mapDispatchToPropsObject.updateAndSetGasLimit(mockProps)
assert(dispatchSpy.calledOnce)
assert.equal(
actionSpies.setGasTotal.getCall(0).args[0],
'0x30x4'
)
})
it('should dispatch an updateGasData action when editingTransactionId is falsy', () => {
const { gasPrice, selectedAddress, selectedToken, recentBlocks, blockGasLimit, to, value, data } = mockProps
mapDispatchToPropsObject.updateAndSetGasLimit(
Object.assign({}, mockProps, { editingTransactionId: false })
)
assert(dispatchSpy.calledOnce)
assert.deepEqual(
actionSpies.updateGasData.getCall(0).args[0],
{ gasPrice, selectedAddress, selectedToken, recentBlocks, blockGasLimit, to, value, data }
)
})
})
describe('updateSendTokenBalance()', () => {
const mockProps = {
address: '0x10',
tokenContract: '0x00a',
selectedToken: { address: '0x1' },
}
it('should dispatch an action', () => {
mapDispatchToPropsObject.updateSendTokenBalance(Object.assign({}, mockProps))
assert(dispatchSpy.calledOnce)
assert.deepEqual(
actionSpies.updateSendTokenBalance.getCall(0).args[0],
mockProps
)
})
})
describe('updateSendErrors()', () => {
it('should dispatch an action', () => {
mapDispatchToPropsObject.updateSendErrors('mockError')
assert(dispatchSpy.calledOnce)
assert.equal(
duckActionSpies.updateSendErrors.getCall(0).args[0],
'mockError'
)
})
})
describe('resetSendState()', () => {
it('should dispatch an action', () => {
mapDispatchToPropsObject.resetSendState()
assert(dispatchSpy.calledOnce)
assert.equal(
duckActionSpies.resetSendState.getCall(0).args.length,
0
)
})
})
})
})