diff --git a/src/use-lunatic/commons/variables/behaviours/resizing-behaviour.ts b/src/use-lunatic/commons/variables/behaviours/resizing-behaviour.ts index 8e9b8a51d..a718c36ad 100644 --- a/src/use-lunatic/commons/variables/behaviours/resizing-behaviour.ts +++ b/src/use-lunatic/commons/variables/behaviours/resizing-behaviour.ts @@ -90,7 +90,7 @@ function resizePairwise( resizingInfo.linksVariables.forEach((variable) => { const value = store.get(variable, args.iteration); let resizedValue; - if (args.removedIndex) { + if (args.removedIndex !== undefined) { const removedIndex = args.removedIndex; resizedValue = resizeDownArrayWithIndex( Array.isArray(value) diff --git a/src/use-lunatic/commons/variables/lunatic-variables-store.spec.ts b/src/use-lunatic/commons/variables/lunatic-variables-store.spec.ts index 6d5d5bc8e..baec44525 100644 --- a/src/use-lunatic/commons/variables/lunatic-variables-store.spec.ts +++ b/src/use-lunatic/commons/variables/lunatic-variables-store.spec.ts @@ -388,6 +388,27 @@ describe('lunatic-variables-store', () => { ]); expect(variables.get('NOM') as string[]).toEqual([null, null, null]); }); + it('should handle both: pairwise resize with index 0', () => { + variables.set('PRENOM', ['John', 'Jane', 'Marc']); + variables.set('LINKS', [ + [null, 2, 4], + [1, null, 2], + [3, 2, null], + ]); + resizingBehaviour(variables, { + PRENOM: { + sizeForLinksVariables: ['count(PRENOM)', 'count(PRENOM)'], + linksVariables: ['LINKS'], + size: 'count(PRENOM)', + }, + }); + variables.set('PRENOM', ['John', 'Marc'], { removedIndex: 0 }); + expect(variables.get('LINKS') as string[][]).toEqual([ + [null, 2], + [2, null], + ]); + }); + it('should handle both: pairwise and normal resize with index', () => { variables.set('PRENOM', ['John', 'Jane', 'Marc']); variables.set('AGE', [40, 30, 20]);