import { jsx as ___EmotionJSX } from "@emotion/core";
import React from 'react';
import renderer from 'react-test-renderer';
import { shallow, mount } from 'enzyme';
import DesktopDropdown from './desktopDropdown';
import MobileDropdown from './mobileDropdown';
import Dropdown from './index';
var options = [{
  value: 'test1',
  label: 'Test1'
}, {
  value: 'test2',
  label: 'Test2'
}, {
  value: 'test3',
  label: 'Test3'
}];
describe('<Dropdown />', function () {
  describe('on touch screen', function () {
    it('renders <MobileDropdown />', function () {
      global.document.documentElement.ontouchstart = function () {};

      var wrapper = shallow(___EmotionJSX(Dropdown, {
        value: "test1",
        options: options
      }));
      delete global.document.documentElement.ontouchstart;
      expect(wrapper.text()).toEqual('<MobileDropdown />');
    });
  });
  describe('when on non-touch screen', function () {
    it('renders <DesktopDropdown />', function () {
      var wrapper = shallow(___EmotionJSX(Dropdown, {
        value: "test1",
        options: options
      }));
      expect(wrapper.text()).toEqual('<DesktopDropdown />');
    });
  });
});
describe('<MobileDropdown />', function () {
  describe('UI snapshots', function () {
    it('renders correctly', function () {
      var tree = renderer.create(___EmotionJSX(MobileDropdown, {
        options: options
      })).toJSON();
      expect(tree).toMatchSnapshot();
    });
  });
  describe('onSelectChange callback', function () {
    it('should be invoked onClick', function () {
      var spy = jest.fn();
      var wrapper = mount(___EmotionJSX(MobileDropdown, {
        options: options,
        onSelectChange: spy,
        value: ""
      }));
      wrapper.find('select').simulate('change', {
        target: {
          value: 'test1'
        }
      });
      expect(spy).toHaveBeenCalled();
    });
  });
});
describe('<DesktopDropdown />', function () {
  it('renders the current option text', function () {
    var wrapper = shallow(___EmotionJSX(DesktopDropdown, {
      options: options,
      currentOption: {
        value: 'test1',
        label: 'Test1'
      }
    }));
    expect(wrapper.find('#select-input-box').text().includes('Test1')).toEqual(true);
  });
  describe('onSelectClick callback', function () {
    it('should be invoked onClick', function () {
      var spy = jest.fn();
      var wrapper = shallow(___EmotionJSX(DesktopDropdown, {
        options: options,
        currentOption: {
          value: 'test1',
          label: 'Test1'
        },
        onSelectClick: spy
      }));
      wrapper.find('#select-input-box').simulate('click');
      expect(spy).toHaveBeenCalled();
    });
  });
  describe('onOptionClick callback', function () {
    it('should be invoked onClick', function () {
      var spy = jest.fn();
      var wrapper = mount(___EmotionJSX(DesktopDropdown, {
        options: options,
        currentOption: {
          value: 'test1',
          label: 'Test1'
        },
        onOptionClick: spy,
        isOpen: true
      }));
      wrapper.find('li').first().simulate('click');
      expect(spy).toHaveBeenCalled();
    });
  });
});