'use strict';

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _enzyme = require('enzyme');

var _reactBootstrap = require('react-bootstrap');

var _ItemTitle = require('./ItemTitle.component');

var _ItemTitle2 = _interopRequireDefault(_ItemTitle);

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

var value = 'Hello world';
var inputProps = {
	value: value,
	display: 'input',
	onChange: jest.fn(),
	onSubmit: jest.fn(),
	onCancel: jest.fn()
};

describe('ItemTitle', function () {
	it('should trigger callback on button title click', function () {
		// given
		var props = {
			value: value,
			display: 'button',
			onClick: jest.fn()
		};
		var titleInstance = _react2.default.createElement(_ItemTitle2.default, props);

		// when
		var wrapper = (0, _enzyme.mount)(titleInstance);
		wrapper.find(_reactBootstrap.Button).simulate('click', { stopPropagation: function stopPropagation() {} });

		// then
		expect(props.onClick).toBeCalled();
		var callArgs = props.onClick.mock.calls[0];
		expect(callArgs.length).toBe(1);
	});

	it('should trigger callback on input title blur', function () {
		// given
		var titleInstance = _react2.default.createElement(_ItemTitle2.default, inputProps);

		// when
		var wrapper = (0, _enzyme.mount)(titleInstance);
		wrapper.find('input').simulate('blur', { target: { value: 'my new title' } });

		// then
		expect(inputProps.onSubmit).toBeCalled();
		var callArgs = inputProps.onSubmit.mock.calls[0];
		expect(callArgs.length).toBe(1);
	});

	it('should trigger callback on input title ENTER', function () {
		// given
		var titleInstance = _react2.default.createElement(_ItemTitle2.default, inputProps);

		// when
		var wrapper = (0, _enzyme.mount)(titleInstance);
		wrapper.find('input').simulate('keyUp', { keyCode: 13, target: { value: 'my new title' } });

		// then
		expect(inputProps.onSubmit).toBeCalled();
		var callArgs = inputProps.onSubmit.mock.calls[0];
		expect(callArgs.length).toBe(1);
	});

	it('should trigger callback on input title ESC', function () {
		// given
		var titleInstance = _react2.default.createElement(_ItemTitle2.default, inputProps);

		// when
		var wrapper = (0, _enzyme.mount)(titleInstance);
		wrapper.find('input').simulate('keyUp', { keyCode: 27 });

		// then
		expect(inputProps.onCancel).toBeCalled();
		var callArgs = inputProps.onCancel.mock.calls[0];
		expect(callArgs.length).toBe(1);
	});
});