'use strict';

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

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

var _reactTestRenderer2 = _interopRequireDefault(_reactTestRenderer);

var _Toolbar = require('./Toolbar.component');

var _Toolbar2 = _interopRequireDefault(_Toolbar);

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

jest.mock('react-dom');

var id = 'my-toolbar';

var actionBar = {
	selected: 1,
	actions: {
		left: [{
			id: 'add',
			label: 'Add',
			bsStyle: 'primary',
			icon: 'talend-plus',
			onClick: jest.fn()
		}]
	},
	multiSelectActions: {
		left: [{
			id: 'delete',
			label: 'Delete selection',
			icon: 'talend-trash',
			onClick: jest.fn()
		}]
	}
};

var selectAllCheckbox = {
	items: [{ id: 1 }, { id: 2 }],
	isSelected: jest.fn(),
	onToggleAll: jest.fn()
};

var display = {
	displayMode: 'table',
	onSelectDisplayMode: jest.fn()
};

var sort = {
	field: 'id',
	isDescending: true,
	onChange: jest.fn(),
	options: [{ id: 'id', name: 'Id' }, { id: 'name', name: 'Name' }]
};

var pagination = {
	startIndex: 6,
	totalResults: 13,
	onChangePagination: jest.fn(),
	itemsPerPage: 5
};

var filter = {
	onFilter: jest.fn(),
	onToggle: jest.fn()
};

describe('Toolbar', function () {
	it('should render empty toolbar', function () {
		// when
		var wrapper = _reactTestRenderer2.default.create(_react2.default.createElement(_Toolbar2.default, null)).toJSON();

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

	it('should render actions toolbar', function () {
		// given
		var tProps = {
			id: id,
			actionBar: {
				actions: actionBar.actions
			}
		};

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

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

	it('should render actions toolbar with selected items', function () {
		// given
		var tProps = {
			id: id,
			actionBar: actionBar
		};

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

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

	it('should render select all checkbox', function () {
		// given
		var tProps = {
			id: id,
			selectAllCheckbox: selectAllCheckbox
		};

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

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

	it('should render display mode selector', function () {
		// given
		var tProps = {
			id: id,
			display: display
		};

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

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

	it('should render sort selector', function () {
		// given
		var tProps = {
			id: id,
			sort: sort
		};

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

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

	it('should render filter form', function () {
		// given
		var tProps = {
			id: id,
			filter: filter
		};

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

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

	it('should render pagination', function () {
		// given
		var tProps = {
			id: id,
			pagination: pagination
		};

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

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