/* eslint-disable react/prop-types */
import React from 'react';
import withTheme from './withTheme';
import ThemeProvider from '../ThemeProvider';

describe('withTheme', () => {
  it('should inject the theme', () => {
    const ref = React.createRef();
    const text = () => ref.current.textContent;

    function Test({ theme }) {
      return <span ref={ref}>{theme.foo}</span>;
    }

    const TestWithTheme = withTheme(Test);

    const txt = mount(
      <ThemeProvider theme={{ foo: 'foo' }}>
        <TestWithTheme />
      </ThemeProvider>,
    );

    expect(txt.find('span').at(0).text()).toBe('foo');

    expect(text()).toBe('foo');
  });

  it('hoist statics', () => {
    const Test = () => null;
    Test.someStatic = 'will not get hoisted';
    const TestWithTheme = withTheme(Test);
    expect(TestWithTheme.someStatic).toBe(Test.someStatic);
  });

  it('should throw is the import is invalid', () => {
    expect(() => withTheme(undefined)).toThrow();
  });
});
