@inseefr/lunatic 2.7.14 → 2.7.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/components/checkbox/checkbox-boolean/lunatic-checkbox-boolean.js +3 -1
- package/lib/components/checkbox/checkbox-group/lunatic-checkbox-group.js +4 -1
- package/lib/components/checkbox/checkbox-one/lunatic-checkbox-one.js +7 -2
- package/lib/components/commons/components/missing/missing.js +4 -1
- package/lib/components/commons/components/missing/missing.scss +26 -29
- package/lib/components/datepicker/lunatic-datepicker.js +1 -0
- package/lib/components/dropdown/lunatic-dropdown.js +1 -0
- package/lib/components/duration/duration.js +4 -1
- package/lib/components/input/lunatic-input.js +1 -0
- package/lib/components/input-number/lunatic-input-number.js +1 -0
- package/lib/components/radio/lunatic-radio-group.js +1 -0
- package/lib/components/suggester/lunatic-suggester.js +1 -0
- package/lib/components/switch/lunatic-switch.js +7 -2
- package/lib/components/textarea/lunatic-textarea.js +3 -1
- package/lib/src/components/checkbox/checkbox-boolean/lunatic-checkbox-boolean.d.ts +1 -1
- package/lib/src/components/checkbox/checkbox-group/lunatic-checkbox-group.d.ts +1 -1
- package/lib/src/components/checkbox/checkbox-one/lunatic-checkbox-one.d.ts +1 -1
- package/lib/src/components/commons/components/lunatic-component-without-label.d.ts +1 -1
- package/lib/src/components/commons/components/missing/missing.d.ts +2 -1
- package/lib/src/components/switch/html/switch.d.ts +1 -0
- package/lib/src/components/switch/lunatic-switch.d.ts +1 -1
- package/lib/src/use-lunatic/commons/execute-condition-filter.d.ts +1 -1
- package/lib/src/use-lunatic/commons/variables/lunatic-variables-store.d.ts +1 -0
- package/lib/src/utils/array.d.ts +11 -0
- package/lib/src/utils/variables.spec.d.ts +1 -0
- package/lib/stories/behaviour/missing/missing.stories.js +90 -0
- package/lib/stories/behaviour/missing/source.json +822 -0
- package/lib/stories/utils/referentiel.js +3 -3
- package/lib/use-lunatic/commons/execute-condition-filter.js +4 -1
- package/lib/use-lunatic/commons/fill-components/fill-component-expressions.js +4 -2
- package/lib/use-lunatic/commons/variables/lunatic-variables-store.js +28 -17
- package/lib/use-lunatic/commons/variables/lunatic-variables-store.spec.js +20 -5
- package/lib/utils/array.js +34 -0
- package/lib/utils/array.spec.js +5 -0
- package/lib/utils/variables.js +4 -15
- package/lib/utils/variables.spec.js +74 -0
- package/package.json +1 -1
|
@@ -17,15 +17,15 @@ var getReferentiel = exports.getReferentiel = /*#__PURE__*/function () {
|
|
|
17
17
|
_context.next = _context.t0 === 'libelle-pcs2020' ? 3 : _context.t0 === 'naf-rev2-stop' ? 4 : _context.t0 === 'naf-rev2' ? 4 : _context.t0 === 'cog-communes' ? 5 : 6;
|
|
18
18
|
break;
|
|
19
19
|
case 3:
|
|
20
|
-
return _context.abrupt("return", fetch('
|
|
20
|
+
return _context.abrupt("return", fetch('./libelles-pcs-2020.json').then(function (r) {
|
|
21
21
|
return r.json();
|
|
22
22
|
}));
|
|
23
23
|
case 4:
|
|
24
|
-
return _context.abrupt("return", fetch('
|
|
24
|
+
return _context.abrupt("return", fetch('./naf-rev2.json').then(function (r) {
|
|
25
25
|
return r.json();
|
|
26
26
|
}));
|
|
27
27
|
case 5:
|
|
28
|
-
return _context.abrupt("return", fetch('
|
|
28
|
+
return _context.abrupt("return", fetch('./communes-2019.json').then(function (r) {
|
|
29
29
|
return r.json();
|
|
30
30
|
}));
|
|
31
31
|
case 6:
|
|
@@ -5,13 +5,16 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports["default"] = void 0;
|
|
7
7
|
var _getCompatibleVtlExpression = _interopRequireDefault(require("./get-compatible-vtl-expression"));
|
|
8
|
+
var _array = require("../../utils/array");
|
|
8
9
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
9
10
|
function executeConditionFilter(filter, execute, iteration) {
|
|
10
11
|
if (filter && typeof execute === 'function') {
|
|
11
12
|
var value = filter.value;
|
|
12
|
-
|
|
13
|
+
var result = execute((0, _getCompatibleVtlExpression["default"])(value), {
|
|
13
14
|
iteration: iteration
|
|
14
15
|
});
|
|
16
|
+
// Todo : replace this with a casting system on execute
|
|
17
|
+
return Array.isArray(result) ? (0, _array.firstValueItem)(result) : result;
|
|
15
18
|
}
|
|
16
19
|
return undefined;
|
|
17
20
|
}
|
|
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports["default"] = void 0;
|
|
7
7
|
var _isObject = require("../../../utils/is-object");
|
|
8
|
+
var _array = require("../../../utils/array");
|
|
8
9
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
9
10
|
function _toArray(arr) { return _arrayWithHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableRest(); }
|
|
10
11
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
@@ -38,9 +39,10 @@ function createCrawl(_ref) {
|
|
|
38
39
|
function executeAndFillObject(object, path) {
|
|
39
40
|
var candidate = object[path];
|
|
40
41
|
try {
|
|
41
|
-
|
|
42
|
+
var result = executeExpression(candidate, {
|
|
42
43
|
iteration: linksIterations !== null && linksIterations !== void 0 ? linksIterations : iteration
|
|
43
|
-
})
|
|
44
|
+
});
|
|
45
|
+
return _objectSpread(_objectSpread({}, object), {}, _defineProperty({}, path, Array.isArray(result) ? (0, _array.firstValueItem)(result) : result));
|
|
44
46
|
} catch (e) {
|
|
45
47
|
return _objectSpread(_objectSpread({}, object), {}, _defineProperty({}, path, e instanceof Error ? e.toString() : e));
|
|
46
48
|
}
|
|
@@ -237,8 +237,7 @@ var LunaticVariable = /*#__PURE__*/function () {
|
|
|
237
237
|
key: "getValue",
|
|
238
238
|
value: function getValue(iteration) {
|
|
239
239
|
var _this$dictionary,
|
|
240
|
-
_this = this
|
|
241
|
-
_iteration;
|
|
240
|
+
_this = this;
|
|
242
241
|
// The variable is not calculated
|
|
243
242
|
if (!this.expression) {
|
|
244
243
|
return this.getSavedValue(iteration);
|
|
@@ -265,7 +264,7 @@ var LunaticVariable = /*#__PURE__*/function () {
|
|
|
265
264
|
if (Object.keys(bindings).length === 0) {
|
|
266
265
|
iteration = undefined;
|
|
267
266
|
}
|
|
268
|
-
if (!this.isOutdated(iteration)) {
|
|
267
|
+
if (this.shapeFrom && !this.isOutdated(iteration)) {
|
|
269
268
|
return this.getSavedValue(iteration);
|
|
270
269
|
}
|
|
271
270
|
if ((0, _env.isTestEnv)()) {
|
|
@@ -277,8 +276,7 @@ var LunaticVariable = /*#__PURE__*/function () {
|
|
|
277
276
|
} catch (e) {
|
|
278
277
|
throw new Error("Cannot interpret expression \"".concat(this.expression, "\" with bindings ").concat(JSON.stringify(bindings), ", error : ").concat(e.toString()));
|
|
279
278
|
}
|
|
280
|
-
this.
|
|
281
|
-
this.calculatedAt.set(undefined, performance.now());
|
|
279
|
+
this.updateTimestamps(iteration, 'calculatedAt');
|
|
282
280
|
return this.getSavedValue(iteration);
|
|
283
281
|
}
|
|
284
282
|
|
|
@@ -300,14 +298,27 @@ var LunaticVariable = /*#__PURE__*/function () {
|
|
|
300
298
|
this.value = [];
|
|
301
299
|
}
|
|
302
300
|
this.value = !Array.isArray(iteration) ? value : (0, _array.setAtIndex)(this.value, iteration, value);
|
|
303
|
-
|
|
304
|
-
this.updatedAt["delete"](iteration === null || iteration === void 0 ? void 0 : iteration.join('.'));
|
|
305
|
-
} else {
|
|
306
|
-
this.updatedAt.set(iteration === null || iteration === void 0 ? void 0 : iteration.join('.'), performance.now());
|
|
307
|
-
}
|
|
308
|
-
this.updatedAt.set(undefined, performance.now());
|
|
301
|
+
this.updateTimestamps(iteration, 'updatedAt');
|
|
309
302
|
return true;
|
|
310
303
|
}
|
|
304
|
+
}, {
|
|
305
|
+
key: "updateTimestamps",
|
|
306
|
+
value: function updateTimestamps(iteration, key) {
|
|
307
|
+
// Update parent iteration level timestamp
|
|
308
|
+
var _iterator2 = _createForOfIteratorHelper((0, _array.subArrays)(iteration)),
|
|
309
|
+
_step2;
|
|
310
|
+
try {
|
|
311
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
312
|
+
var subIteration = _step2.value;
|
|
313
|
+
this[key].set(subIteration.join('.'), performance.now());
|
|
314
|
+
}
|
|
315
|
+
} catch (err) {
|
|
316
|
+
_iterator2.e(err);
|
|
317
|
+
} finally {
|
|
318
|
+
_iterator2.f();
|
|
319
|
+
}
|
|
320
|
+
this[key].set(undefined, performance.now());
|
|
321
|
+
}
|
|
311
322
|
}, {
|
|
312
323
|
key: "setValueForArray",
|
|
313
324
|
value: function setValueForArray(value) {
|
|
@@ -334,20 +345,20 @@ var LunaticVariable = /*#__PURE__*/function () {
|
|
|
334
345
|
return this.value;
|
|
335
346
|
}
|
|
336
347
|
var current = this.value;
|
|
337
|
-
var
|
|
338
|
-
|
|
348
|
+
var _iterator3 = _createForOfIteratorHelper(iteration),
|
|
349
|
+
_step3;
|
|
339
350
|
try {
|
|
340
|
-
for (
|
|
341
|
-
var index =
|
|
351
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
352
|
+
var index = _step3.value;
|
|
342
353
|
if (!Array.isArray(current)) {
|
|
343
354
|
return current;
|
|
344
355
|
}
|
|
345
356
|
current = current[index];
|
|
346
357
|
}
|
|
347
358
|
} catch (err) {
|
|
348
|
-
|
|
359
|
+
_iterator3.e(err);
|
|
349
360
|
} finally {
|
|
350
|
-
|
|
361
|
+
_iterator3.f();
|
|
351
362
|
}
|
|
352
363
|
return current;
|
|
353
364
|
}
|
|
@@ -37,7 +37,8 @@ var _lunaticVariablesStore = require("./lunatic-variables-store");
|
|
|
37
37
|
variables.set('FIRSTNAME', 'John');
|
|
38
38
|
variables.set('LASTNAME', 'Doe');
|
|
39
39
|
variables.setCalculated('FULLNAME', 'FIRSTNAME || " " || LASTNAME', {
|
|
40
|
-
dependencies: ['FIRSTNAME', 'LASTNAME']
|
|
40
|
+
dependencies: ['FIRSTNAME', 'LASTNAME'],
|
|
41
|
+
shapeFrom: 'FIRSTNAME'
|
|
41
42
|
});
|
|
42
43
|
(0, _vitest.expect)(variables.get('FULLNAME')).toEqual('John Doe');
|
|
43
44
|
(0, _vitest.expect)(variables.interpretCount).toBe(1);
|
|
@@ -54,10 +55,12 @@ var _lunaticVariablesStore = require("./lunatic-variables-store");
|
|
|
54
55
|
variables.set('LASTNAME', 'Doe');
|
|
55
56
|
variables.set('AGE', '18');
|
|
56
57
|
variables.setCalculated('FULLNAME', 'FIRSTNAME || " " || LASTNAME', {
|
|
57
|
-
dependencies: ['FIRSTNAME', 'LASTNAME']
|
|
58
|
+
dependencies: ['FIRSTNAME', 'LASTNAME'],
|
|
59
|
+
shapeFrom: 'FIRSTNAME'
|
|
58
60
|
});
|
|
59
61
|
variables.setCalculated('LABEL', 'FULLNAME || " is " || AGE', {
|
|
60
|
-
dependencies: ['FULLNAME', 'AGE']
|
|
62
|
+
dependencies: ['FULLNAME', 'AGE'],
|
|
63
|
+
shapeFrom: 'FULLNAME'
|
|
61
64
|
});
|
|
62
65
|
(0, _vitest.expect)(variables.get('LABEL')).toEqual('John Doe is 18');
|
|
63
66
|
(0, _vitest.expect)(variables.interpretCount).toBe(2);
|
|
@@ -83,7 +86,7 @@ var _lunaticVariablesStore = require("./lunatic-variables-store");
|
|
|
83
86
|
variables.set('LASTNAME', 'Doe');
|
|
84
87
|
(0, _vitest.expect)(variables.run('FIRSTNAME || " " || LASTNAME')).toEqual('John Doe');
|
|
85
88
|
(0, _vitest.expect)(variables.run('FIRSTNAME || " " || LASTNAME')).toEqual('John Doe');
|
|
86
|
-
(0, _vitest.expect)(variables.interpretCount).toBe(
|
|
89
|
+
(0, _vitest.expect)(variables.interpretCount).toBe(2);
|
|
87
90
|
variables.set('FIRSTNAME', 'Jane');
|
|
88
91
|
(0, _vitest.expect)(variables.run('FIRSTNAME || " " || LASTNAME')).toEqual('Jane Doe');
|
|
89
92
|
});
|
|
@@ -220,7 +223,19 @@ var _lunaticVariablesStore = require("./lunatic-variables-store");
|
|
|
220
223
|
iteration: [1]
|
|
221
224
|
});
|
|
222
225
|
(0, _vitest.expect)(variables.run('"hello"')).toEqual('hello');
|
|
223
|
-
(0, _vitest.expect)(variables.interpretCount).toBe(
|
|
226
|
+
(0, _vitest.expect)(variables.interpretCount).toBe(3);
|
|
227
|
+
});
|
|
228
|
+
(0, _vitest.it)('should handle deep refresh', function () {
|
|
229
|
+
variables.set('LIENS', [['17', null], [null, '17']]);
|
|
230
|
+
variables.setCalculated('IS_12', 'if ("12" in LIENS) then 1 else 0', {
|
|
231
|
+
dependencies: ['LIENS'],
|
|
232
|
+
shapeFrom: 'LIENS'
|
|
233
|
+
});
|
|
234
|
+
(0, _vitest.expect)(variables.get('IS_12', [0])).toBe(0);
|
|
235
|
+
variables.set('LIENS', '12', {
|
|
236
|
+
iteration: [0, 0]
|
|
237
|
+
});
|
|
238
|
+
(0, _vitest.expect)(variables.get('IS_12', [0])).toBe(1);
|
|
224
239
|
});
|
|
225
240
|
});
|
|
226
241
|
(0, _vitest.describe)('resizing', function () {
|
package/lib/utils/array.js
CHANGED
|
@@ -3,9 +3,11 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.firstValueItem = firstValueItem;
|
|
6
7
|
exports.getAtIndex = getAtIndex;
|
|
7
8
|
exports.resizeArray = resizeArray;
|
|
8
9
|
exports.setAtIndex = setAtIndex;
|
|
10
|
+
exports.subArrays = subArrays;
|
|
9
11
|
exports.times = times;
|
|
10
12
|
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
|
|
11
13
|
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
@@ -81,4 +83,36 @@ function resizeArray(array, newLength, defaultValue) {
|
|
|
81
83
|
return new Array(newLength).fill(defaultValue !== null && defaultValue !== void 0 ? defaultValue : null).map(function (value, index) {
|
|
82
84
|
return index < array.length ? array[index] : value;
|
|
83
85
|
}, []);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Return the first non null/undefined value of an array
|
|
90
|
+
*/
|
|
91
|
+
function firstValueItem(items) {
|
|
92
|
+
if (!Array.isArray(items)) {
|
|
93
|
+
return items;
|
|
94
|
+
}
|
|
95
|
+
return items.find(function (v) {
|
|
96
|
+
return v !== undefined && v !== null;
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Return a list of partial array
|
|
102
|
+
*
|
|
103
|
+
* Example :
|
|
104
|
+
* - subArray([1, 2, 3]) // [[1], [1, 2], [1, 2, 3]]
|
|
105
|
+
*/
|
|
106
|
+
function subArrays(items) {
|
|
107
|
+
if (!Array.isArray(items)) {
|
|
108
|
+
return [];
|
|
109
|
+
}
|
|
110
|
+
if (items.length === 1) {
|
|
111
|
+
return [items];
|
|
112
|
+
}
|
|
113
|
+
var arrays = [];
|
|
114
|
+
for (var i = 1; i <= items.length; i++) {
|
|
115
|
+
arrays.push(items.slice(0, i));
|
|
116
|
+
}
|
|
117
|
+
return arrays;
|
|
84
118
|
}
|
package/lib/utils/array.spec.js
CHANGED
|
@@ -27,4 +27,9 @@ var _array = require("./array");
|
|
|
27
27
|
(0, _vitest.expect)((0, _array.setAtIndex)([null], [1, 2], 10)).toEqual([null, [null, null, 10]]);
|
|
28
28
|
});
|
|
29
29
|
});
|
|
30
|
+
(0, _vitest.it)('firstValueItem', function () {
|
|
31
|
+
(0, _vitest.expect)((0, _array.firstValueItem)([0, 1, 2])).toBe(0);
|
|
32
|
+
(0, _vitest.expect)((0, _array.firstValueItem)([null, 1, 2])).toBe(1);
|
|
33
|
+
(0, _vitest.expect)((0, _array.firstValueItem)([null, undefined, false])).toBe(false);
|
|
34
|
+
});
|
|
30
35
|
});
|
package/lib/utils/variables.js
CHANGED
|
@@ -8,29 +8,18 @@ exports.getInitialVariableValue = getInitialVariableValue;
|
|
|
8
8
|
* Extract the initial value from the source.json and data.json
|
|
9
9
|
*/
|
|
10
10
|
function getInitialVariableValue(variable) {
|
|
11
|
-
var _data$variable$variab;
|
|
11
|
+
var _data$variable$variab, _data$COLLECTED;
|
|
12
12
|
var data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
13
13
|
switch (variable.variableType) {
|
|
14
14
|
case 'EXTERNAL':
|
|
15
15
|
case 'CALCULATED':
|
|
16
16
|
return (_data$variable$variab = data[variable.variableType]) === null || _data$variable$variab === void 0 ? void 0 : _data$variable$variab[variable.name];
|
|
17
17
|
case 'COLLECTED':
|
|
18
|
-
var
|
|
19
|
-
var fromData;
|
|
20
|
-
if (collectedData && variable.name in collectedData) {
|
|
21
|
-
var _collectedData$variab = collectedData[variable.name],
|
|
22
|
-
COLLECTED = _collectedData$variab.COLLECTED,
|
|
23
|
-
FORCED = _collectedData$variab.FORCED;
|
|
24
|
-
fromData = COLLECTED !== null && COLLECTED !== void 0 ? COLLECTED : FORCED;
|
|
25
|
-
}
|
|
18
|
+
var fromData = (_data$COLLECTED = data.COLLECTED) === null || _data$COLLECTED === void 0 || (_data$COLLECTED = _data$COLLECTED[variable.name]) === null || _data$COLLECTED === void 0 ? void 0 : _data$COLLECTED.COLLECTED;
|
|
26
19
|
if ('values' in variable && variable.values) {
|
|
27
|
-
|
|
28
|
-
var _variable$values = variable.values,
|
|
29
|
-
_COLLECTED = _variable$values.COLLECTED,
|
|
30
|
-
_FORCED = _variable$values.FORCED;
|
|
31
|
-
return (_ref = (_fromData = fromData) !== null && _fromData !== void 0 ? _fromData : _FORCED) !== null && _ref !== void 0 ? _ref : _COLLECTED;
|
|
20
|
+
return fromData !== null && fromData !== void 0 ? fromData : variable.values.COLLECTED;
|
|
32
21
|
}
|
|
33
|
-
return
|
|
22
|
+
return fromData;
|
|
34
23
|
default:
|
|
35
24
|
return null;
|
|
36
25
|
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _vitest = require("vitest");
|
|
4
|
+
var _variables = require("./variables");
|
|
5
|
+
var data = {
|
|
6
|
+
EXTERNAL: {
|
|
7
|
+
ADRESSE: 'mon adresse'
|
|
8
|
+
},
|
|
9
|
+
CALCULATED: {
|
|
10
|
+
PRENOMSB: ['Paul', 'Pierre']
|
|
11
|
+
},
|
|
12
|
+
COLLECTED: {
|
|
13
|
+
NB_HAB: {
|
|
14
|
+
COLLECTED: 2
|
|
15
|
+
},
|
|
16
|
+
PRENOMS: {
|
|
17
|
+
COLLECTED: ['Paul', 'Pierre'],
|
|
18
|
+
EDITED: [],
|
|
19
|
+
INPUTED: [],
|
|
20
|
+
FORCED: [],
|
|
21
|
+
PREVIOUS: []
|
|
22
|
+
},
|
|
23
|
+
AGE: {}
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
var externalVariable = {
|
|
27
|
+
variableType: 'EXTERNAL',
|
|
28
|
+
name: 'ADRESSE'
|
|
29
|
+
};
|
|
30
|
+
var calculatedVariable = {
|
|
31
|
+
variableType: 'CALCULATED',
|
|
32
|
+
bindingDependencies: ['PRENOMS'],
|
|
33
|
+
expression: {
|
|
34
|
+
type: 'VTL',
|
|
35
|
+
value: 'PRENOMS'
|
|
36
|
+
},
|
|
37
|
+
name: 'PRENOMSB',
|
|
38
|
+
shapeFrom: 'PRENOMS'
|
|
39
|
+
};
|
|
40
|
+
var simpleCollectedVariable = {
|
|
41
|
+
variableType: 'COLLECTED',
|
|
42
|
+
name: 'NB_HAB'
|
|
43
|
+
};
|
|
44
|
+
var loopCollectedVariable = {
|
|
45
|
+
variableType: 'COLLECTED',
|
|
46
|
+
values: {
|
|
47
|
+
COLLECTED: []
|
|
48
|
+
},
|
|
49
|
+
name: 'PRENOMS'
|
|
50
|
+
};
|
|
51
|
+
var emptyCollectedVariable = {
|
|
52
|
+
variableType: 'COLLECTED',
|
|
53
|
+
name: 'AGE'
|
|
54
|
+
};
|
|
55
|
+
(0, _vitest.describe)('getInitialVariableValue', function () {
|
|
56
|
+
(0, _vitest.it)('should return external value', function () {
|
|
57
|
+
(0, _vitest.expect)((0, _variables.getInitialVariableValue)(externalVariable, data)).toEqual('mon adresse');
|
|
58
|
+
});
|
|
59
|
+
(0, _vitest.it)('should return calculated value', function () {
|
|
60
|
+
(0, _vitest.expect)((0, _variables.getInitialVariableValue)(calculatedVariable, data)).toEqual(['Paul', 'Pierre']);
|
|
61
|
+
});
|
|
62
|
+
(0, _vitest.it)('should return collected value out of a loop', function () {
|
|
63
|
+
(0, _vitest.expect)((0, _variables.getInitialVariableValue)(simpleCollectedVariable, data)).toEqual(2);
|
|
64
|
+
});
|
|
65
|
+
(0, _vitest.it)('should return array of collected values in a loop', function () {
|
|
66
|
+
(0, _vitest.expect)((0, _variables.getInitialVariableValue)(loopCollectedVariable, data)).toEqual(['Paul', 'Pierre']);
|
|
67
|
+
});
|
|
68
|
+
(0, _vitest.it)('should return undefined value out of a loop', function () {
|
|
69
|
+
(0, _vitest.expect)((0, _variables.getInitialVariableValue)(emptyCollectedVariable, data)).toEqual(undefined);
|
|
70
|
+
});
|
|
71
|
+
(0, _vitest.it)('should set empty undefined if no data', function () {
|
|
72
|
+
(0, _vitest.expect)((0, _variables.getInitialVariableValue)(simpleCollectedVariable)).toEqual(undefined);
|
|
73
|
+
});
|
|
74
|
+
});
|