2018-05-14 11:25:03 +02:00
|
|
|
import assert from 'assert'
|
2020-08-18 21:18:25 +02:00
|
|
|
import React from 'react'
|
2018-05-14 11:25:03 +02:00
|
|
|
import { shallow } from 'enzyme'
|
|
|
|
import sinon from 'sinon'
|
2020-08-14 13:46:45 +02:00
|
|
|
import AmountMaxButton from '../amount-max-button.component'
|
2018-05-14 11:25:03 +02:00
|
|
|
|
|
|
|
describe('AmountMaxButton Component', function () {
|
|
|
|
let wrapper
|
|
|
|
let instance
|
|
|
|
|
2020-02-11 21:33:32 +01:00
|
|
|
const propsMethodSpies = {
|
|
|
|
setAmountToMax: sinon.spy(),
|
|
|
|
setMaxModeTo: sinon.spy(),
|
|
|
|
}
|
|
|
|
|
2020-08-14 13:47:02 +02:00
|
|
|
const MOCK_EVENT = { preventDefault: () => undefined }
|
2020-02-11 21:33:32 +01:00
|
|
|
|
|
|
|
before(function () {
|
|
|
|
sinon.spy(AmountMaxButton.prototype, 'setMaxAmount')
|
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
beforeEach(function () {
|
2020-11-03 00:41:28 +01:00
|
|
|
wrapper = shallow(
|
2019-12-03 17:35:44 +01:00
|
|
|
<AmountMaxButton
|
|
|
|
balance="mockBalance"
|
|
|
|
gasTotal="mockGasTotal"
|
|
|
|
maxModeOn={false}
|
2020-11-03 00:41:28 +01:00
|
|
|
sendToken={{ address: 'mockTokenAddress' }}
|
2019-12-03 17:35:44 +01:00
|
|
|
setAmountToMax={propsMethodSpies.setAmountToMax}
|
|
|
|
setMaxModeTo={propsMethodSpies.setMaxModeTo}
|
|
|
|
tokenBalance="mockTokenBalance"
|
2020-11-03 00:41:28 +01:00
|
|
|
/>,
|
|
|
|
{
|
|
|
|
context: {
|
|
|
|
t: (str) => `${str}_t`,
|
|
|
|
metricsEvent: () => undefined,
|
|
|
|
},
|
2019-05-07 18:12:14 +02:00
|
|
|
},
|
2020-11-03 00:41:28 +01:00
|
|
|
)
|
2018-05-14 11:25:03 +02:00
|
|
|
instance = wrapper.instance()
|
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
afterEach(function () {
|
2018-05-14 11:25:03 +02:00
|
|
|
propsMethodSpies.setAmountToMax.resetHistory()
|
|
|
|
propsMethodSpies.setMaxModeTo.resetHistory()
|
|
|
|
AmountMaxButton.prototype.setMaxAmount.resetHistory()
|
|
|
|
})
|
|
|
|
|
2020-02-11 21:33:32 +01:00
|
|
|
after(function () {
|
|
|
|
sinon.restore()
|
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('setMaxAmount', function () {
|
|
|
|
it('should call setAmountToMax with the correct params', function () {
|
2018-05-14 11:25:03 +02:00
|
|
|
assert.equal(propsMethodSpies.setAmountToMax.callCount, 0)
|
|
|
|
instance.setMaxAmount()
|
|
|
|
assert.equal(propsMethodSpies.setAmountToMax.callCount, 1)
|
2020-11-03 00:41:28 +01:00
|
|
|
assert.deepEqual(propsMethodSpies.setAmountToMax.getCall(0).args, [
|
|
|
|
{
|
2018-05-14 11:25:03 +02:00
|
|
|
balance: 'mockBalance',
|
|
|
|
gasTotal: 'mockGasTotal',
|
2020-05-29 19:46:10 +02:00
|
|
|
sendToken: { address: 'mockTokenAddress' },
|
2018-05-14 11:25:03 +02:00
|
|
|
tokenBalance: 'mockTokenBalance',
|
2020-11-03 00:41:28 +01:00
|
|
|
},
|
|
|
|
])
|
2018-05-14 11:25:03 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('render', function () {
|
|
|
|
it('should render an element with a send-v2__amount-max class', function () {
|
2018-10-16 01:26:24 +02:00
|
|
|
assert(wrapper.exists('.send-v2__amount-max'))
|
2018-05-14 11:25:03 +02:00
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('should call setMaxModeTo and setMaxAmount when the checkbox is checked', function () {
|
2020-11-03 00:41:28 +01:00
|
|
|
const { onClick } = wrapper.find('.send-v2__amount-max').props()
|
2018-05-14 11:25:03 +02:00
|
|
|
|
|
|
|
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)
|
2020-11-03 00:41:28 +01:00
|
|
|
assert.deepEqual(propsMethodSpies.setMaxModeTo.getCall(0).args, [true])
|
2018-05-14 11:25:03 +02:00
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('should render the expected text when maxModeOn is false', function () {
|
2018-05-14 11:25:03 +02:00
|
|
|
wrapper.setProps({ maxModeOn: false })
|
|
|
|
assert.equal(wrapper.find('.send-v2__amount-max').text(), 'max_t')
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|