2021-02-04 19:15:23 +01:00
|
|
|
import React from 'react';
|
|
|
|
import { shallow } from 'enzyme';
|
|
|
|
import sinon from 'sinon';
|
2021-03-16 22:00:08 +01:00
|
|
|
import Dialog from '../../../../components/ui/dialog';
|
|
|
|
import AddRecipient from './add-recipient.component';
|
2019-07-31 21:56:44 +02:00
|
|
|
|
|
|
|
const propsMethodSpies = {
|
2021-06-23 23:35:25 +02:00
|
|
|
updateRecipient: sinon.spy(),
|
|
|
|
useMyAccountsForRecipientSearch: sinon.spy(),
|
|
|
|
useContactListForRecipientSearch: sinon.spy(),
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2019-07-31 21:56:44 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('AddRecipient Component', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
let wrapper;
|
2019-07-31 21:56:44 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
beforeEach(() => {
|
2020-11-03 00:41:28 +01:00
|
|
|
wrapper = shallow(
|
2019-12-03 17:35:44 +01:00
|
|
|
<AddRecipient
|
2021-06-23 23:35:25 +02:00
|
|
|
userInput=""
|
|
|
|
recipient={{
|
|
|
|
address: '',
|
|
|
|
nickname: '',
|
|
|
|
error: '',
|
|
|
|
warning: '',
|
|
|
|
}}
|
2019-12-03 17:35:44 +01:00
|
|
|
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
|
|
|
);
|
|
|
|
});
|
2019-07-31 21:56:44 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
afterEach(() => {
|
2021-06-23 23:35:25 +02:00
|
|
|
propsMethodSpies.updateRecipient.resetHistory();
|
|
|
|
propsMethodSpies.useMyAccountsForRecipientSearch.resetHistory();
|
|
|
|
propsMethodSpies.useContactListForRecipientSearch.resetHistory();
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2019-07-31 21:56:44 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('render', () => {
|
|
|
|
it('should render a component', () => {
|
|
|
|
expect(wrapper.find('.send__select-recipient-wrapper')).toHaveLength(1);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2019-07-31 21:56:44 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should render no content if there are no recents, transfers, and contacts', () => {
|
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
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(
|
|
|
|
wrapper.find('.send__select-recipient-wrapper__list__link'),
|
|
|
|
).toHaveLength(0);
|
|
|
|
expect(
|
|
|
|
wrapper.find('.send__select-recipient-wrapper__group'),
|
|
|
|
).toHaveLength(0);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2019-07-31 21:56:44 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should render transfer', () => {
|
2019-07-31 21:56:44 +02:00
|
|
|
wrapper.setProps({
|
2021-06-23 23:35:25 +02:00
|
|
|
isUsingMyAccountsForRecipientSearch: true,
|
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
|
|
|
);
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(xferLink).toHaveLength(1);
|
2019-07-31 21:56:44 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const groups = wrapper.find('RecipientGroup');
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(
|
|
|
|
groups.shallow().find('.send__select-recipient-wrapper__group'),
|
|
|
|
).toHaveLength(1);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2019-07-31 21:56:44 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should render ContactList', () => {
|
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-04-15 20:01:46 +02:00
|
|
|
expect(contactList).toHaveLength(1);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2019-07-31 21:56:44 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should render contacts', () => {
|
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
|
|
|
);
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(xferLink).toHaveLength(0);
|
2019-07-31 21:56:44 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const groups = wrapper.find('ContactList');
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(groups).toHaveLength(1);
|
2019-07-31 21:56:44 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(
|
|
|
|
groups.find('.send__select-recipient-wrapper__group-item'),
|
|
|
|
).toHaveLength(0);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2019-07-31 21:56:44 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should render error when query has no results', () => {
|
2019-07-31 21:56:44 +02:00
|
|
|
wrapper.setProps({
|
|
|
|
addressBook: [],
|
2022-11-21 16:19:11 +01:00
|
|
|
domainError: 'bad',
|
2019-07-31 21:56:44 +02:00
|
|
|
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-04-15 20:01:46 +02:00
|
|
|
expect(dialog.props().type).toStrictEqual('error');
|
|
|
|
expect(dialog.props().children).toStrictEqual('bad_t');
|
|
|
|
expect(dialog).toHaveLength(1);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2019-07-31 21:56:44 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should render error when query has ens does not resolve', () => {
|
2019-07-31 21:56:44 +02:00
|
|
|
wrapper.setProps({
|
|
|
|
addressBook: [],
|
2022-11-21 16:19:11 +01:00
|
|
|
domainError: 'very bad',
|
2019-07-31 21:56:44 +02:00
|
|
|
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-04-15 20:01:46 +02:00
|
|
|
expect(dialog.props().type).toStrictEqual('error');
|
2021-06-23 23:35:25 +02:00
|
|
|
expect(dialog.props().children).toStrictEqual('very bad_t');
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(dialog).toHaveLength(1);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2019-07-31 21:56:44 +02:00
|
|
|
|
2021-06-23 23:35:25 +02:00
|
|
|
it('should render error when ens resolved but ens error exists', () => {
|
2019-07-31 21:56:44 +02:00
|
|
|
wrapper.setProps({
|
|
|
|
addressBook: [],
|
2022-11-21 16:19:11 +01:00
|
|
|
domainError: 'bad',
|
|
|
|
domainResolution: '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-06-23 23:35:25 +02:00
|
|
|
expect(dialog).toHaveLength(1);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|