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

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

describe('ItemBlockContent component', () => {
  const ITEM_FIXTURE = {
    content: {
      blocks: [
        {
          name: 'storyshare/paragraph',
          attributes: {
            children: [],
          },
        },
      ],
    },
  };

  let wrapper;

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

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

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

  it('passes the blocks to the BlockContent component', () => {
    expect(wrapper.find('BlockContent'))
      .toHaveProp('blocks', ITEM_FIXTURE.content.blocks);
  });

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

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

  testItemComponent(ItemBlockContent);
});
