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
90 lines
2.6 KiB
JavaScript
90 lines
2.6 KiB
JavaScript
import React from 'react'
|
|
import assert from 'assert'
|
|
import { shallow } from 'enzyme'
|
|
import sinon from 'sinon'
|
|
import AmountMaxButton from '../amount-max-button.component.js'
|
|
|
|
const propsMethodSpies = {
|
|
setAmountToMax: sinon.spy(),
|
|
setMaxModeTo: sinon.spy(),
|
|
}
|
|
|
|
const MOCK_EVENT = { preventDefault: () => {} }
|
|
|
|
sinon.spy(AmountMaxButton.prototype, 'setMaxAmount')
|
|
|
|
describe('AmountMaxButton Component', function () {
|
|
let wrapper
|
|
let instance
|
|
|
|
beforeEach(() => {
|
|
wrapper = shallow(<AmountMaxButton
|
|
balance={'mockBalance'}
|
|
gasTotal={'mockGasTotal'}
|
|
maxModeOn={false}
|
|
selectedToken={ { address: 'mockTokenAddress' } }
|
|
setAmountToMax={propsMethodSpies.setAmountToMax}
|
|
setMaxModeTo={propsMethodSpies.setMaxModeTo}
|
|
tokenBalance={'mockTokenBalance'}
|
|
/>, {
|
|
context: {
|
|
t: str => str + '_t',
|
|
metricsEvent: () => {},
|
|
},
|
|
})
|
|
instance = wrapper.instance()
|
|
})
|
|
|
|
afterEach(() => {
|
|
propsMethodSpies.setAmountToMax.resetHistory()
|
|
propsMethodSpies.setMaxModeTo.resetHistory()
|
|
AmountMaxButton.prototype.setMaxAmount.resetHistory()
|
|
})
|
|
|
|
describe('setMaxAmount', () => {
|
|
|
|
it('should call setAmountToMax with the correct params', () => {
|
|
assert.equal(propsMethodSpies.setAmountToMax.callCount, 0)
|
|
instance.setMaxAmount()
|
|
assert.equal(propsMethodSpies.setAmountToMax.callCount, 1)
|
|
assert.deepEqual(
|
|
propsMethodSpies.setAmountToMax.getCall(0).args,
|
|
[{
|
|
balance: 'mockBalance',
|
|
gasTotal: 'mockGasTotal',
|
|
selectedToken: { address: 'mockTokenAddress' },
|
|
tokenBalance: 'mockTokenBalance',
|
|
}]
|
|
)
|
|
})
|
|
|
|
})
|
|
|
|
describe('render', () => {
|
|
it('should render an element with a send-v2__amount-max class', () => {
|
|
assert(wrapper.exists('.send-v2__amount-max'))
|
|
})
|
|
|
|
it('should call setMaxModeTo and setMaxAmount when the checkbox is checked', () => {
|
|
const {
|
|
onClick,
|
|
} = wrapper.find('.send-v2__amount-max').props()
|
|
|
|
assert.equal(AmountMaxButton.prototype.setMaxAmount.callCount, 0)
|
|
assert.equal(propsMethodSpies.setMaxModeTo.callCount, 0)
|
|
onClick(MOCK_EVENT)
|
|
assert.equal(AmountMaxButton.prototype.setMaxAmount.callCount, 1)
|
|
assert.equal(propsMethodSpies.setMaxModeTo.callCount, 1)
|
|
assert.deepEqual(
|
|
propsMethodSpies.setMaxModeTo.getCall(0).args,
|
|
[true]
|
|
)
|
|
})
|
|
|
|
it('should render the expected text when maxModeOn is false', () => {
|
|
wrapper.setProps({ maxModeOn: false })
|
|
assert.equal(wrapper.find('.send-v2__amount-max').text(), 'max_t')
|
|
})
|
|
})
|
|
})
|