// @flow
import React from 'react';
import { shallow } from 'enzyme';
import Avatar from './Avatar';

describe('Avatar component', () => {
  let wrapper;

  beforeEach(() => {
    wrapper = shallow(<Avatar />);
  });

  it('has an image', () => {
    expect(wrapper.find('ImageBackground')).toExist();
  });

  it('image has url', () => {
    const imageUrl = 'fernando.png';
    wrapper.setProps({ imageUrl });
    expect(wrapper.find('ImageBackground'))
      .toHaveProp('source', expect.objectContaining({ uri: imageUrl }));
  });

  it('has a default size', () => {
    const size = 40;
    expect(wrapper.find('View').first())
      .toHaveProp('style', expect.objectContaining({ height: size, width: size }));
    expect(wrapper.find('ImageBackground'))
      .toHaveProp('source', expect.objectContaining({ height: size, width: size }));
    expect(wrapper.find('ImageBackground').find('View'))
      .toHaveProp('style', expect.objectContaining({ height: size, width: size }));
  });

  it('can have custom size', () => {
    const size = 80;
    wrapper.setProps({ size });
    expect(wrapper.find('View').first())
      .toHaveProp('style', expect.objectContaining({ height: size, width: size }));
    expect(wrapper.find('ImageBackground'))
      .toHaveProp('source', expect.objectContaining({ height: size, width: size }));
    expect(wrapper.find('ImageBackground').find('View'))
      .toHaveProp('style', expect.objectContaining({ height: size, width: size }));
  });
});
