mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-24 19:10:22 +01:00
0e9c8fb5cc
* Changed max button to checkbox, disabled input if max mode is on, recalculate price according to gas fee if max mode is on * Disabled insufficient funds message in the modal if max mode is on, displays proper amounts in modal when max mode is on, sets the send amount according to custom gas price after gas modal save, resets the send amount after resetting custom gas price * Disabled max mode checkbox if gas buttons are loading, refactored gas-modal-page-container * Implemented new max button & max mode message. Moved insufficient funds error to underneath the send amount field * Fixed existing integration test to pass, created new tests to ensure send amount field is disabled when max button is clicked and the amount changes when the gas price is changed. Refactored some components
94 lines
2.7 KiB
JavaScript
94 lines
2.7 KiB
JavaScript
import assert from 'assert'
|
|
import proxyquire from 'proxyquire'
|
|
import sinon from 'sinon'
|
|
|
|
let mapStateToProps
|
|
let mapDispatchToProps
|
|
|
|
const actionSpies = {
|
|
setMaxModeTo: sinon.spy(),
|
|
updateSendAmount: sinon.spy(),
|
|
}
|
|
const duckActionSpies = {
|
|
updateSendErrors: sinon.spy(),
|
|
}
|
|
|
|
proxyquire('../amount-max-button.container.js', {
|
|
'react-redux': {
|
|
connect: (ms, md) => {
|
|
mapStateToProps = ms
|
|
mapDispatchToProps = md
|
|
return () => ({})
|
|
},
|
|
},
|
|
'../../../send.selectors.js': {
|
|
getGasTotal: (s) => `mockGasTotal:${s}`,
|
|
getSelectedToken: (s) => `mockSelectedToken:${s}`,
|
|
getSendFromBalance: (s) => `mockBalance:${s}`,
|
|
getTokenBalance: (s) => `mockTokenBalance:${s}`,
|
|
},
|
|
'./amount-max-button.selectors.js': { getMaxModeOn: (s) => `mockMaxModeOn:${s}` },
|
|
'./amount-max-button.utils.js': { calcMaxAmount: (mockObj) => mockObj.val + 1 },
|
|
'../../../../../selectors/custom-gas': { getBasicGasEstimateLoadingStatus: (s) => `mockButtonDataLoading:${s}`},
|
|
'../../../../../store/actions': actionSpies,
|
|
'../../../../../ducks/send/send.duck': duckActionSpies,
|
|
})
|
|
|
|
describe('amount-max-button container', () => {
|
|
|
|
describe('mapStateToProps()', () => {
|
|
|
|
it('should map the correct properties to props', () => {
|
|
assert.deepEqual(mapStateToProps('mockState'), {
|
|
balance: 'mockBalance:mockState',
|
|
buttonDataLoading: 'mockButtonDataLoading:mockState',
|
|
gasTotal: 'mockGasTotal:mockState',
|
|
maxModeOn: 'mockMaxModeOn:mockState',
|
|
selectedToken: 'mockSelectedToken:mockState',
|
|
tokenBalance: 'mockTokenBalance:mockState',
|
|
})
|
|
})
|
|
|
|
})
|
|
|
|
describe('mapDispatchToProps()', () => {
|
|
let dispatchSpy
|
|
let mapDispatchToPropsObject
|
|
|
|
beforeEach(() => {
|
|
dispatchSpy = sinon.spy()
|
|
mapDispatchToPropsObject = mapDispatchToProps(dispatchSpy)
|
|
})
|
|
|
|
describe('setAmountToMax()', () => {
|
|
it('should dispatch an action', () => {
|
|
mapDispatchToPropsObject.setAmountToMax({ val: 11, foo: 'bar' })
|
|
assert(dispatchSpy.calledTwice)
|
|
assert(duckActionSpies.updateSendErrors.calledOnce)
|
|
assert.deepEqual(
|
|
duckActionSpies.updateSendErrors.getCall(0).args[0],
|
|
{ amount: null }
|
|
)
|
|
assert(actionSpies.updateSendAmount.calledOnce)
|
|
assert.equal(
|
|
actionSpies.updateSendAmount.getCall(0).args[0],
|
|
12
|
|
)
|
|
})
|
|
})
|
|
|
|
describe('setMaxModeTo()', () => {
|
|
it('should dispatch an action', () => {
|
|
mapDispatchToPropsObject.setMaxModeTo('mockVal')
|
|
assert(dispatchSpy.calledOnce)
|
|
assert.equal(
|
|
actionSpies.setMaxModeTo.getCall(0).args[0],
|
|
'mockVal'
|
|
)
|
|
})
|
|
})
|
|
|
|
})
|
|
|
|
})
|