ParameterCreate.spec.jsx 3.29 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
// @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: '',
		});
	});
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135

	describe.only('regression', () => {
		it(`doesnt let min be larger than max in a range parameter`, () => {
			let param = {
				type: 'int8',
				default: '',
				description: '',
				range: [
					1,
					2
				]
			};
			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[step="1"]').at(0).prop('onChange')( { target: { value: 3 }});
			wrapper.update();
			expect(updateParameter.callCount).to.equal(0);
			expect(wrapper.props().param.range).to.deep.equal([1, 2]);

			wrapper.find('Input[step="1"]').at(0).prop('onChange')( { target: { value: 2 }});
			wrapper.update();
			expect(updateParameter.callCount).to.equal(1);
			expect(wrapper.props().param.range).to.deep.equal([2, 2]);
		});
		it(`doesnt let max be smaller than min in a range parameter`, () => {
			let param = {
				type: 'int8',
				default: '',
				description: '',
				range: [
					3,
					4
				]
			};
			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[step="1"]').at(1).prop('onChange')( { target: { value: 1 }});
			wrapper.update();
			expect(updateParameter.callCount).to.equal(0);
			expect(wrapper.props().param.range).to.deep.equal([3, 4]);

			wrapper.find('Input[step="1"]').at(1).prop('onChange')( { target: { value: 3 }});
			wrapper.update();
			expect(updateParameter.callCount).to.equal(1);
			expect(wrapper.props().param.range).to.deep.equal([3, 3]);
		});
	});
136
});