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

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

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

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

  const CONTENT_FIXTURE = 'test-content';

  let wrapper;

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

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

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

  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);
  });
});
