'use strict';

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

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

var _reactTestRenderer2 = _interopRequireDefault(_reactTestRenderer);

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

var _ItemTitle2 = _interopRequireDefault(_ItemTitle);

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

var item = {
	id: 1,
	name: 'Hello world',
	created: '2016-09-22',
	modified: '2016-09-22',
	author: 'Jean-Pierre DUPONT',
	icon: 'fa fa-file-excel-o',
	displayMode: 'input'
};

describe('ItemTitle', function () {
	it('should render text title', function () {
		// given
		var props = {
			id: 'title',
			className: 'my-title',
			item: item,
			titleProps: {
				key: 'name',
				displayModeKey: undefined, // no display mode in item
				onClick: undefined }
		};

		// when
		var wrapper = _reactTestRenderer2.default.create(_react2.default.createElement(_ItemTitle2.default, props)).toJSON();

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

	it('should render button title', function () {
		// given
		var props = {
			id: 'title',
			className: 'my-title',
			item: item,
			titleProps: {
				key: 'name',
				displayModeKey: undefined, // no display mode in item
				onClick: jest.fn() }
		};

		// when
		var wrapper = _reactTestRenderer2.default.create(_react2.default.createElement(_ItemTitle2.default, props)).toJSON();

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

	it('should render input title', function () {
		// given
		var props = {
			id: 'title',
			className: 'my-title',
			item: item,
			titleProps: {
				key: 'name',
				displayModeKey: 'displayMode' }
		};
		function createNodeMock(element) {
			if (element.type === 'input') {
				return {};
			}
			return null;
		}
		var rendererOptions = { createNodeMock: createNodeMock };

		// when
		var wrapper = _reactTestRenderer2.default.create(_react2.default.createElement(_ItemTitle2.default, props), rendererOptions).toJSON();

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

	it('should render icon', function () {
		// given
		var props = {
			className: 'my-title',
			item: item,
			titleProps: {
				key: 'name',
				iconKey: 'icon' }
		};

		// when
		var wrapper = _reactTestRenderer2.default.create(_react2.default.createElement(_ItemTitle2.default, props)).toJSON();

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