Commit 38ea1b96 authored by Jaden DIEFENBAUGH's avatar Jaden DIEFENBAUGH
Browse files

[experiment] fix copying experiments auto-versioning, #90

parent 3ac81317
Pipeline #20309 passed with stages
in 81 minutes and 25 seconds
......@@ -60,16 +60,19 @@ type State = {
};
const getStartNameSegs = (copyObj?: BeatObject, existingNames: string[], entity: BeatEntity, nameOrVersion: boolean) => {
const autoVersion = entity !== 'experiment';
if(copyObj){
const newName = copyObj.name || '';
const segs = newName.split('/');
const version = Number.parseInt(segs[segs.length - 1]);
segs[segs.length - 1] = `${ nameOrVersion ? 1 : version + 1 }`;
if(autoVersion){
const version = Number.parseInt(segs[segs.length - 1]);
segs[segs.length - 1] = `${ nameOrVersion ? 1 : version + 1 }`;
}
return segs;
} else {
const len = nameSegmentsForEntity(entity);
return Array.apply(null, Array(len)).map((u, i) => i === len - 1 && autoVersion ? '1' : '');
}
const len = nameSegmentsForEntity(entity);
return Array.apply(null, Array(len)).map((u, i) => i === len - 1 ? '1' : '');
};
export class NewEntityModal extends React.Component<Props, State> {
......
......@@ -378,4 +378,70 @@ describe.only('<NewEntityModal />', () => {
expect(inputs.get(2).props.disabled).to.equal(true);
});
});
describe('for experiments', () => {
const entity = 'experiment';
it(`properly handles creating a new object`, () => {
const nameOrVersion = true;
const copyObj = undefined;
const newNameSegs = ['', '', '', '', ''];
wrapper = mount(
<C
isOpen={isOpen}
toggle={toggle}
create={create}
entity={entity}
data={test_exps}
algorithms={test_algs}
toolchains={test_tcs}
nameOrVersion={nameOrVersion}
copyObj={copyObj}
/>
);
expect(wrapper.state('numSegs')).to.equal(5);
expect(wrapper.state('nameSegs')).to.deep.equal(newNameSegs);
const inputs = wrapper.find('input');
const select = wrapper.find('select');
expect(inputs).to.have.length(2);
expect(inputs.get(0).props.value).to.equal(newNameSegs[0]);
expect(inputs.get(0).props.disabled).to.be.undefined;
expect(select.get(0).props.value).to.equal('');
expect(select.get(0).props.disabled).to.be.undefined;
expect(inputs.get(1).props.value).to.equal(newNameSegs[4]);
expect(inputs.get(1).props.disabled).to.be.undefined;
});
it(`properly handles copying`, () => {
const nameOrVersion = true;
const copyObj = test_exps[0];
const oldNameSegs = copyObj.name.split('/');
const newNameSegs = [...oldNameSegs];
wrapper = mount(
<C
isOpen={isOpen}
toggle={toggle}
create={create}
entity={entity}
data={test_exps}
algorithms={test_algs}
toolchains={test_tcs}
nameOrVersion={nameOrVersion}
copyObj={copyObj}
/>
);
expect(wrapper.state('numSegs')).to.equal(5);
expect(wrapper.state('nameSegs')).to.deep.equal(newNameSegs);
const inputs = wrapper.find('input');
const select = wrapper.find('select');
expect(inputs).to.have.length(2);
expect(inputs.get(0).props.value).to.equal(newNameSegs[0]);
expect(inputs.get(0).props.disabled).to.be.undefined;
expect(select.get(0).props.value).to.equal(newNameSegs.slice(1, 4).join('/'));
expect(select.get(0).props.disabled).to.be.undefined;
expect(inputs.get(1).props.value).to.equal(newNameSegs[4]);
expect(inputs.get(1).props.disabled).to.be.undefined;
});
});
});
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