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.
149 lines
5.0 KiB
149 lines
5.0 KiB
4 years ago
|
import React from 'react';
|
||
|
import { shallow } from 'enzyme';
|
||
|
import sinon from 'sinon';
|
||
4 years ago
|
import * as utils from '../../../helpers/utils/util';
|
||
|
import Identicon from '../../ui/identicon';
|
||
|
import AccountListItem from './account-list-item';
|
||
7 years ago
|
|
||
4 years ago
|
describe('AccountListItem Component', () => {
|
||
4 years ago
|
let wrapper, propsMethodSpies, checksumAddressStub;
|
||
7 years ago
|
|
||
4 years ago
|
describe('render', () => {
|
||
|
beforeAll(() => {
|
||
4 years ago
|
checksumAddressStub = sinon
|
||
|
.stub(utils, 'checksumAddress')
|
||
4 years ago
|
.returns('mockCheckSumAddress');
|
||
5 years ago
|
propsMethodSpies = {
|
||
|
handleClick: sinon.spy(),
|
||
4 years ago
|
};
|
||
|
});
|
||
4 years ago
|
beforeEach(() => {
|
||
4 years ago
|
wrapper = shallow(
|
||
5 years ago
|
<AccountListItem
|
||
4 years ago
|
account={{
|
||
|
address: 'mockAddress',
|
||
|
name: 'mockName',
|
||
|
balance: 'mockBalance',
|
||
|
}}
|
||
5 years ago
|
className="mockClassName"
|
||
|
displayAddress={false}
|
||
|
handleClick={propsMethodSpies.handleClick}
|
||
|
icon={<i className="mockIcon" />}
|
||
4 years ago
|
/>,
|
||
|
{ context: { t: (str) => `${str}_t` } },
|
||
4 years ago
|
);
|
||
|
});
|
||
7 years ago
|
|
||
4 years ago
|
afterEach(() => {
|
||
4 years ago
|
propsMethodSpies.handleClick.resetHistory();
|
||
|
checksumAddressStub.resetHistory();
|
||
|
});
|
||
5 years ago
|
|
||
4 years ago
|
afterAll(() => {
|
||
4 years ago
|
sinon.restore();
|
||
|
});
|
||
7 years ago
|
|
||
4 years ago
|
it('should render a div with the passed className', () => {
|
||
|
expect(wrapper.find('.mockClassName')).toHaveLength(1);
|
||
|
expect(wrapper.find('.mockClassName').is('div')).toStrictEqual(true);
|
||
|
expect(
|
||
|
wrapper.find('.mockClassName').hasClass('account-list-item'),
|
||
|
).toStrictEqual(true);
|
||
4 years ago
|
});
|
||
7 years ago
|
|
||
4 years ago
|
it('should call handleClick with the expected props when the root div is clicked', () => {
|
||
4 years ago
|
const { onClick } = wrapper.find('.mockClassName').props();
|
||
4 years ago
|
expect(propsMethodSpies.handleClick.callCount).toStrictEqual(0);
|
||
4 years ago
|
onClick();
|
||
4 years ago
|
expect(propsMethodSpies.handleClick.callCount).toStrictEqual(1);
|
||
|
expect(propsMethodSpies.handleClick.getCall(0).args).toStrictEqual([
|
||
4 years ago
|
{ address: 'mockAddress', name: 'mockName', balance: 'mockBalance' },
|
||
4 years ago
|
]);
|
||
|
});
|
||
7 years ago
|
|
||
4 years ago
|
it('should have a top row div', () => {
|
||
|
expect(
|
||
|
wrapper.find('.mockClassName > .account-list-item__top-row'),
|
||
|
).toHaveLength(1);
|
||
|
expect(
|
||
4 years ago
|
wrapper.find('.mockClassName > .account-list-item__top-row').is('div'),
|
||
4 years ago
|
).toStrictEqual(true);
|
||
4 years ago
|
});
|
||
7 years ago
|
|
||
4 years ago
|
it('should have an identicon, name and icon in the top row', () => {
|
||
4 years ago
|
const topRow = wrapper.find(
|
||
|
'.mockClassName > .account-list-item__top-row',
|
||
4 years ago
|
);
|
||
4 years ago
|
expect(topRow.find(Identicon)).toHaveLength(1);
|
||
|
expect(topRow.find('.account-list-item__account-name')).toHaveLength(1);
|
||
|
expect(topRow.find('.account-list-item__icon')).toHaveLength(1);
|
||
4 years ago
|
});
|
||
7 years ago
|
|
||
4 years ago
|
it('should show the account name if it exists', () => {
|
||
4 years ago
|
const topRow = wrapper.find(
|
||
|
'.mockClassName > .account-list-item__top-row',
|
||
4 years ago
|
);
|
||
4 years ago
|
expect(
|
||
4 years ago
|
topRow.find('.account-list-item__account-name').text(),
|
||
4 years ago
|
).toStrictEqual('mockName');
|
||
4 years ago
|
});
|
||
7 years ago
|
|
||
4 years ago
|
it('should show the account address if there is no name', () => {
|
||
4 years ago
|
wrapper.setProps({ account: { address: 'addressButNoName' } });
|
||
4 years ago
|
const topRow = wrapper.find(
|
||
|
'.mockClassName > .account-list-item__top-row',
|
||
4 years ago
|
);
|
||
4 years ago
|
expect(
|
||
4 years ago
|
topRow.find('.account-list-item__account-name').text(),
|
||
4 years ago
|
).toStrictEqual('addressButNoName');
|
||
4 years ago
|
});
|
||
7 years ago
|
|
||
4 years ago
|
it('should render the passed icon', () => {
|
||
4 years ago
|
const topRow = wrapper.find(
|
||
|
'.mockClassName > .account-list-item__top-row',
|
||
4 years ago
|
);
|
||
4 years ago
|
expect(
|
||
|
topRow.find('.account-list-item__icon').childAt(0).is('i'),
|
||
|
).toStrictEqual(true);
|
||
|
expect(
|
||
4 years ago
|
topRow.find('.account-list-item__icon').childAt(0).hasClass('mockIcon'),
|
||
4 years ago
|
).toStrictEqual(true);
|
||
4 years ago
|
});
|
||
7 years ago
|
|
||
4 years ago
|
it('should not render an icon if none is passed', () => {
|
||
4 years ago
|
wrapper.setProps({ icon: null });
|
||
4 years ago
|
const topRow = wrapper.find(
|
||
|
'.mockClassName > .account-list-item__top-row',
|
||
4 years ago
|
);
|
||
4 years ago
|
expect(topRow.find('.account-list-item__icon')).toHaveLength(0);
|
||
4 years ago
|
});
|
||
7 years ago
|
|
||
4 years ago
|
it('should render the account address as a checksumAddress if displayAddress is true and name is provided', () => {
|
||
4 years ago
|
wrapper.setProps({ displayAddress: true });
|
||
4 years ago
|
expect(wrapper.find('.account-list-item__account-address')).toHaveLength(
|
||
4 years ago
|
1,
|
||
4 years ago
|
);
|
||
4 years ago
|
expect(
|
||
4 years ago
|
wrapper.find('.account-list-item__account-address').text(),
|
||
4 years ago
|
).toStrictEqual('mockCheckSumAddress');
|
||
|
expect(checksumAddressStub.getCall(0).args).toStrictEqual([
|
||
4 years ago
|
'mockAddress',
|
||
4 years ago
|
]);
|
||
|
});
|
||
7 years ago
|
|
||
4 years ago
|
it('should not render the account address as a checksumAddress if displayAddress is false', () => {
|
||
4 years ago
|
wrapper.setProps({ displayAddress: false });
|
||
4 years ago
|
expect(wrapper.find('.account-list-item__account-address')).toHaveLength(
|
||
4 years ago
|
0,
|
||
4 years ago
|
);
|
||
|
});
|
||
7 years ago
|
|
||
4 years ago
|
it('should not render the account address as a checksumAddress if name is not provided', () => {
|
||
4 years ago
|
wrapper.setProps({ account: { address: 'someAddressButNoName' } });
|
||
4 years ago
|
expect(wrapper.find('.account-list-item__account-address')).toHaveLength(
|
||
4 years ago
|
0,
|
||
4 years ago
|
);
|
||
|
});
|
||
|
});
|
||
|
});
|