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

import childrenFromHtml from '../../childrenFromHtml';
import { Paragraph } from './Paragraph';

jest.mock('../../childrenFromHtml');

describe('Paragraph block', () => {
  const CHILDREN_FIXTURE = ['test-children'];

  const CONTENT_FIXTURE = 'test-content';

  let wrapper;

  beforeEach(() => {
    childrenFromHtml.mockReturnValue(CHILDREN_FIXTURE);
    wrapper = shallow(
      <Paragraph content={ CONTENT_FIXTURE } />
    );
  });

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

  it('renders a paragraph', () => {
    expect(wrapper).toHaveDisplayName('p');
  });

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

  it('converts content into children for the RichText component', () => {
    childrenFromHtml.mockClear();
    wrapper.setProps(); // trigger rerender
    expect(childrenFromHtml).toHaveBeenCalled();
    expect(childrenFromHtml).toHaveBeenCalledWith(CONTENT_FIXTURE);
  });

  it('passes converted children to the RichText component', () => {
    expect(wrapper.find('RichText')).toHaveProp('children', CHILDREN_FIXTURE);
  });
});
