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

import { File } from './File';
import DefaultItem from '../../../../elements/Item/Item';

describe('File block', () => {
  let wrapper;

  beforeEach(() => {
    wrapper = shallow(
      <File id={ 23 } label="Test file" />
    );
  });

  const MEDIA_FIXTURE = { source_url: 'http://www.test.png' };

  const getMediaItem = () =>
    wrapper.find(DefaultItem).renderProp('children')(MEDIA_FIXTURE);

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

  it('renders an item to retrieve Media', () => {
    const mediaItem = wrapper.find(DefaultItem);

    expect(mediaItem).toExist();
    expect(mediaItem).toHaveProp('id', 23);
    expect(mediaItem).toHaveProp('typeSlug', 'media');
  });

  it('renders a paragraph', () => {
    expect(getMediaItem().find('p')).toExist();
  });

  it('renders anchor tag', () => {
    expect(getMediaItem().find('a')).toExist();
  });

  it('renders anchor tag with href from prop', () => {
    expect(getMediaItem().find('a')).toHaveProp('href', 'http://www.test.png');
  });

  it('renders anchor tag with rel prop', () => {
    expect(getMediaItem().find('a')).toHaveProp('rel', 'noopener noreferrer');
  });

  it('renders label attribute as title', () => {
    expect(getMediaItem().find('a').children()).toHaveText('Test file');
  });
});
