import React from 'react';
import { shallow, mount } from 'enzyme';
import Button from '../src/Button';
import mocker from './helper/mocker';

describe('Button', () => {
  let wrapper;

  beforeEach(() => {
    wrapper = shallow(<Button waves="light">Stuff</Button>);
  });

  test('renders', () => {
    expect(wrapper).toMatchSnapshot();
  });

  test('should output a button', () => {
    expect(wrapper.find('button')).toHaveLength(1);
  });

  test('should output a component with btn class', () => {
    expect(wrapper.find('.btn')).toHaveLength(1);
  });

  test('should apply waves', () => {
    expect(wrapper.find('.waves-effect')).toHaveLength(1);
  });

  test('should apply large styles', () => {
    wrapper = shallow(<Button large>Stuff</Button>);
    expect(wrapper.find('.btn-large')).toHaveLength(1);
  });

  test('should apply small styles', () => {
    wrapper = shallow(<Button small>Stuff</Button>);
    expect(wrapper.find('.btn-small')).toHaveLength(1);
  });

  test('should apply floating styles', () => {
    wrapper = shallow(<Button floating>Stuff</Button>);
    expect(wrapper.find('.btn-floating')).toHaveLength(1);
  });

  test('should apply flat styles', () => {
    wrapper = shallow(<Button flat>Stuff</Button>);
    expect(wrapper.find('.btn-flat')).toHaveLength(1);
  });

  test('should apply FAB hover', () => {
    wrapper = shallow(<Button fab="vertical">Stuff</Button>);
    wrapper.simulate('hover');
    expect(wrapper.find('.fixed-action-btn active'));
  });

  test('should apply FAB click-only', () => {
    wrapper = shallow(
      <Button fab="horizontal" fabClickOnly>
        Stuff
      </Button>
    );
    wrapper.simulate('click');
    expect(wrapper.find('.fixed-action-btn active'));
  });

  describe('with a disabled prop', () => {
    let wrapper = mount(<Button disabled>Stuff</Button>);
    test('should have a disabled class', () => {
      expect(wrapper.find('.disabled')).toHaveLength(1);
    });

    test('should have a disabled attribute', () => {
      expect(wrapper.prop('disabled')).toEqual(true);
    });
  });

  describe('with a tooltip', () => {
    let tooltip = 'Hello';
    let tooltipOptions = {
      position: 'top',
      delay: 50
    };

    const tooltipMock = jest.fn();
    mocker('tooltip', tooltipMock);
    wrapper = shallow(<Button tooltip={tooltip}>Stuff</Button>);
    test('initializes Button with tooltip', () => {
      expect(tooltipMock).toHaveBeenCalled();
    });

    wrapper = shallow(<Button tooltipOptions={tooltipOptions}>Stuff</Button>);
    test('initializes Button with tooltip options', () => {
      expect(tooltipMock).toHaveBeenCalledWith(tooltipOptions);
    });
  });
});

@@ -126,16 +126,20 @@
 /helper/
+new-
 mocker';
@@ -2122,26 +2122,349 @@
 () =%3E %7B%0A    
-le
+const tooltipInitMock = jest.fn();%0A    const tooltipInstanceDestroyMock = jest.fn();%0A    const tooltipMock = %7B%0A      init: (el, options) =%3E %7B%0A        tooltipInitMock(options);%0A        return %7B%0A          destroy: tooltipInstanceDestroyMock%0A        %7D;%0A      %7D%0A    %7D;%0A    const restore = mocker('Tooltip', tooltipMock);%0A    cons
 t tooltip = 
@@ -2476,18 +2476,20 @@
 o';%0A    
-le
+cons
 t toolti
@@ -2556,75 +2556,172 @@
     
-const tooltipMock = jest.fn();%0A    mocker('tooltip', tooltipMock);%0A
+beforeEach(() =%3E %7B%0A      tooltipInitMock.mockClear();%0A    %7D);%0A%0A    afterAll(() =%3E %7B%0A      restore();%0A    %7D);%0A%0A    test('initializes Button with tooltip', () =%3E %7B%0A  
     
@@ -2773,32 +2773,91 @@
 tuff%3C/Button%3E);%0A
+      expect(tooltipInitMock).toHaveBeenCalled();%0A    %7D);%0A%0A
     test('initia
@@ -2873,32 +2873,40 @@
 ton with tooltip
+ options
 ', () =%3E %7B%0A     
@@ -2892,32 +2892,113 @@
 tions', () =%3E %7B%0A
+      wrapper = shallow(%3CButton tooltipOptions=%7BtooltipOptions%7D%3EStuff%3C/Button%3E);%0A
       expect(too
@@ -2993,32 +2993,36 @@
   expect(tooltip
+Init
 Mock).toHaveBeen
@@ -3023,37 +3023,102 @@
 veBeenCalled
-();%0A    %7D);%0A%0A
+With(tooltipOptions);%0A    %7D);%0A%0A    test('Destroyed when unmounted', () =%3E %7B%0A  
     wrapper 
@@ -3134,39 +3134,32 @@
 (%3CButton tooltip
-Options
 =%7BtooltipOptions
@@ -3143,39 +3143,32 @@
 tooltip=%7Btooltip
-Options
 %7D%3EStuff%3C/Button%3E
@@ -3178,63 +3178,28 @@
     
-test('initializes Button with tooltip options', () =%3E %7B
+  wrapper.unmount();
 %0A   
@@ -3211,24 +3211,39 @@
 pect(tooltip
+InstanceDestroy
 Mock).toHave
@@ -3252,35 +3252,17 @@
 enCalled
-With(tooltipOptions
+(
 );%0A    %7D

Add test for tooltip init and destroy methods