1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-12 04:37:13 +01:00
metamask-extension/ui/app/pages/send/send-content/send-amount-row/amount-max-button/tests/amount-max-button-component.test.js

93 lines
2.8 KiB
JavaScript
Raw Normal View History

import assert from 'assert';
import React from 'react';
import { shallow } from 'enzyme';
import sinon from 'sinon';
import AmountMaxButton from '../amount-max-button.component';
describe('AmountMaxButton Component', function () {
let wrapper;
let instance;
const propsMethodSpies = {
setAmountToMax: sinon.spy(),
setMaxModeTo: sinon.spy(),
};
const MOCK_EVENT = { preventDefault: () => undefined };
before(function () {
sinon.spy(AmountMaxButton.prototype, 'setMaxAmount');
});
beforeEach(function () {
2020-11-03 00:41:28 +01:00
wrapper = shallow(
<AmountMaxButton
balance="mockBalance"
gasTotal="mockGasTotal"
maxModeOn={false}
2020-11-03 00:41:28 +01:00
sendToken={{ address: 'mockTokenAddress' }}
setAmountToMax={propsMethodSpies.setAmountToMax}
setMaxModeTo={propsMethodSpies.setMaxModeTo}
tokenBalance="mockTokenBalance"
2020-11-03 00:41:28 +01:00
/>,
{
context: {
t: (str) => `${str}_t`,
metricsEvent: () => undefined,
},
},
);
instance = wrapper.instance();
});
afterEach(function () {
propsMethodSpies.setAmountToMax.resetHistory();
propsMethodSpies.setMaxModeTo.resetHistory();
AmountMaxButton.prototype.setMaxAmount.resetHistory();
});
after(function () {
sinon.restore();
});
describe('setMaxAmount', function () {
it('should call setAmountToMax with the correct params', function () {
assert.strictEqual(propsMethodSpies.setAmountToMax.callCount, 0);
instance.setMaxAmount();
assert.strictEqual(propsMethodSpies.setAmountToMax.callCount, 1);
assert.deepStrictEqual(propsMethodSpies.setAmountToMax.getCall(0).args, [
2020-11-03 00:41:28 +01:00
{
balance: 'mockBalance',
gasTotal: 'mockGasTotal',
sendToken: { address: 'mockTokenAddress' },
tokenBalance: 'mockTokenBalance',
2020-11-03 00:41:28 +01:00
},
]);
});
});
describe('render', function () {
it('should render an element with a send-v2__amount-max class', function () {
assert(wrapper.exists('.send-v2__amount-max'));
});
it('should call setMaxModeTo and setMaxAmount when the checkbox is checked', function () {
const { onClick } = wrapper.find('.send-v2__amount-max').props();
assert.strictEqual(AmountMaxButton.prototype.setMaxAmount.callCount, 0);
assert.strictEqual(propsMethodSpies.setMaxModeTo.callCount, 0);
onClick(MOCK_EVENT);
assert.strictEqual(AmountMaxButton.prototype.setMaxAmount.callCount, 1);
assert.strictEqual(propsMethodSpies.setMaxModeTo.callCount, 1);
assert.deepStrictEqual(propsMethodSpies.setMaxModeTo.getCall(0).args, [
true,
]);
});
it('should render the expected text when maxModeOn is false', function () {
wrapper.setProps({ maxModeOn: false });
assert.strictEqual(wrapper.find('.send-v2__amount-max').text(), 'max_t');
});
});
});