Skip to content

Commit

Permalink
fix: duration and suggester components in resizing (#1159)
Browse files Browse the repository at this point in the history
  • Loading branch information
nsenave authored Nov 18, 2024
1 parent f226a9e commit 03d0828
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
15 changes: 10 additions & 5 deletions eno-core/src/main/java/fr/insee/eno/core/utils/LunaticUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,13 @@ public static List<String> getCollectedVariablesInLoop(Loop loop) {
List<String> result = new ArrayList<>();
loop.getComponents().forEach(component -> {
switch (component.getComponentType()) {
case CHECKBOX_BOOLEAN, INPUT_NUMBER, INPUT, TEXTAREA, DATEPICKER, RADIO, CHECKBOX_ONE, DROPDOWN,
CHECKBOX_GROUP, TABLE ->
case CHECKBOX_BOOLEAN, INPUT_NUMBER, INPUT, TEXTAREA, SUGGESTER, DATEPICKER, DURATION, RADIO,
CHECKBOX_ONE, DROPDOWN, CHECKBOX_GROUP, TABLE ->
result.addAll(getDirectResponseNames(component));
case QUESTIONNAIRE, SEQUENCE, SUBSEQUENCE, TEXT, ACCORDION ->
doNothing();
case QUESTION ->
throw new IllegalStateException("This method does not support the question component.");
case ROSTER_FOR_LOOP ->
throw new LunaticLoopException(String.format(
"Dynamic tables are forbidden in loops: loop '%s' contains a dynamic table.",
Expand All @@ -132,14 +136,15 @@ public static List<String> getCollectedVariablesInLoop(Loop loop) {
throw new LunaticLoopException(String.format(
"Pairwise components are forbidden in loops: loop '%s' contains a pairwise component.",
loop.getId()));
default ->
log.debug("(Variables in Lunatic loop) Component of type {} has no response.",
component.getComponentType());
}
});
return result;
}

private static void doNothing() {
/* No-op method */
}

/**
* Return the response name of the component that belong to the given pairwise links. This method checks if
* the inner component is valid.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ void simpleResponseComponents_resizedVariables() {
input.setResponse(new ResponseType());
input.getResponse().setName("INPUT_VAR");
lunaticLoop.getComponents().add(input);
Suggester suggester = new Suggester(); // The suggester component type is set by the constructor
suggester.setResponse(new ResponseType());
suggester.getResponse().setName("SUGGESTER_VAR");
lunaticLoop.getComponents().add(suggester);
Textarea textarea = new Textarea();
textarea.setComponentType(ComponentTypeEnum.TEXTAREA);
textarea.setResponse(new ResponseType());
Expand All @@ -136,6 +140,11 @@ void simpleResponseComponents_resizedVariables() {
datepicker.setResponse(new ResponseType());
datepicker.getResponse().setName("DATE_VAR");
lunaticLoop.getComponents().add(datepicker);
Duration duration = new Duration();
duration.setComponentType(ComponentTypeEnum.DURATION);
duration.setResponse(new ResponseType());
duration.getResponse().setName("DURATION_VAR");
lunaticLoop.getComponents().add(duration);
Dropdown dropdown = new Dropdown();
dropdown.setComponentType(ComponentTypeEnum.DROPDOWN);
dropdown.setResponse(new ResponseType());
Expand All @@ -160,8 +169,8 @@ void simpleResponseComponents_resizedVariables() {
// Then
assertThat(lunaticResizing.getResizingEntry("LOOP_SIZE_VAR").getVariables())
.containsExactlyInAnyOrderElementsOf(Set.of(
"BOOLEAN_VAR", "INPUT_VAR", "TEXT_VAR", "NUMBER_VAR", "DATE_VAR",
"DROPDOWN_VAR", "RADIO_VAR", "CHECKBOX_VAR"));
"BOOLEAN_VAR", "INPUT_VAR", "SUGGESTER_VAR", "TEXT_VAR", "NUMBER_VAR",
"DATE_VAR", "DURATION_VAR", "DROPDOWN_VAR", "RADIO_VAR", "CHECKBOX_VAR"));
}

@Test
Expand Down

0 comments on commit 03d0828

Please sign in to comment.