'use strict';

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

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

var _reactTestRenderer2 = _interopRequireDefault(_reactTestRenderer);

var _DisplayTile = require('./DisplayTile.component');

var _DisplayTile2 = _interopRequireDefault(_DisplayTile);

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

jest.mock('react-dom');

var items = [{
	id: 1,
	name: 'Hello world',
	created: '2016-09-22',
	modified: '2016-09-22',
	author: 'Jean-Pierre DUPONT',
	actions: [{
		label: 'edit',
		icon: 'fa fa-edit',
		onClick: jest.fn()
	}, {
		label: 'delete',
		icon: 'fa fa-trash-o',
		onClick: jest.fn()
	}],
	icon: 'fa fa-file-excel-o',
	className: 'item-0-class'
}, {
	id: 2,
	name: 'Foo',
	created: '2016-09-22',
	modified: '2016-09-22',
	author: 'Jean-Pierre DUPONT',
	icon: 'fa fa-file-pdf-o',
	className: 'item-1-class'
}, {
	id: 2,
	name: 'Bar',
	created: '2016-09-22',
	modified: '2016-09-22',
	author: 'Jean-Pierre DUPONT'
}];

var columns = [{ key: 'id', label: 'Id' }, { key: 'name', label: 'Name' }, { key: 'author', label: 'Author' }, { key: 'created', label: 'Created' }, { key: 'modified', label: 'Modified' }];

describe('DisplayTile', function () {
	it('should render 3 tiles with name as title by default', function () {
		// given
		var props = {
			items: items,
			columns: columns
		};

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

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

	it('should render 3 tiles with id as title by setting', function () {
		// given
		var props = {
			items: items,
			columns: columns,
			titleProps: {
				key: 'id', // title key defined
				iconKey: 'icon'
			}
		};

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

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

	it('should render 3 tiles which render a title buttons', function () {
		// given
		var props = {
			items: items,
			columns: columns,
			titleProps: {
				key: 'name',
				iconKey: 'icon',
				onClick: jest.fn() // title click callback defined
			}
		};

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

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

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

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

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

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

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

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

	it('shoudl render selected list element with defaut \'active\' class', function () {
		// given
		var props = {
			id: 'tile-list',
			items: items,
			columns: columns,
			itemProps: { isSelected: function isSelected() {
					return true;
				} }
		};

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

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

	it('shoudl render selected list element with custom selectedClass if set', function () {
		// given
		var props = {
			id: 'tile-list',
			items: items,
			columns: columns,
			itemProps: { isSelected: function isSelected() {
					return true;
				}, selectedClass: 'something' }
		};

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

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