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

import C from './ParameterCreate.jsx';

describe('<ParameterCreate />', () => {
	let wrapper;
	const name = 'parameter';
	// shortcut for a func to update just the parameter obj, not the name
	const _updateParameter = (name, p, oldName) => {
		wrapper.setProps({
			param: p,
		});
	};
	const params = [];

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

	it(`saves the default value of a boolean parameter`, () => {
		let param = {
			type: '',
			default: '',
			description: '',
		};
		const updateParameter = sinon.spy(_updateParameter);

		wrapper = mount(
			<C
				name={name}
				param={param}
				params={params}
				updateParameter={updateParameter}
			/>
		);

		// sanity checks
		expect(wrapper.find('TypedField')).to.have.prop('name', name);

		wrapper.find('Input.custom-select').prop('onChange')( { target: { value: 'bool' }});
		wrapper.update();
		expect(wrapper.props().param).to.deep.equal(
			{
				type: 'bool',
				default: '',
				description: '',
			}
		);

		wrapper.find('input[type="radio"]').at(0).simulate('change', { target: { checked: 'true' }});;
		//wrapper.find('input[type="radio"]').at(0).simulate('change', { target: { value: 'true' }});;
		wrapper.update();
		expect(wrapper.props().param).to.deep.equal({
			type: 'bool',
			default: true,
			description: '',
		});
	});
});
