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

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

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

  let wrapper;

  beforeEach(() => {
    wrapper = shallow(
      <ItemContent 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 content using dangerouslySetInnerHTML', () => {
    expect(wrapper.find('div'))
      .toHaveProp('dangerouslySetInnerHTML', { __html: 'Test content' });
  });

  it('copes if rendered content is empty', () => {
    wrapper.setProps({ item: { content: { rendered: '' } } });
  });

  it('copes if rendered content is missing', () => {
    wrapper.setProps({ item: { content: { } } });
    expect(wrapper).toBeEmptyRender();
  });

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

  testItemComponent(ItemContent);
});
