Skip to content

Commit

Permalink
Merge branch '2.7' into fix/label-roster
Browse files Browse the repository at this point in the history
  • Loading branch information
ddecrulle authored Jan 16, 2024
2 parents ce84070 + f5b7fbf commit b380e4a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
11 changes: 11 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 @@ -204,6 +204,17 @@ describe('lunatic-variables-store', () => {
);
expect(variables.get('FULLNAME')).toEqual(['John 1', 'Jane 2']);
});
it('should handle aggregate functions', () => {
variables.set('AGE', [1, 2, 3]);
variables.setCalculated('MAXAGE', 'max(AGE)');
variables.setCalculated('AGE_AND_MAX', 'AGE + MAXAGE', {
shapeFrom: 'AGE',
});
expect(variables.get('AGE_AND_MAX', [0])).toEqual(4);
variables.set('AGE', 12, { iteration: [1] });
expect(variables.get('AGE', [1])).toEqual(12);
expect(variables.get('AGE_AND_MAX', [0])).toEqual(13);
});
});

describe('resizing', () => {
Expand Down
7 changes: 6 additions & 1 deletion src/use-lunatic/commons/variables/lunatic-variables-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,12 @@ class LunaticVariable {
0,
...this.getDependencies().map(
(dep) =>
this.dictionary?.get(dep)?.updatedAt.get(iteration?.join('.')) ?? 0
// Check when a value at the same iteration was calculated
this.dictionary?.get(dep)?.updatedAt.get(iteration?.join('.')) ??
// For aggregated value (max / min) look the global updatedAt time
this.dictionary?.get(dep)?.updatedAt.get(undefined) ??
// Otherwise this is a static value that never changes
0
)
);
return (
Expand Down

0 comments on commit b380e4a

Please sign in to comment.