index.test.js 977 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
import React from 'react';
import range from 'lodash/range';
import { mount } from 'enzyme';
import AvatarList from './index';

const renderItems = numItems =>
  range(numItems).map(i => (
    <AvatarList.Item
      key={i}
      tips="Jake"
      src="https://gw.alipayobjects.com/zos/rmsportal/zOsKZmFRdUtvpqCImOVY.png"
    />
  ));

describe('AvatarList', () => {
  it('renders all items', () => {
    const wrapper = mount(<AvatarList>{renderItems(4)}</AvatarList>);
    expect(wrapper.find('AvatarList').length).toBe(1);
    expect(wrapper.find('Item').length).toBe(4);
    expect(wrapper.findWhere(node => node.key() === 'exceed').length).toBe(0);
  });

  it('renders max of 3 items', () => {
    const wrapper = mount(<AvatarList maxLength={3}>{renderItems(4)}</AvatarList>);
    expect(wrapper.find('AvatarList').length).toBe(1);
    expect(wrapper.find('Item').length).toBe(3);
    expect(wrapper.findWhere(node => node.key() === 'exceed').length).toBe(1);
  });
});