// @flow
import React from 'react';
import { expect } from 'chai';
import { mount } from 'enzyme';
import sinon from 'sinon';
import { spies } from '@test';

import C from './CacheInput.jsx';

describe('<CacheInput />', () => {
	let wrapper;
	const validateFunc = sinon.spy();
	const onChange = sinon.spy();
	const fieldTest = true;
	const children = <span>child</span>;
	const value = 'value';

	afterEach(() => {
		if(wrapper && wrapper.unmount)
			wrapper.unmount();
	});

	it(`has 2 required props`, () => {
		wrapper = mount(
			<C
				onChange={onChange}
				value={value}
			/>
		);

		expect(wrapper).to.have.props(
			['onChange', 'value']
		).deep.equal(
			[onChange, value]
		);

		expect(wrapper).to.not.have.props(
			['validateFunc', 'fieldTest', 'children']
		);
	});

	it(`can take up to 5 props`, () => {
		const validateFunc = sinon.spy();
		const onChange = sinon.spy();
		const fieldTest = true;
		const children = <span>child</span>;
		const value = 'value';
		wrapper = mount(
			<C
				validateFunc={validateFunc}
				onChange={onChange}
				fieldTest={fieldTest}
				value={value}
			>{ children }</C>
		);

		expect(wrapper).to.have.props(
			['validateFunc', 'onChange', 'fieldTest', 'value', 'children']
		).deep.equal(
			[validateFunc, onChange, fieldTest, value, children]
		);
	});
});
