'use strict';

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _enzyme = require('enzyme');

var _keycode = require('keycode');

var _keycode2 = _interopRequireDefault(_keycode);

var _CellTitleInput = require('./CellTitleInput.component');

var _CellTitleInput2 = _interopRequireDefault(_CellTitleInput);

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

describe('CellTitleInput', function () {
	it('should render the input', function () {
		// given
		var rowData = { id: 1 };

		// when
		var wrapper = (0, _enzyme.shallow)(_react2.default.createElement(_CellTitleInput2.default, {
			id: 'my-cell',
			cellData: 'my value',
			onEditCancel: jest.fn(),
			onEditSubmit: jest.fn(),
			rowData: rowData
		}));

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

	it('should call submit callback on blur', function () {
		// given
		var rowData = { id: 1 };
		var onEditCancel = jest.fn();
		var onEditSubmit = jest.fn();

		var wrapper = (0, _enzyme.mount)(_react2.default.createElement(_CellTitleInput2.default, {
			id: 'my-cell-input',
			cellData: 'my value',
			onEditCancel: onEditCancel,
			onEditSubmit: onEditSubmit,
			rowData: rowData
		}));

		// when
		wrapper.find('#my-cell-input').simulate('blur');

		// then
		expect(onEditSubmit).toBeCalledWith(expect.anything(), {
			value: 'my value',
			model: rowData
		});
	});

	it('should call submit callback on form submit', function () {
		// given
		var rowData = { id: 1 };
		var onEditCancel = jest.fn();
		var onEditSubmit = jest.fn();

		var wrapper = (0, _enzyme.mount)(_react2.default.createElement(_CellTitleInput2.default, {
			id: 'my-cell-input',
			cellData: 'my value',
			onEditCancel: onEditCancel,
			onEditSubmit: onEditSubmit,
			rowData: rowData
		}));

		// when
		wrapper.simulate('submit');

		// then
		expect(onEditSubmit).toBeCalledWith(expect.anything(), {
			value: 'my value',
			model: rowData
		});
	});

	it('should call cancel callback on ESC keyup', function () {
		// given
		var rowData = { id: 1 };
		var onEditCancel = jest.fn();
		var onEditSubmit = jest.fn();
		var event = { keyCode: (0, _keycode2.default)('escape') };

		var wrapper = (0, _enzyme.mount)(_react2.default.createElement(_CellTitleInput2.default, {
			id: 'my-cell-input',
			cellData: 'my value',
			onEditCancel: onEditCancel,
			onEditSubmit: onEditSubmit,
			rowData: rowData
		}));

		// when
		wrapper.find('#my-cell-input').simulate('keyUp', event);

		// then
		expect(onEditCancel).toBeCalledWith(expect.anything(), rowData);
	});
});