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

import { testItemComponent } from '../../../tests/item';
import MediaVideo from '../MediaVideo';
import { ItemFeaturedVideo } from './ItemFeaturedVideo';

jest.mock('../../../public/lib/jwplayer/jwplayer', () => null);

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

  let wrapper;

  beforeEach(() => {
    wrapper = shallow(
      <ItemFeaturedVideo item={ ITEM_FIXTURE } posterWidth={ 640 } />
    );
  });

  const findMediaVideo = () => wrapper.find(MediaVideo);

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

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

  it('passes the mediaId to MediaVideo component', () => {
    expect(findMediaVideo()).toHaveProp('id', 23);
  });

  it('passes the posterId to MediaVideo component', () => {
    expect(findMediaVideo()).toHaveProp('posterId', 42);
  });

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

  it('avoids passing internal props through to the MediaVideo', () => {
    expect(findMediaVideo()).not.toHaveProp('item');
  });

  it('renders nothing if no _storyshare_featured_video_id', () => {
    wrapper.setProps({ item: { } });
    expect(wrapper).toBeEmptyRender();
  });

  it('renders nothing if _storyshare_featured_video_id is 0', () => {
    wrapper.setProps({ item: { _storyshare_featured_video_id: 0 } });
    expect(wrapper).toBeEmptyRender();
  });

  it('is possible to override the posterId via props', () => {
    wrapper.setProps({ posterId: 15 });

    expect(wrapper).toHaveProp('posterId', 15);
  });

  testItemComponent(ItemFeaturedVideo);
});
