'use strict';

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _VirtualizedList = require('../VirtualizedList.component');

var _VirtualizedList2 = _interopRequireDefault(_VirtualizedList);

var _tablerow = require('./tablerow');

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

describe('tablerow', function () {
	describe('#insertSelectionConfiguration', function () {
		it('should insert selection column when selection callback is provided', function () {
			// given
			var isSelected = jest.fn();
			var selectionToggle = jest.fn();
			var children = [_react2.default.createElement(_VirtualizedList2.default.Content, {
				label: 'Id',
				dataKey: 'id',
				width: 50
			}), _react2.default.createElement(_VirtualizedList2.default.Content, {
				label: 'Name',
				dataKey: 'name',
				width: 350
			})];

			// when
			var result = (0, _tablerow.insertSelectionConfiguration)({
				children: children,
				isSelected: isSelected,
				selectionToggle: selectionToggle
			});

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

		it('should NOT insert selection column when selection callback is NOT provided', function () {
			// given
			var children = [_react2.default.createElement(_VirtualizedList2.default.Content, {
				label: 'Id',
				dataKey: 'id',
				width: 50
			}), _react2.default.createElement(_VirtualizedList2.default.Content, {
				label: 'Name',
				dataKey: 'name',
				width: 350
			})];

			// when
			var result = (0, _tablerow.insertSelectionConfiguration)({ children: children });

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

	describe('#toColumns', function () {
		it('should create column with enhanced header classname from theme', function () {
			// given
			var theme = { header: 'theme-header-classname' };
			var children = [_react2.default.createElement(_VirtualizedList2.default.Content, {
				label: 'Id',
				dataKey: 'id',
				headerClassName: 'my-header-classname',
				width: 50
			})];

			// when
			var result = (0, _tablerow.toColumns)(null, theme, children);

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

		it('should create column with enhanced classname from theme', function () {
			// given
			var theme = { cell: 'theme-classname' };
			var children = [_react2.default.createElement(_VirtualizedList2.default.Content, {
				label: 'Id',
				dataKey: 'id',
				className: 'my-classname',
				width: 50
			})];

			// when
			var result = (0, _tablerow.toColumns)(null, theme, children);

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

		it('should add id in columns data', function () {
			// given
			var id = 'my-id';
			var children = [_react2.default.createElement(_VirtualizedList2.default.Content, {
				label: 'Id',
				dataKey: 'id',
				columnData: { custom: 'lol' },
				width: 50
			})];

			// when
			var result = (0, _tablerow.toColumns)(id, {}, children);

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