'use strict';

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

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

var _reactTestRenderer2 = _interopRequireDefault(_reactTestRenderer);

var _Items = require('./Items.component');

var _Items2 = _interopRequireDefault(_Items);

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

jest.mock('../../../node_modules/react-virtualized/dist/commonjs/AutoSizer/AutoSizer', function () {
	return function (props) {
		return _react2.default.createElement(
			'div',
			{ id: 'autoSizer' },
			props.children({ height: 30, width: 30 })
		);
	};
} // eslint-disable-line react/prop-types
);
var ITEMS_DEFAULT_HEIGHT = 42;

describe('Items', function () {
	it('should display one item in edit mode and the other in default', function () {
		// given
		var props = {
			items: Array(3).fill('').map(function (item, index) {
				return {
					values: ['Lorem ipsum dolor sit amet ' + index]
				};
			}),
			currentEdit: {
				validate: {
					disabled: false
				}
			},
			itemsProp: {
				key: 'values',
				onSubmitItem: jest.fn(),
				onAbortItem: jest.fn(),
				onSelectItem: jest.fn(),
				getItemHeight: function getItemHeight() {
					return ITEMS_DEFAULT_HEIGHT;
				},
				actionsDefault: [{
					disabled: false,
					label: 'Edit',
					icon: 'talend-pencil',
					id: 'edit',
					onClick: jest.fn()
				}, {
					label: 'Delete',
					icon: 'talend-trash',
					id: 'delete',
					onClick: jest.fn()
				}],
				actionsEdit: [{
					disabled: false,
					label: 'Validate',
					icon: 'talend-check',
					id: 'validate',
					onClick: jest.fn()
				}]
			}
		};

		props.items[0].displayMode = 'DISPLAY_MODE_EDIT';

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

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

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