import * as React from "react";
import {shallow} from 'enzyme';
import {findByTestAttr} from "utils/testUtils";
import Index from './index';

const setup = (props = {}) => {
  return shallow(<Index {...props} />);
};

describe('Button', () => {
  it('renders without error', () => {
    const wrapper = setup();
    const component = findByTestAttr(wrapper, 'wen-button');
    expect(component.length).toBe(1);
  });

  it('can trigger onClick ', () => {
    const fn = jest.fn();
    const wrapper = setup({
      onClick: fn
    });
    const button = findByTestAttr(wrapper, 'wen-button');
    button.simulate('click', {
      preventDefault() {
      }
    });
    expect(fn.mock.calls.length).toBe(1);
  });

  it('dont trigger click when `loading` props is true', () => {
    const fn = jest.fn();
    const wrapper = setup({
      loading: true,
      onClick: fn
    });
    const button = findByTestAttr(wrapper, 'wen-button');
    button.simulate('click', {
      preventDefault() {
      }
    });
    expect(fn.mock.calls.length).toBe(0);
  });

  it('can accept `type` props', () => {
    const type = 'warning';
    const wrapper = setup({
      type
    });
    const button = findByTestAttr(wrapper, type);
    expect(button.length).toBe(1);
  });

  it('can accept `className` props', () => {
    const className = 'test';
    const wrapper = setup({
      className
    });
    const button = findByTestAttr(wrapper, className);
    expect(button.length).toBe(1);
  });

  it('can accept `style` props', () => {
    const wrapper = setup({
      style: {
        color: 'red'
      }
    });
    const button = findByTestAttr(wrapper, 'wen-button');
    expect(button.prop('style')).toHaveProperty('color', 'red');
  });

});






