Skip to content

Commit

Permalink
fix: resizing pairwise when removedIndex is 0
Browse files Browse the repository at this point in the history
  • Loading branch information
laurentC35 committed Jan 9, 2025
1 parent e2f002a commit ed1e41d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
21 changes: 21 additions & 0 deletions src/use-lunatic/commons/variables/lunatic-variables-store.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down

0 comments on commit ed1e41d

Please sign in to comment.