/*
Copyright (c) 2018 Uber Technologies, Inc.

This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
*/
import React from 'react';
import { mount } from 'enzyme';
import { Panel, StyledContent, StyledHeader, StyledToggleIcon } from '../index.js';
describe('Panel', function () {
  test('basic rendering', function () {
    var props = {
      title: 'title',
      children: 'content'
    };
    var renderedHeader;
    var renderedContent;
    var renderedToggleIcon;
    var wrapper = mount(React.createElement(Panel, props));
    renderedHeader = wrapper.find(StyledHeader).first();
    renderedToggleIcon = wrapper.find(StyledToggleIcon).first();
    renderedContent = wrapper.find(StyledContent).first();
    expect(renderedHeader).toExist();
    expect(renderedHeader.props()).toMatchSnapshot('Header has correct props');
    expect(renderedToggleIcon).toExist();
    expect(renderedContent).toExist();
    expect(renderedContent.props()).toMatchSnapshot('Content has correct props');
  });
  test('component overrides', function () {
    var overrides = {
      Header: jest.fn().mockImplementation(function (_ref) {
        var children = _ref.children;
        return React.createElement("span", null, children);
      })
    }; // $FlowFixMe

    var wrapper = mount(React.createElement(Panel, {
      overrides: overrides
    }, "Content"));
    var header = wrapper.find(overrides.Header);
    expect(header).toHaveLength(1);
  });
  test('onChange is called on a click event', function () {
    var props = {
      onChange: jest.fn(),
      onClick: jest.fn(),
      title: 'title'
    };
    var wrapper = mount(React.createElement(Panel, props, "Content"));
    var header = wrapper.find(StyledHeader);
    header.simulate('click');
    expect(props.onChange).toHaveBeenCalledWith({
      expanded: true
    });
    expect(props.onClick).toHaveBeenCalled();
  });
  test('onChange is called on a Enter keydown event', function () {
    var props = {
      onChange: jest.fn(),
      onKeyDown: jest.fn(),
      title: 'title'
    };
    var event = {
      key: 'Enter'
    };
    var wrapper = mount(React.createElement(Panel, props, "Content"));
    var header = wrapper.find(StyledHeader);
    header.simulate('keydown', event);
    expect(props.onChange).toHaveBeenCalledWith({
      expanded: true
    });
    expect(props.onKeyDown).toHaveBeenCalled();
  });
  test('onChange is called on a Space keydown event', function () {
    var props = {
      onChange: jest.fn(),
      onKeyDown: jest.fn(),
      title: 'title'
    };
    var event = {
      which: 32
    };
    var wrapper = mount(React.createElement(Panel, props, "Content"));
    var header = wrapper.find(StyledHeader);
    header.simulate('keydown', event);
    expect(props.onChange).toHaveBeenCalledWith({
      expanded: true
    });
    expect(props.onKeyDown).toHaveBeenCalled();
  });
});