'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 _enzyme = require('enzyme');

var _CellTitle = require('./CellTitle.component');

var _CellTitle2 = _interopRequireDefault(_CellTitle);

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

describe('CellTitle', function () {
	it('should render title selector component', function () {
		// given
		var columnData = {
			id: 'my-title',
			displayModeKey: 'displayMode',
			onClick: jest.fn(),
			onEditCancel: jest.fn(),
			onEditSubmit: jest.fn()
		};
		var rowData = {
			id: 1,
			displayMode: 'text',
			icon: 'talend-file-o',
			title: 'my awesome title'
		};

		// when
		var wrapper = (0, _enzyme.shallow)(_react2.default.createElement(_CellTitle2.default, {
			cellData: 'my awesome title',
			columnData: columnData,
			rowData: rowData,
			rowIndex: 1
		}));

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

	describe('icon', function () {
		var rowData = {
			id: 1,
			title: 'my awesome title',
			icon: 'talend-file-o'
		};

		it('should render the icon', function () {
			// given
			var columnData = {
				id: 'my-title',
				iconKey: 'icon'
			};

			// when
			var wrapper = (0, _enzyme.shallow)(_react2.default.createElement(_CellTitle2.default, {
				cellData: 'my awesome title',
				columnData: columnData,
				rowData: rowData,
				rowIndex: 1
			}));

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

		it('should NOT render the icon when no iconKey is provided', function () {
			// given
			var columnData = {
				id: 'my-title',
				iconKey: undefined // no icon key
			};

			// when
			var wrapper = (0, _enzyme.shallow)(_react2.default.createElement(_CellTitle2.default, {
				cellData: 'my awesome title',
				columnData: columnData,
				rowData: rowData,
				rowIndex: 1
			}));

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

		it('should NOT render the icon when the rowData has no icon value', function () {
			// given
			var columnData = {
				id: 'my-title',
				iconKey: 'icon'
			};
			var noIconRowData = _extends({}, rowData, {
				icon: undefined // no icon name value
			});

			// when
			var wrapper = (0, _enzyme.shallow)(_react2.default.createElement(_CellTitle2.default, {
				cellData: 'my awesome title',
				columnData: columnData,
				rowData: noIconRowData,
				rowIndex: 1
			}));

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

	describe('actions', function () {
		var rowData = {
			id: 1,
			title: 'my awesome title',
			actions: [{
				label: 'edit',
				icon: 'talend-pencil',
				onClick: jest.fn('onEdit')
			}, {
				label: 'delete',
				icon: 'talend-trash',
				onClick: jest.fn('onDelete')
			}]
		};

		it('should render the actions', function () {
			// given
			var columnData = {
				id: 'my-title',
				actionsKey: 'actions'
			};

			// when
			var wrapper = (0, _enzyme.shallow)(_react2.default.createElement(_CellTitle2.default, {
				cellData: 'my awesome title',
				columnData: columnData,
				rowData: rowData,
				rowIndex: 1
			}));

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

		it('should NOT render the actions when no actions key is provided', function () {
			// given
			var columnData = {
				id: 'my-title',
				actionsKey: undefined // no actions key
			};

			// when
			var wrapper = (0, _enzyme.shallow)(_react2.default.createElement(_CellTitle2.default, {
				cellData: 'my awesome title',
				columnData: columnData,
				rowData: rowData,
				rowIndex: 1
			}));

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

		it('should NOT render the actions when rowData has no actions', function () {
			// given
			var columnData = {
				id: 'my-title',
				actionsKey: 'actions'
			};
			var noActionsRowData = _extends({}, rowData, {
				actions: undefined // not actions
			});

			// when
			var wrapper = (0, _enzyme.shallow)(_react2.default.createElement(_CellTitle2.default, {
				cellData: 'my awesome title',
				columnData: columnData,
				rowData: noActionsRowData,
				rowIndex: 1
			}));

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