import { shallow } from 'enzyme';
import React from 'react';
import { Provider as ReduxProvider } from 'react-redux';

import Site from '.';
import Context from './Context';
import Name from './SiteName';
import Version from './SiteVersion';
import { Site as MockSite } from '../../../tests/storyshare';

describe('Site component', () => {
  const CHILDREN = <div>Test children</div>;

  const OPTIONS_FIXTURE = { };

  const SITE_FIXTURE = new MockSite();

  let wrapper;

  beforeEach(() => {
    wrapper = shallow(
      <Site
        options={ OPTIONS_FIXTURE }
        site={ SITE_FIXTURE }
      >
        { CHILDREN }
      </Site>
    );
  });

  const getProvider = () => wrapper.find(Context.Provider);

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

  it('renders a Provider to pass the context', () => {
    expect(getProvider()).toExist();
  });

  it('passes options to the Provider', () => {
    expect(getProvider().prop('value').options).toBe(OPTIONS_FIXTURE);
  });

  it('passes the site to the Provider', () => {
    expect(getProvider().prop('value').site).toBe(SITE_FIXTURE);
  });

  it('renders a redux Provider', () => {
    expect(getProvider().find(ReduxProvider)).toExist();
  });

  it('passes the store to the redux Provider', () => {
    expect(wrapper.find(ReduxProvider)).toHaveProp('store', SITE_FIXTURE.store);
  });

  it('renders any children', () => {
    expect(wrapper).toContainReact(CHILDREN);
  });

  it('exposes SiteName as Site.Name', () => {
    expect(Site.Name).toBe(Name);
  });

  it('exposes SiteVersion as Site.Version', () => {
    expect(Site.Version).toBe(Version);
  });
});
