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

var _SelectSortBy = require('./SelectSortBy.component');

var _SelectSortBy2 = _interopRequireDefault(_SelectSortBy);

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

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

describe('SelectSortBy', function () {
	it('should render', function () {
		// given
		var props = _extends({
			field: field
		}, requiredProps);

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

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

	it('should render with no dropdown', function () {
		// given
		var props = _extends({
			field: field
		}, requiredProps, {
			options: [{ id: 'id', name: 'Id' }]
		});

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

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

	it('should render without field selected', function () {
		// when
		var wrapper = _reactTestRenderer2.default.create(_react2.default.createElement(_SelectSortBy2.default, requiredProps)).toJSON();

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

	it('should render id if provided', function () {
		// given
		var props = _extends({
			id: id,
			field: field
		}, requiredProps);

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

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

	it('should call toggle callback on sort-order click', function () {
		// given
		var props = _extends({
			id: id,
			field: field
		}, requiredProps);
		var event = { target: {} };

		// when
		var wrapper = (0, _enzyme.shallow)(_react2.default.createElement(_SelectSortBy2.default, props));
		wrapper.find('#toolbar-sort-order').simulate('click', event);

		// then
		expect(props.onChange).toBeCalledWith(event, {
			field: 'id',
			isDescending: true
		});
	});
});