'use strict';

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _enzyme = require('enzyme');

var _constants = require('../utils/constants');

var _CellTitleSelector = require('./CellTitleSelector.component');

var _CellTitleSelector2 = _interopRequireDefault(_CellTitleSelector);

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

var TITLE_MODE_TEXT = _constants.cellTitleDisplayModes.TITLE_MODE_TEXT,
    TITLE_MODE_INPUT = _constants.cellTitleDisplayModes.TITLE_MODE_INPUT;


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

		// when
		var wrapper = (0, _enzyme.shallow)(_react2.default.createElement(_CellTitleSelector2.default, {
			id: 'my-title',
			cellData: 'my value',
			className: 'my-title-classname',
			displayMode: TITLE_MODE_INPUT,
			onEditCancel: jest.fn(),
			onEditSubmit: jest.fn(),
			rowData: rowData
		}));

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

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

		// when
		var wrapper = (0, _enzyme.shallow)(_react2.default.createElement(_CellTitleSelector2.default, {
			id: 'my-title',
			cellData: 'my value',
			className: 'my-title-classname',
			displayMode: TITLE_MODE_TEXT,
			onClick: jest.fn(),
			rowData: rowData
		}));

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

	it('should trigger callback on button click', function () {
		// given
		var rowData = { id: 1 };
		var onClick = jest.fn();
		var clickEvent = { button: 0 };
		var wrapper = (0, _enzyme.shallow)(_react2.default.createElement(_CellTitleSelector2.default, {
			id: 'my-title',
			cellData: 'my value',
			className: 'my-title-classname',
			displayMode: TITLE_MODE_TEXT,
			onClick: onClick,
			rowData: rowData
		}));

		// when
		wrapper.find('#my-title-btn').simulate('click', clickEvent);

		// then
		expect(onClick).toBeCalledWith(clickEvent, rowData);
	});

	it('should render the simple text', function () {
		// when
		var wrapper = (0, _enzyme.shallow)(_react2.default.createElement(_CellTitleSelector2.default, {
			id: 'my-title',
			cellData: 'my value',
			className: 'my-title-classname',
			displayMode: TITLE_MODE_TEXT
		}));

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