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

import { testItemComponent } from '../../../tests/item';
import { ItemExcerpt } from './ItemExcerpt';

describe('ItemExcerpt component', () => {
  const ITEM_FIXTURE = {
    excerpt: { rendered: 'Test excerpt' },
  };

  let wrapper;

  beforeEach(() => {
    wrapper = shallow(
      <ItemExcerpt item={ ITEM_FIXTURE } />
    );
  });

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

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

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

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

  it('renders the excerpt using dangerouslySetInnerHTML', () => {
    expect(wrapper.find('div'))
      .toHaveProp('dangerouslySetInnerHTML', { __html: 'Test excerpt' });
  });

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

  testItemComponent(ItemExcerpt);
});
