2021-02-04 19:15:23 +01:00
|
|
|
import assert from 'assert';
|
|
|
|
import React from 'react';
|
|
|
|
import { shallow } from 'enzyme';
|
|
|
|
import sinon from 'sinon';
|
|
|
|
import AddRecipient from '../add-recipient.component';
|
|
|
|
import Dialog from '../../../../../components/ui/dialog';
|
2019-07-31 21:56:44 +02:00
|
|
|
|
|
|
|
const propsMethodSpies = {
|
|
|
|
closeToDropdown: sinon.spy(),
|
|
|
|
openToDropdown: sinon.spy(),
|
|
|
|
updateGas: sinon.spy(),
|
|
|
|
updateSendTo: sinon.spy(),
|
|
|
|
updateSendToError: sinon.spy(),
|
|
|
|
updateSendToWarning: sinon.spy(),
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2019-07-31 21:56:44 +02:00
|
|
|
|
|
|
|
describe('AddRecipient Component', function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
let wrapper;
|
|
|
|
let instance;
|
2019-07-31 21:56:44 +02:00
|
|
|
|
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
|
|
|
<AddRecipient
|
|
|
|
closeToDropdown={propsMethodSpies.closeToDropdown}
|
|
|
|
inError={false}
|
|
|
|
inWarning={false}
|
|
|
|
network="mockNetwork"
|
|
|
|
openToDropdown={propsMethodSpies.openToDropdown}
|
|
|
|
to="mockTo"
|
|
|
|
toAccounts={['mockAccount']}
|
|
|
|
toDropdownOpen={false}
|
|
|
|
updateGas={propsMethodSpies.updateGas}
|
|
|
|
updateSendTo={propsMethodSpies.updateSendTo}
|
|
|
|
updateSendToError={propsMethodSpies.updateSendToError}
|
|
|
|
updateSendToWarning={propsMethodSpies.updateSendToWarning}
|
2020-11-03 00:41:28 +01:00
|
|
|
addressBook={[
|
|
|
|
{
|
|
|
|
address: '0x80F061544cC398520615B5d3e7A3BedD70cd4510',
|
|
|
|
name: 'Fav 5',
|
|
|
|
},
|
|
|
|
]}
|
|
|
|
nonContacts={[
|
|
|
|
{
|
|
|
|
address: '0x70F061544cC398520615B5d3e7A3BedD70cd4510',
|
|
|
|
name: 'Fav 7',
|
|
|
|
},
|
|
|
|
]}
|
|
|
|
contacts={[
|
|
|
|
{
|
|
|
|
address: '0x60F061544cC398520615B5d3e7A3BedD70cd4510',
|
|
|
|
name: 'Fav 6',
|
|
|
|
},
|
|
|
|
]}
|
|
|
|
/>,
|
|
|
|
{ context: { t: (str) => `${str}_t` } },
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
instance = wrapper.instance();
|
|
|
|
});
|
2019-07-31 21:56:44 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
afterEach(function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
propsMethodSpies.closeToDropdown.resetHistory();
|
|
|
|
propsMethodSpies.openToDropdown.resetHistory();
|
|
|
|
propsMethodSpies.updateSendTo.resetHistory();
|
|
|
|
propsMethodSpies.updateSendToError.resetHistory();
|
|
|
|
propsMethodSpies.updateSendToWarning.resetHistory();
|
|
|
|
propsMethodSpies.updateGas.resetHistory();
|
|
|
|
});
|
2019-07-31 21:56:44 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('selectRecipient', function () {
|
|
|
|
it('should call updateSendTo', function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
assert.strictEqual(propsMethodSpies.updateSendTo.callCount, 0);
|
|
|
|
instance.selectRecipient('mockTo2', 'mockNickname');
|
|
|
|
assert.strictEqual(propsMethodSpies.updateSendTo.callCount, 1);
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.deepStrictEqual(propsMethodSpies.updateSendTo.getCall(0).args, [
|
2020-11-03 00:41:28 +01:00
|
|
|
'mockTo2',
|
|
|
|
'mockNickname',
|
2021-02-04 19:15:23 +01:00
|
|
|
]);
|
|
|
|
});
|
2019-07-31 21:56:44 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('should call updateGas if there is no to error', function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
assert.strictEqual(propsMethodSpies.updateGas.callCount, 0);
|
|
|
|
instance.selectRecipient(false);
|
|
|
|
assert.strictEqual(propsMethodSpies.updateGas.callCount, 1);
|
|
|
|
});
|
|
|
|
});
|
2019-07-31 21:56:44 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('render', function () {
|
|
|
|
it('should render a component', function () {
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.strictEqual(
|
|
|
|
wrapper.find('.send__select-recipient-wrapper').length,
|
|
|
|
1,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
});
|
2019-07-31 21:56:44 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('should render no content if there are no recents, transfers, and contacts', function () {
|
2019-07-31 21:56:44 +02:00
|
|
|
wrapper.setProps({
|
|
|
|
ownedAccounts: [],
|
|
|
|
addressBook: [],
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2019-07-31 21:56:44 +02:00
|
|
|
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.strictEqual(
|
2020-11-03 00:41:28 +01:00
|
|
|
wrapper.find('.send__select-recipient-wrapper__list__link').length,
|
|
|
|
0,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.strictEqual(
|
2020-11-03 00:41:28 +01:00
|
|
|
wrapper.find('.send__select-recipient-wrapper__group').length,
|
|
|
|
0,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
});
|
2019-07-31 21:56:44 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('should render transfer', function () {
|
2019-07-31 21:56:44 +02:00
|
|
|
wrapper.setProps({
|
2020-11-03 00:41:28 +01:00
|
|
|
ownedAccounts: [
|
|
|
|
{ address: '0x123', name: '123' },
|
|
|
|
{ address: '0x124', name: '124' },
|
|
|
|
],
|
2019-07-31 21:56:44 +02:00
|
|
|
addressBook: [{ address: '0x456', name: 'test-name' }],
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
wrapper.setState({ isShowingTransfer: true });
|
2019-07-31 21:56:44 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
const xferLink = wrapper.find(
|
|
|
|
'.send__select-recipient-wrapper__list__link',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
assert.strictEqual(xferLink.length, 1);
|
2019-07-31 21:56:44 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const groups = wrapper.find('RecipientGroup');
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.strictEqual(
|
2020-11-03 00:41:28 +01:00
|
|
|
groups.shallow().find('.send__select-recipient-wrapper__group').length,
|
|
|
|
1,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
});
|
2019-07-31 21:56:44 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('should render ContactList', function () {
|
2019-07-31 21:56:44 +02:00
|
|
|
wrapper.setProps({
|
2020-11-03 00:41:28 +01:00
|
|
|
ownedAccounts: [
|
|
|
|
{ address: '0x123', name: '123' },
|
|
|
|
{ address: '0x124', name: '124' },
|
|
|
|
],
|
2019-07-31 21:56:44 +02:00
|
|
|
addressBook: [{ address: '0x125' }],
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2019-07-31 21:56:44 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const contactList = wrapper.find('ContactList');
|
2019-07-31 21:56:44 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
assert.strictEqual(contactList.length, 1);
|
|
|
|
});
|
2019-07-31 21:56:44 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('should render contacts', function () {
|
2019-07-31 21:56:44 +02:00
|
|
|
wrapper.setProps({
|
|
|
|
addressBook: [
|
|
|
|
{ address: '0x125', name: 'alice' },
|
|
|
|
{ address: '0x126', name: 'alex' },
|
|
|
|
{ address: '0x127', name: 'catherine' },
|
|
|
|
],
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
wrapper.setState({ isShowingTransfer: false });
|
2019-07-31 21:56:44 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
const xferLink = wrapper.find(
|
|
|
|
'.send__select-recipient-wrapper__list__link',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
assert.strictEqual(xferLink.length, 0);
|
2019-07-31 21:56:44 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const groups = wrapper.find('ContactList');
|
|
|
|
assert.strictEqual(groups.length, 1);
|
2019-07-31 21:56:44 +02:00
|
|
|
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.strictEqual(
|
2020-11-03 00:41:28 +01:00
|
|
|
groups.find('.send__select-recipient-wrapper__group-item').length,
|
|
|
|
0,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
});
|
2019-07-31 21:56:44 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('should render error when query has no results', function () {
|
2019-07-31 21:56:44 +02:00
|
|
|
wrapper.setProps({
|
|
|
|
addressBook: [],
|
|
|
|
toError: 'bad',
|
|
|
|
contacts: [],
|
|
|
|
nonContacts: [],
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2019-07-31 21:56:44 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const dialog = wrapper.find(Dialog);
|
2019-07-31 21:56:44 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
assert.strictEqual(dialog.props().type, 'error');
|
|
|
|
assert.strictEqual(dialog.props().children, 'bad_t');
|
|
|
|
assert.strictEqual(dialog.length, 1);
|
|
|
|
});
|
2019-07-31 21:56:44 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('should render error when query has ens does not resolve', function () {
|
2019-07-31 21:56:44 +02:00
|
|
|
wrapper.setProps({
|
|
|
|
addressBook: [],
|
|
|
|
toError: 'bad',
|
|
|
|
ensResolutionError: 'very bad',
|
|
|
|
contacts: [],
|
|
|
|
nonContacts: [],
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2019-07-31 21:56:44 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const dialog = wrapper.find(Dialog);
|
2019-07-31 21:56:44 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
assert.strictEqual(dialog.props().type, 'error');
|
|
|
|
assert.strictEqual(dialog.props().children, 'very bad');
|
|
|
|
assert.strictEqual(dialog.length, 1);
|
|
|
|
});
|
2019-07-31 21:56:44 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('should not render error when ens resolved', function () {
|
2019-07-31 21:56:44 +02:00
|
|
|
wrapper.setProps({
|
|
|
|
addressBook: [],
|
|
|
|
toError: 'bad',
|
|
|
|
ensResolution: '0x128',
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2019-07-31 21:56:44 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const dialog = wrapper.find(Dialog);
|
2019-07-31 21:56:44 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
assert.strictEqual(dialog.length, 0);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|