You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
207 lines
5.9 KiB
207 lines
5.9 KiB
4 years ago
|
import React from 'react';
|
||
|
import { shallow } from 'enzyme';
|
||
|
import sinon from 'sinon';
|
||
4 years ago
|
import Dialog from '../../../../components/ui/dialog';
|
||
|
import AddRecipient from './add-recipient.component';
|
||
5 years ago
|
|
||
|
const propsMethodSpies = {
|
||
|
closeToDropdown: sinon.spy(),
|
||
|
openToDropdown: sinon.spy(),
|
||
|
updateGas: sinon.spy(),
|
||
|
updateSendTo: sinon.spy(),
|
||
|
updateSendToError: sinon.spy(),
|
||
|
updateSendToWarning: sinon.spy(),
|
||
4 years ago
|
};
|
||
5 years ago
|
|
||
4 years ago
|
describe('AddRecipient Component', () => {
|
||
4 years ago
|
let wrapper;
|
||
|
let instance;
|
||
5 years ago
|
|
||
4 years ago
|
beforeEach(() => {
|
||
4 years ago
|
wrapper = shallow(
|
||
5 years ago
|
<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}
|
||
4 years ago
|
addressBook={[
|
||
|
{
|
||
|
address: '0x80F061544cC398520615B5d3e7A3BedD70cd4510',
|
||
|
name: 'Fav 5',
|
||
|
},
|
||
|
]}
|
||
|
nonContacts={[
|
||
|
{
|
||
|
address: '0x70F061544cC398520615B5d3e7A3BedD70cd4510',
|
||
|
name: 'Fav 7',
|
||
|
},
|
||
|
]}
|
||
|
contacts={[
|
||
|
{
|
||
|
address: '0x60F061544cC398520615B5d3e7A3BedD70cd4510',
|
||
|
name: 'Fav 6',
|
||
|
},
|
||
|
]}
|
||
|
/>,
|
||
|
{ context: { t: (str) => `${str}_t` } },
|
||
4 years ago
|
);
|
||
|
instance = wrapper.instance();
|
||
|
});
|
||
5 years ago
|
|
||
4 years ago
|
afterEach(() => {
|
||
4 years ago
|
propsMethodSpies.closeToDropdown.resetHistory();
|
||
|
propsMethodSpies.openToDropdown.resetHistory();
|
||
|
propsMethodSpies.updateSendTo.resetHistory();
|
||
|
propsMethodSpies.updateSendToError.resetHistory();
|
||
|
propsMethodSpies.updateSendToWarning.resetHistory();
|
||
|
propsMethodSpies.updateGas.resetHistory();
|
||
|
});
|
||
5 years ago
|
|
||
4 years ago
|
describe('selectRecipient', () => {
|
||
|
it('should call updateSendTo', () => {
|
||
|
expect(propsMethodSpies.updateSendTo.callCount).toStrictEqual(0);
|
||
4 years ago
|
instance.selectRecipient('mockTo2', 'mockNickname');
|
||
4 years ago
|
expect(propsMethodSpies.updateSendTo.callCount).toStrictEqual(1);
|
||
|
expect(propsMethodSpies.updateSendTo.getCall(0).args).toStrictEqual([
|
||
4 years ago
|
'mockTo2',
|
||
|
'mockNickname',
|
||
4 years ago
|
]);
|
||
|
});
|
||
5 years ago
|
|
||
4 years ago
|
it('should call updateGas if there is no to error', () => {
|
||
|
expect(propsMethodSpies.updateGas.callCount).toStrictEqual(0);
|
||
4 years ago
|
instance.selectRecipient(false);
|
||
4 years ago
|
expect(propsMethodSpies.updateGas.callCount).toStrictEqual(1);
|
||
4 years ago
|
});
|
||
|
});
|
||
5 years ago
|
|
||
4 years ago
|
describe('render', () => {
|
||
|
it('should render a component', () => {
|
||
|
expect(wrapper.find('.send__select-recipient-wrapper')).toHaveLength(1);
|
||
4 years ago
|
});
|
||
5 years ago
|
|
||
4 years ago
|
it('should render no content if there are no recents, transfers, and contacts', () => {
|
||
5 years ago
|
wrapper.setProps({
|
||
|
ownedAccounts: [],
|
||
|
addressBook: [],
|
||
4 years ago
|
});
|
||
5 years ago
|
|
||
4 years ago
|
expect(
|
||
|
wrapper.find('.send__select-recipient-wrapper__list__link'),
|
||
|
).toHaveLength(0);
|
||
|
expect(
|
||
|
wrapper.find('.send__select-recipient-wrapper__group'),
|
||
|
).toHaveLength(0);
|
||
4 years ago
|
});
|
||
5 years ago
|
|
||
4 years ago
|
it('should render transfer', () => {
|
||
5 years ago
|
wrapper.setProps({
|
||
4 years ago
|
ownedAccounts: [
|
||
|
{ address: '0x123', name: '123' },
|
||
|
{ address: '0x124', name: '124' },
|
||
|
],
|
||
5 years ago
|
addressBook: [{ address: '0x456', name: 'test-name' }],
|
||
4 years ago
|
});
|
||
|
wrapper.setState({ isShowingTransfer: true });
|
||
5 years ago
|
|
||
4 years ago
|
const xferLink = wrapper.find(
|
||
|
'.send__select-recipient-wrapper__list__link',
|
||
4 years ago
|
);
|
||
4 years ago
|
expect(xferLink).toHaveLength(1);
|
||
5 years ago
|
|
||
4 years ago
|
const groups = wrapper.find('RecipientGroup');
|
||
4 years ago
|
expect(
|
||
|
groups.shallow().find('.send__select-recipient-wrapper__group'),
|
||
|
).toHaveLength(1);
|
||
4 years ago
|
});
|
||
5 years ago
|
|
||
4 years ago
|
it('should render ContactList', () => {
|
||
5 years ago
|
wrapper.setProps({
|
||
4 years ago
|
ownedAccounts: [
|
||
|
{ address: '0x123', name: '123' },
|
||
|
{ address: '0x124', name: '124' },
|
||
|
],
|
||
5 years ago
|
addressBook: [{ address: '0x125' }],
|
||
4 years ago
|
});
|
||
5 years ago
|
|
||
4 years ago
|
const contactList = wrapper.find('ContactList');
|
||
5 years ago
|
|
||
4 years ago
|
expect(contactList).toHaveLength(1);
|
||
4 years ago
|
});
|
||
5 years ago
|
|
||
4 years ago
|
it('should render contacts', () => {
|
||
5 years ago
|
wrapper.setProps({
|
||
|
addressBook: [
|
||
|
{ address: '0x125', name: 'alice' },
|
||
|
{ address: '0x126', name: 'alex' },
|
||
|
{ address: '0x127', name: 'catherine' },
|
||
|
],
|
||
4 years ago
|
});
|
||
|
wrapper.setState({ isShowingTransfer: false });
|
||
5 years ago
|
|
||
4 years ago
|
const xferLink = wrapper.find(
|
||
|
'.send__select-recipient-wrapper__list__link',
|
||
4 years ago
|
);
|
||
4 years ago
|
expect(xferLink).toHaveLength(0);
|
||
5 years ago
|
|
||
4 years ago
|
const groups = wrapper.find('ContactList');
|
||
4 years ago
|
expect(groups).toHaveLength(1);
|
||
5 years ago
|
|
||
4 years ago
|
expect(
|
||
|
groups.find('.send__select-recipient-wrapper__group-item'),
|
||
|
).toHaveLength(0);
|
||
4 years ago
|
});
|
||
5 years ago
|
|
||
4 years ago
|
it('should render error when query has no results', () => {
|
||
5 years ago
|
wrapper.setProps({
|
||
|
addressBook: [],
|
||
|
toError: 'bad',
|
||
|
contacts: [],
|
||
|
nonContacts: [],
|
||
4 years ago
|
});
|
||
5 years ago
|
|
||
4 years ago
|
const dialog = wrapper.find(Dialog);
|
||
5 years ago
|
|
||
4 years ago
|
expect(dialog.props().type).toStrictEqual('error');
|
||
|
expect(dialog.props().children).toStrictEqual('bad_t');
|
||
|
expect(dialog).toHaveLength(1);
|
||
4 years ago
|
});
|
||
5 years ago
|
|
||
4 years ago
|
it('should render error when query has ens does not resolve', () => {
|
||
5 years ago
|
wrapper.setProps({
|
||
|
addressBook: [],
|
||
|
toError: 'bad',
|
||
|
ensResolutionError: 'very bad',
|
||
|
contacts: [],
|
||
|
nonContacts: [],
|
||
4 years ago
|
});
|
||
5 years ago
|
|
||
4 years ago
|
const dialog = wrapper.find(Dialog);
|
||
5 years ago
|
|
||
4 years ago
|
expect(dialog.props().type).toStrictEqual('error');
|
||
|
expect(dialog.props().children).toStrictEqual('very bad');
|
||
|
expect(dialog).toHaveLength(1);
|
||
4 years ago
|
});
|
||
5 years ago
|
|
||
4 years ago
|
it('should not render error when ens resolved', () => {
|
||
5 years ago
|
wrapper.setProps({
|
||
|
addressBook: [],
|
||
|
toError: 'bad',
|
||
|
ensResolution: '0x128',
|
||
4 years ago
|
});
|
||
5 years ago
|
|
||
4 years ago
|
const dialog = wrapper.find(Dialog);
|
||
5 years ago
|
|
||
4 years ago
|
expect(dialog).toHaveLength(0);
|
||
4 years ago
|
});
|
||
|
});
|
||
|
});
|