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

import { FileIcon } from './FileIcon';

describe('FileIcon component', () => {
  let wrapper;

  beforeEach(() => {
    wrapper = shallow(
      <FileIcon />
    );
  });

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

  it('renders an SUI Icon', () => {
    expect(wrapper.name()).toBe('Icon');
  });

  it('renders the plain file icon by default', () => {
    expect(wrapper).toHaveProp('name', 'file');
  });

  it('can use an outline icon', () => {
    wrapper.setProps({ outline: true });
    expect(wrapper).toHaveProp('name', 'file outline');
  });

  it('renders an appropriate icon for a MIME type', () => {
    wrapper.setProps({ outline: true, type: 'application/pdf' });
    expect(wrapper).toHaveProp('name', 'file pdf outline');
  });

  it('falls back to the plain file icon if the type is not recognised', () => {
    wrapper.setProps({ type: 'application/vdn.storyshare.export' });
    expect(wrapper).toHaveProp('name', 'file');
  });

  it('passes unknown props through to the Icon', () => {
    wrapper.setProps({ unknown: 'value' });
    expect(wrapper).toHaveProp('unknown', 'value');
  });

  it('avoids passing internal props through to the Icono', () => {
    expect(wrapper).not.toHaveProp('outline');
    expect(wrapper).not.toHaveProp('type');
  });
});
