import React from 'react';
import ListItem from '../ListItem';
import renderer from 'react-test-renderer';
import { shallow } from 'enzyme';

const PROPS = {
	item: { word: 'fructuary', index: -1 },
	index: 0,
	overItem: false,
	onItemClick: jest.fn(),
	onItemMouseEnter: jest.fn(),
	search: 'ss'
};

describe('<ListItem/>', () => {
	it('snapshot', () => {
		const tree = renderer.create(<ListItem {...PROPS} />).toJSON();
		expect(tree).toMatchSnapshot();
	});

	it('snapshot - hover', () => {
		const tree = renderer.create(<ListItem {...PROPS} overItem />).toJSON();
		expect(tree).toMatchSnapshot();
	});
});

describe('ListItem', () => {
	const event = { stopPropagation: jest.fn() };
	let component;

	beforeEach(() => {
		PROPS.onItemClick.mockReset();
		PROPS.onItemMouseEnter.mockReset();
		component = shallow(<ListItem {...PROPS} />);
		event.stopPropagation.mockClear();
	});

	describe('on click', () => {
		let handleClickSpy;
		beforeEach(() => {
			handleClickSpy = jest.spyOn(component.instance(), 'handleClick');
			component.instance().forceUpdate();
			component.update();

			component.find('li').simulate('click', event);
		});

		it('should call handleClick', () => {
			expect(handleClickSpy).toBeCalled();
		});

		it('should stop event propagation', () => {
			expect(event.stopPropagation).toHaveBeenCalled();
		});

		it('should call props.onItemClick', () => {
			expect(PROPS.onItemClick).toBeCalledWith(PROPS.item);
		});
	});

	describe('on mouse enter', () => {
		let handleMouseEnterSpy;
		beforeEach(() => {
			handleMouseEnterSpy = jest.spyOn(component.instance(), 'handleMouseEnter');
			component.instance().forceUpdate();
			component.update();

			component.find('li').simulate('mouseEnter', event);
		});

		it('should call handleMouseEnter', () => {
			expect(handleMouseEnterSpy).toBeCalled();
		});

		it('should stop event propagation', () => {
			expect(event.stopPropagation).toHaveBeenCalled();
		});

		it('should call props.onItemClick', () => {
			expect(PROPS.onItemMouseEnter).toBeCalledWith(PROPS.index);
		});
	});
});

@@ -698,16 +698,58 @@
 mponent;
+%0A%09let handleClickSpy, handleMouseEnterSpy;
 %0A%0A%09befor
@@ -833,16 +833,53 @@
 eset();%0A
+%09%09event.stopPropagation.mockClear();%0A
 %09%09compon
@@ -924,85 +924,88 @@
 ;%0A%09%09
-event.stopPropagation.mockClear();%0A%09%7D);%0A%0A%09describe('on click', () =%3E %7B%0A%09%09let 
+const instance = component.instance();%0A%09%09handleClickSpy = jest.spyOn(instance, '
 hand
@@ -1015,48 +1015,30 @@
 lick
-Spy
+')
 ;%0A%09%09
-beforeEach(() =%3E %7B%0A%09%09%09handleClick
+handleMouseEnter
 Spy 
@@ -1050,34 +1050,24 @@
 t.spyOn(
-component.
 instance
 (), 'han
@@ -1050,34 +1050,32 @@
 t.spyOn(instance
-()
 , 'handleClick')
@@ -1071,38 +1071,32 @@
 ndle
-Click');%0A%09%09%09component.
+MouseEnter');%0A%09%09
 instance
 ().f
@@ -1083,34 +1083,32 @@
 er');%0A%09%09instance
-()
 .forceUpdate();%0A
@@ -1099,33 +1099,32 @@
 .forceUpdate();%0A
-%09
 %09%09component.upda
@@ -1121,32 +1121,88 @@
 onent.update();%0A
+%09%7D);%0A%0A%09describe('on click', () =%3E %7B%0A%09%09beforeEach(() =%3E %7B
 %0A%09%09%09component.fi
@@ -1446,38 +1446,32 @@
 it('should call 
-props.
 onItemClick', ()
@@ -1457,32 +1457,46 @@
 call onItemClick
+ prop callback
 ', () =%3E %7B%0A%09%09%09ex
@@ -1601,195 +1601,26 @@
 %7B%0A%09%09
-let handleMouseEnterSpy;%0A%09%09beforeEach(() =%3E %7B%0A%09%09%09handleMouseEnterSpy = jest.spyOn(component.instance(), 'handleMouseEnter');%0A%09%09%09component.instance().forceUpdate();%0A%09%09%09component.update();%0A
+beforeEach(() =%3E %7B
 %0A%09%09%09
@@ -1852,35 +1852,42 @@
 pagation
-).toHaveBeenCalled(
+.mock.calls.length).toBe(1
 );%0A%09%09%7D);
@@ -1910,23 +1910,36 @@
 all 
-props.onItemCli
+onItemMouseEnter prop callba
 ck',

update ListItem spec