@inseefr/lunatic 3.4.17 → 3.4.19
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/components/Input/Input.js +6 -3
- package/components/Input/Input.js.map +1 -1
- package/components/Input/Input.spec.js +13 -0
- package/components/Input/Input.spec.js.map +1 -1
- package/components/Textarea/Textarea.js +4 -1
- package/components/Textarea/Textarea.js.map +1 -1
- package/components/Textarea/Textarea.spec.js +13 -0
- package/components/Textarea/Textarea.spec.js.map +1 -1
- package/components/shared/CharactersCount/CharactersCount.d.ts +7 -0
- package/components/shared/CharactersCount/CharactersCount.js +20 -0
- package/components/shared/CharactersCount/CharactersCount.js.map +1 -0
- package/components/shared/CharactersCount/CharactersCount.spec.d.ts +1 -0
- package/components/shared/CharactersCount/CharactersCount.spec.js +28 -0
- package/components/shared/CharactersCount/CharactersCount.spec.js.map +1 -0
- package/components/shared/utils/getCharactersCountId.d.ts +4 -0
- package/components/shared/utils/getCharactersCountId.js +10 -0
- package/components/shared/utils/getCharactersCountId.js.map +1 -0
- package/esm/components/Input/Input.js +6 -3
- package/esm/components/Input/Input.js.map +1 -1
- package/esm/components/Input/Input.spec.js +13 -0
- package/esm/components/Input/Input.spec.js.map +1 -1
- package/esm/components/Textarea/Textarea.js +4 -1
- package/esm/components/Textarea/Textarea.js.map +1 -1
- package/esm/components/Textarea/Textarea.spec.js +13 -0
- package/esm/components/Textarea/Textarea.spec.js.map +1 -1
- package/esm/components/shared/CharactersCount/CharactersCount.d.ts +7 -0
- package/esm/components/shared/CharactersCount/CharactersCount.js +15 -0
- package/esm/components/shared/CharactersCount/CharactersCount.js.map +1 -0
- package/esm/components/shared/CharactersCount/CharactersCount.spec.d.ts +1 -0
- package/esm/components/shared/CharactersCount/CharactersCount.spec.js +26 -0
- package/esm/components/shared/CharactersCount/CharactersCount.spec.js.map +1 -0
- package/esm/components/shared/utils/getCharactersCountId.d.ts +4 -0
- package/esm/components/shared/utils/getCharactersCountId.js +7 -0
- package/esm/components/shared/utils/getCharactersCountId.js.map +1 -0
- package/esm/main.css +10 -0
- package/esm/main.css.map +1 -1
- package/esm/use-lunatic/hooks/use-page-has-response.js +1 -1
- package/esm/use-lunatic/hooks/use-page-has-response.js.map +1 -1
- package/esm/use-lunatic/props/propValue.js +15 -4
- package/esm/use-lunatic/props/propValue.js.map +1 -1
- package/esm/use-lunatic/props/propValue.spec.js +49 -2
- package/esm/use-lunatic/props/propValue.spec.js.map +1 -1
- package/main.css +10 -0
- package/main.css.map +1 -1
- package/package.json +23 -1
- package/src/components/Input/Input.spec.tsx +19 -0
- package/src/components/Input/Input.tsx +26 -18
- package/src/components/Input/__snapshots__/Input.spec.tsx.snap +27 -19
- package/src/components/RosterForLoop/__snapshots__/RosterForLoop.spec.tsx.snap +42 -20
- package/src/components/Textarea/Textarea.spec.tsx +18 -0
- package/src/components/Textarea/Textarea.tsx +21 -13
- package/src/components/Textarea/__snapshots__/Textarea.spec.tsx.snap +21 -11
- package/src/components/shared/CharactersCount/CharactersCount.spec.tsx +31 -0
- package/src/components/shared/CharactersCount/CharactersCount.tsx +27 -0
- package/src/components/shared/utils/getCharactersCountId.test.ts +14 -0
- package/src/components/shared/utils/getCharactersCountId.ts +6 -0
- package/src/css/components/Input.scss +10 -0
- package/src/use-lunatic/hooks/use-page-has-response.test.ts +42 -0
- package/src/use-lunatic/hooks/use-page-has-response.ts +1 -1
- package/src/use-lunatic/props/propValue.spec.ts +53 -2
- package/src/use-lunatic/props/propValue.ts +21 -6
- package/tsconfig.build.tsbuildinfo +1 -1
- package/use-lunatic/hooks/use-page-has-response.js +1 -1
- package/use-lunatic/hooks/use-page-has-response.js.map +1 -1
- package/use-lunatic/props/propValue.js +15 -4
- package/use-lunatic/props/propValue.js.map +1 -1
- package/use-lunatic/props/propValue.spec.js +49 -2
- package/use-lunatic/props/propValue.spec.js.map +1 -1
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { getCharactersCountId } from './getCharactersCountId';
|
|
3
|
+
|
|
4
|
+
describe('getCharacterCountId', () => {
|
|
5
|
+
it('should return the correct ID when maxLength is provided', () => {
|
|
6
|
+
expect(getCharactersCountId('test-id', 100)).toBe(
|
|
7
|
+
'characters-count-test-id'
|
|
8
|
+
);
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it('should return undefined when maxLength is not provided', () => {
|
|
12
|
+
expect(getCharactersCountId('test-id')).toBeUndefined();
|
|
13
|
+
});
|
|
14
|
+
});
|
|
@@ -156,3 +156,45 @@ describe('usePageHasResponse', () => {
|
|
|
156
156
|
expect(result.current()).toBeTruthy();
|
|
157
157
|
});
|
|
158
158
|
});
|
|
159
|
+
|
|
160
|
+
it('should be true for a loop component with values', () => {
|
|
161
|
+
const mockExecuteExpression = vi.fn();
|
|
162
|
+
mockExecuteExpression.mockReturnValueOnce('my value');
|
|
163
|
+
|
|
164
|
+
const values = {
|
|
165
|
+
VOTREPRENO: ['Alice', 'Bob', 'Charlie'],
|
|
166
|
+
VOTREAGE: [22, 30, 40],
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
const components = [
|
|
170
|
+
{
|
|
171
|
+
...defaultComponentValues,
|
|
172
|
+
componentType: 'Loop',
|
|
173
|
+
components: [
|
|
174
|
+
{
|
|
175
|
+
...defaultComponentValues,
|
|
176
|
+
componentType: 'Question',
|
|
177
|
+
components: [
|
|
178
|
+
{
|
|
179
|
+
...defaultComponentValues,
|
|
180
|
+
componentType: 'Input',
|
|
181
|
+
response: { name: 'VOTREPRENO' },
|
|
182
|
+
},
|
|
183
|
+
{
|
|
184
|
+
...defaultComponentValues,
|
|
185
|
+
componentType: 'InputNumber',
|
|
186
|
+
response: { name: 'VOTREAGE' },
|
|
187
|
+
},
|
|
188
|
+
],
|
|
189
|
+
},
|
|
190
|
+
],
|
|
191
|
+
value: values,
|
|
192
|
+
},
|
|
193
|
+
] as any as LunaticComponentProps[];
|
|
194
|
+
|
|
195
|
+
const { result } = renderHook(() =>
|
|
196
|
+
usePageHasResponse(components, mockExecuteExpression)
|
|
197
|
+
);
|
|
198
|
+
|
|
199
|
+
expect(result.current()).toBeTruthy();
|
|
200
|
+
});
|
|
@@ -60,7 +60,7 @@ function hasOneResponse(
|
|
|
60
60
|
return !isSubComponentsEmpty(childrenComponent, executeExpression);
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
// We found a value in one of the root component
|
|
63
|
+
// We found a value in one of the root component. Used for Loop
|
|
64
64
|
if ('value' in component && !isEmpty(component.value)) {
|
|
65
65
|
return true;
|
|
66
66
|
}
|
|
@@ -25,7 +25,7 @@ describe('fillComponentValue', () => {
|
|
|
25
25
|
);
|
|
26
26
|
};
|
|
27
27
|
|
|
28
|
-
describe('response', () => {
|
|
28
|
+
describe('single response', () => {
|
|
29
29
|
const component = {
|
|
30
30
|
response: { name: 'PRENOM' },
|
|
31
31
|
} as LunaticComponentDefinition<'Input'>;
|
|
@@ -44,7 +44,7 @@ describe('fillComponentValue', () => {
|
|
|
44
44
|
);
|
|
45
45
|
});
|
|
46
46
|
});
|
|
47
|
-
describe('responses', () => {
|
|
47
|
+
describe('multiple responses', () => {
|
|
48
48
|
const component = {
|
|
49
49
|
responses: times(3, (k) => ({
|
|
50
50
|
response: { name: `NAME${k}` },
|
|
@@ -64,4 +64,55 @@ describe('fillComponentValue', () => {
|
|
|
64
64
|
});
|
|
65
65
|
});
|
|
66
66
|
});
|
|
67
|
+
|
|
68
|
+
describe('Loop component with nested components', () => {
|
|
69
|
+
const loopComponent = {
|
|
70
|
+
id: 'm7j9kwro',
|
|
71
|
+
componentType: 'Loop',
|
|
72
|
+
components: [
|
|
73
|
+
{
|
|
74
|
+
id: 'm7j9iem8',
|
|
75
|
+
componentType: 'Sequence',
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
id: 'question-m7j9q1ep',
|
|
79
|
+
componentType: 'Question',
|
|
80
|
+
components: [
|
|
81
|
+
{
|
|
82
|
+
id: 'm7j9q1ep',
|
|
83
|
+
componentType: 'Input',
|
|
84
|
+
response: { name: 'VOTREPRENO' },
|
|
85
|
+
},
|
|
86
|
+
],
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
id: 'question-m7jb81xh',
|
|
90
|
+
componentType: 'Question',
|
|
91
|
+
components: [
|
|
92
|
+
{
|
|
93
|
+
id: 'm7jb81xh',
|
|
94
|
+
componentType: 'InputNumber',
|
|
95
|
+
response: { name: 'VOTREAGE' },
|
|
96
|
+
},
|
|
97
|
+
],
|
|
98
|
+
},
|
|
99
|
+
],
|
|
100
|
+
} as LunaticComponentDefinition;
|
|
101
|
+
|
|
102
|
+
it('should correctly extract values from nested responses as arrays', () => {
|
|
103
|
+
const values = {
|
|
104
|
+
VOTREPRENO: ['Alice', 'Bob', 'Charlie'],
|
|
105
|
+
VOTREAGE: [22, 30, 40],
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
expectFilledComponent(loopComponent, values).toEqual(values);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it('should return null for missing responses', () => {
|
|
112
|
+
expectFilledComponent(loopComponent).toEqual({
|
|
113
|
+
VOTREPRENO: null,
|
|
114
|
+
VOTREAGE: null,
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
});
|
|
67
118
|
});
|
|
@@ -29,12 +29,27 @@ export function getValueProp(
|
|
|
29
29
|
}
|
|
30
30
|
// For loop, value will be a map of child component values
|
|
31
31
|
if ('components' in component) {
|
|
32
|
-
return
|
|
33
|
-
component.components
|
|
34
|
-
.map((c) => ('response' in c ? c.response.name : null))
|
|
35
|
-
.filter((name) => name !== null)
|
|
36
|
-
.map((name) => [name, args.variables.get(name!)])
|
|
37
|
-
);
|
|
32
|
+
return getChildResponseValues(component.components, args.variables);
|
|
38
33
|
}
|
|
39
34
|
return null;
|
|
40
35
|
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Get the values of every child components recursively.
|
|
39
|
+
*/
|
|
40
|
+
function getChildResponseValues(
|
|
41
|
+
components: LunaticComponentDefinition[],
|
|
42
|
+
variables: LunaticVariablesStore
|
|
43
|
+
): Record<string, unknown> {
|
|
44
|
+
return Object.fromEntries(
|
|
45
|
+
components.flatMap((c) => {
|
|
46
|
+
if ('response' in c) {
|
|
47
|
+
return [[c.response.name, variables.get(c.response.name)]];
|
|
48
|
+
}
|
|
49
|
+
if ('components' in c) {
|
|
50
|
+
return Object.entries(getChildResponseValues(c.components, variables));
|
|
51
|
+
}
|
|
52
|
+
return [];
|
|
53
|
+
})
|
|
54
|
+
);
|
|
55
|
+
}
|