Commit 751ea946 authored by Jaden's avatar Jaden Committed by Flavio TARSETTI

[js][algorithm] restrict param ranges, closes #206

parent d65987d9
Pipeline #29710 passed with stages
in 20 minutes and 19 seconds
......@@ -273,11 +273,15 @@ export default class ParameterCreate extends React.Component<Props, State> {
value={param.range[0]}
onChange={e => {
const num = e.target.value;
const max = param.range[1];
if(num > max){
return;
}
const newParam = {
...param,
range: [
num,
param.range[1],
max,
]
};
updateParameter(
......@@ -299,10 +303,14 @@ export default class ParameterCreate extends React.Component<Props, State> {
required
onChange={e => {
const num = e.target.value;
const min = param.range[0];
if(num < min){
return;
}
const newParam = {
...param,
range: [
param.range[0],
min,
num,
]
};
......
......@@ -62,4 +62,75 @@ describe('<ParameterCreate />', () => {
description: '',
});
});
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]);
});
});
});
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment