Commit b42f3e43 authored by Jaden Diefenbaugh's avatar Jaden Diefenbaugh Committed by Flavio Tarsetti

better unique keys when add new i/o, fixes #176

parent 7b1f7ce1
Pipeline #26673 passed with stages
in 49 minutes and 17 seconds
......@@ -87,7 +87,8 @@ const newCacheFromData = (data: BlockType): ModalCache => {
const getCurrentObjs = (arr: any) => arr
.filter((o, i, os) => o.action !== 'delete' && !os.slice(i).find(p => p.action === 'delete' && p.name === o.name));
const getCurrentNames = (arr: any) => getCurrentObjs(arr).map(o => o.name);
const getCurrentNames = (arr: any): string[] => getCurrentObjs(arr).map(o => o.name);
const getCurrentNameKeys = (arr: any): string[] => getCurrentObjs(arr).reduce((names, o) => [...names, o.name, o.original], []);
class ToolchainModal extends React.Component<Props, State> {
constructor(props: Props){
......@@ -113,7 +114,7 @@ class ToolchainModal extends React.Component<Props, State> {
addIO = (io: boolean) => {
const arr = io ? 'inputs' : 'outputs';
const newKey = generateNewKey(io ? 'input' : 'output', getCurrentNames(this.state.cache[arr]));
const newKey = generateNewKey(io ? 'input' : 'output', getCurrentNameKeys(this.state.cache[arr]));
this.setState({
cache: {
...this.state.cache,
......
......@@ -169,4 +169,33 @@ describe('<ToolchainModal />', function () {
{ action: 'change', name: 'input0', original: 'input1' },
]);
});
it('doesnt change the name of multiple inputs/outputs at a time', async () => {
const newBlockName = 'block';
wrapper = mount(
<C
active={true}
data={testBlockData2}
blockNames={testBlockNames}
possibleChannels={testChannels}
toggle={() => {}}
deleteBlock={() => {}}
updateBlockData={() => {}}
createAlgorithmFromBlock={() => {}}
/>
);
wrapper.find('button.btn.btn-secondary').at(1).simulate('click');;
wrapper.update();
expect(wrapper.state('cache').inputs[2]).to.deep.equal({ action: 'add', name: 'input', original: 'input' });
wrapper.find('CacheInput[value="input"]').prop('onChange')( { target: { value: 'test0' }});
wrapper.update();
wrapper.find('button.btn.btn-secondary').at(1).simulate('click');;
wrapper.update();
expect(wrapper.state('cache').inputs[3]).to.deep.equal({ action: 'add', name: 'input2', original: 'input2' });
wrapper.find('CacheInput[value="input2"]').prop('onChange')( { target: { value: 'test1' }});
wrapper.update();
expect(wrapper.state('cache').inputs[2]).to.deep.equal({ action: 'add', name: 'test0', original: 'input' });
expect(wrapper.state('cache').inputs[3]).to.deep.equal({ action: 'add', name: 'test1', original: 'input2' });
});
});
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