'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 _reactTestRenderer = require('react-test-renderer');

var _reactTestRenderer2 = _interopRequireDefault(_reactTestRenderer);

var _Item = require('./Item.component');

var _Item2 = _interopRequireDefault(_Item);

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

jest.mock('react-dom');

var columns = [{ key: 'name', label: 'Name', type: 'title' }, { key: 'author', label: 'Author' }, { key: 'created', label: 'Created' }, { key: 'modified', label: 'Modified' }];
var item = {
	id: 2,
	name: 'Bar',
	created: '2016-09-22',
	modified: '2016-09-22',
	author: 'Jean-Pierre DUPONT',
	icon: 'fa fa-file-excel-o'
};
var actions = [{
	key: 'edit',
	label: 'Edit',
	icon: 'fa fa-edit',
	onClick: jest.fn()
}, {
	key: 'delete',
	label: 'Delete',
	icon: 'fa fa-trash-o',
	onClick: jest.fn()
}];

describe('Item', function () {
	it('should render', function () {
		// given
		var props = {
			item: item,
			columns: columns
		};

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

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

	it('should render with id if provided', function () {
		// given
		var props = {
			id: 'list-item',
			item: item,
			columns: columns
		};

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

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

	it('should render with item custom className', function () {
		// given
		var props = {
			item: _extends({}, item, { className: 'item-1-class' }),
			columns: columns,
			itemProps: { classNameKey: 'className' }
		};

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

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

	it('should render with selected item', function () {
		// given
		var props = {
			item: item,
			columns: columns,
			itemProps: { isSelected: function isSelected() {
					return true;
				} }
		};

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

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

	it('should render with custom selected class', function () {
		// given
		var props = {
			item: item,
			columns: columns,
			itemProps: {
				isSelected: function isSelected() {
					return function () {
						return true;
					};
				},
				selectedClass: 'selectedClass'
			}
		};

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

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

	it('should render with actions', function () {
		// given
		var props = {
			item: item,
			actions: actions,
			columns: columns
		};

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

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

	it('should render with icon', function () {
		// given
		var props = {
			item: item,
			columns: [{ key: 'icon', label: '', type: 'icon' }].concat(columns)
		};

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

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