import { shallow } from 'enzyme';
import React from 'react';

import { testItemComponent } from '../../../tests/item';
import MediaImage from '../MediaImage';
import { ItemFeaturedImage } from './ItemFeaturedImage';

describe('ItemFeaturedImage component', () => {
  const ITEM_FIXTURE = {
    featured_media: 42,
  };

  let wrapper;

  beforeEach(() => {
    wrapper = shallow(
      <ItemFeaturedImage item={ ITEM_FIXTURE } width={ 400 } />
    );
  });

  it('renders', () => {
    expect(wrapper).toExist();
  });

  it('renders a MediaImage', () => {
    expect(wrapper.find(MediaImage)).toExist();
  });

  it('passes the featured_media ID through to the MediaImage', () => {
    expect(wrapper.find(MediaImage)).toHaveProp('id', 42);
  });

  it('passes unknown props through to the MediaImage', () => {
    wrapper.setProps({ unknown: 'value' });
    expect(wrapper.find(MediaImage)).toHaveProp('unknown', 'value');
  });

  it('avoids passing internal props through to the MediaImage', () => {
    const image = wrapper.find(MediaImage);
    expect(image).not.toHaveProp('item');
  });

  it('copes if no featured_media is available', () => {
    wrapper.setProps({ item: { } });
    expect(wrapper).toBeEmptyRender();
  });

  testItemComponent(ItemFeaturedImage);
});
