'use strict';

var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _reactTestRenderer = require('react-test-renderer');

var _reactTestRenderer2 = _interopRequireDefault(_reactTestRenderer);

var _Action = require('./Action.component');

var _Action2 = _interopRequireDefault(_Action);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

jest.mock('react-dom');

var myAction = {
	label: 'Click me',
	icon: 'talend-caret-down',
	onClick: jest.fn()
};

var mouseDownAction = {
	label: 'Click me',
	icon: 'talend-caret-down',
	onMouseDown: jest.fn()
};

describe('Action', function () {
	it('should render a button', function () {
		// when
		var wrapper = _reactTestRenderer2.default.create(_react2.default.createElement(_Action2.default, myAction)).toJSON();

		// then
		expect(wrapper).toMatchSnapshot();
	});

	it('should click on the button trigger the onclick props', function () {
		// given
		var wrapper = _reactTestRenderer2.default.create(_react2.default.createElement(_Action2.default, _extends({ extra: 'extra' }, myAction))).toJSON();

		// when
		wrapper.props.onClick();

		// then
		expect(myAction.onClick).toHaveBeenCalled();
		expect(myAction.onClick.mock.calls.length).toBe(1);
		var args = myAction.onClick.mock.calls[0];
		expect(args.length).toBe(2);
		expect(args[0]).toBe();
		expect(args[1].action.extra).toBe('extra');
	});

	it('should pass all props to the Button', function () {
		// when
		var wrapper = _reactTestRenderer2.default.create(_react2.default.createElement(_Action2.default, _extends({
			className: 'navbar-btn',
			notExisting: true
		}, myAction))).toJSON();

		// then
		expect(wrapper).toMatchSnapshot();
	});

	it('should display a Progress indicator if set', function () {
		// when
		var wrapper = _reactTestRenderer2.default.create(_react2.default.createElement(_Action2.default, _extends({
			className: 'navbar-btn',
			inProgress: true
		}, myAction))).toJSON();

		// then
		expect(wrapper).toMatchSnapshot();
	});

	it('should display a disabled Icon', function () {
		// when
		var wrapper = _reactTestRenderer2.default.create(_react2.default.createElement(_Action2.default, _extends({
			className: 'navbar-btn',
			disabled: true
		}, myAction))).toJSON();

		// then
		expect(wrapper).toMatchSnapshot();
	});

	it('should reverse icon/label', function () {
		// when
		var wrapper = _reactTestRenderer2.default.create(_react2.default.createElement(_Action2.default, _extends({
			iconPosition: 'right'
		}, myAction))).toJSON();

		// then
		expect(wrapper).toMatchSnapshot();
	});

	it('should apply transformation on icon', function () {
		// when
		var wrapper = _reactTestRenderer2.default.create(_react2.default.createElement(_Action2.default, _extends({
			iconTransform: 'rotate-180'
		}, myAction))).toJSON();

		// then
		expect(wrapper).toMatchSnapshot();
	});

	it('should render action with html property name = props.name if set', function () {
		// when
		var wrapper = _reactTestRenderer2.default.create(_react2.default.createElement(_Action2.default, _extends({
			name: 'custom_name'
		}, myAction))).toJSON();

		// then
		expect(wrapper).toMatchSnapshot();
	});

	it('should trigger action if set up onMouseDown event', function () {
		// given
		var wrapper = _reactTestRenderer2.default.create(_react2.default.createElement(_Action2.default, _extends({ extra: 'extra' }, mouseDownAction))).toJSON();

		// when
		wrapper.props.onMouseDown();

		// then
		expect(mouseDownAction.onMouseDown).toHaveBeenCalled();
		expect(mouseDownAction.onMouseDown.mock.calls.length).toBe(1);
		var args = mouseDownAction.onMouseDown.mock.calls[0];
		expect(args.length).toBe(2);
		expect(args[0]).toBe();
		expect(args[1].action.extra).toBe('extra');
	});
});