'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 _ItemEdit = require('./ItemEdit.component');

var _ItemEdit2 = _interopRequireDefault(_ItemEdit);

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

var item = {
	values: ['toto'],
	itemProps: {
		key: 'values',
		onSubmitItem: jest.fn(), // provided click callback
		onChangeItem: jest.fn(),
		onAbortItem: jest.fn(), // provided click callback
		actions: [{
			label: 'Validate',
			id: 'validate',
			onClick: jest.fn() // provided click callback
		}, {
			label: 'Cancel',
			id: 'cancel',
			onClick: jest.fn() // provided click callback
		}]
	}
};

describe('Item', function () {
	it('should display input value with two buttons', function () {
		// given
		var props = {
			id: '0-item',
			item: item,
			currentEdit: {
				validate: {
					disabled: false
				}
			}
		};

		function createNodeMock(element) {
			if (element.type === 'input') {
				return {};
			}
			return null;
		}
		var rendererOptions = { createNodeMock: createNodeMock };

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

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

	it('should display input value with two buttons. The validate button is disabled', function () {
		// given
		var props = {
			id: '0-item',
			item: item,
			currentEdit: {
				validate: {
					disabled: true
				}
			}
		};

		function createNodeMock(element) {
			if (element.type === 'input') {
				return {};
			}
			return null;
		}
		var rendererOptions = { createNodeMock: createNodeMock };

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

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

	it('should display input value with error', function () {
		// given
		var errorItem = _extends({}, item);
		errorItem.error = 'an error occured';
		var props = {
			id: '0-item',
			item: errorItem,
			currentEdit: {
				validate: {
					disabled: false
				}
			}
		};

		function createNodeMock(element) {
			if (element.type === 'input') {
				return {};
			}
			return null;
		}
		var rendererOptions = { createNodeMock: createNodeMock };

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

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