-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: lunatic navigation in loops (#796)
- fix: insert subsequence components in loops - refactor: LunaticPaginationMode in LunaticParameters class - test: add unit and functional tests on the Lunatic pagination feature - docs: comment about max page for non paginated loops - style: fix typos here and there
- Loading branch information
Showing
20 changed files
with
362,669 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
...ee/eno/core/processing/out/steps/lunatic/pagination/LunaticPaginationFunctionalTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package fr.insee.eno.core.processing.out.steps.lunatic.pagination; | ||
|
||
import fr.insee.eno.core.DDIToEno; | ||
import fr.insee.eno.core.exceptions.business.DDIParsingException; | ||
import fr.insee.eno.core.mappers.LunaticMapper; | ||
import fr.insee.eno.core.model.EnoQuestionnaire; | ||
import fr.insee.eno.core.parameter.EnoParameters; | ||
import fr.insee.eno.core.parameter.Format; | ||
import fr.insee.eno.core.processing.out.steps.lunatic.LunaticAddHierarchy; | ||
import fr.insee.eno.core.processing.out.steps.lunatic.LunaticLoopResolution; | ||
import fr.insee.eno.core.processing.out.steps.lunatic.LunaticSortComponents; | ||
import fr.insee.eno.core.processing.out.steps.lunatic.table.LunaticTableProcessing; | ||
import fr.insee.lunatic.model.flat.ComponentTypeEnum; | ||
import fr.insee.lunatic.model.flat.Loop; | ||
import fr.insee.lunatic.model.flat.Questionnaire; | ||
import fr.insee.lunatic.model.flat.Subsequence; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
class LunaticPaginationFunctionalTests { | ||
|
||
private Questionnaire mapDDIAndApplyPagination(String id) throws DDIParsingException { | ||
// Given | ||
EnoParameters enoParameters = EnoParameters.of(EnoParameters.Context.HOUSEHOLD, EnoParameters.ModeParameter.CAWI, Format.LUNATIC); | ||
EnoQuestionnaire enoQuestionnaire = DDIToEno.transform( | ||
LunaticPaginationFunctionalTests.class.getClassLoader().getResourceAsStream( | ||
"functional/ddi/pagination/ddi-"+id+".xml"), | ||
enoParameters); | ||
Questionnaire lunaticQuestionnaire = new Questionnaire(); | ||
LunaticMapper lunaticMapper = new LunaticMapper(); | ||
lunaticMapper.mapEnoObject(enoQuestionnaire, lunaticQuestionnaire); | ||
new LunaticSortComponents(enoQuestionnaire).apply(lunaticQuestionnaire); | ||
new LunaticLoopResolution(enoQuestionnaire).apply(lunaticQuestionnaire); | ||
new LunaticTableProcessing(enoQuestionnaire).apply(lunaticQuestionnaire); | ||
new LunaticAddHierarchy().apply(lunaticQuestionnaire); | ||
|
||
// When | ||
new LunaticAddPageNumbers(enoParameters.getLunaticParameters().getLunaticPaginationMode()) | ||
.apply(lunaticQuestionnaire); | ||
|
||
return lunaticQuestionnaire; | ||
} | ||
|
||
@Test | ||
void functionalTest1() throws DDIParsingException { | ||
Questionnaire lunaticQuestionnaire = mapDDIAndApplyPagination("llxh9g6g"); | ||
|
||
// Then | ||
assertNotNull(lunaticQuestionnaire.getMaxPage()); | ||
// ... | ||
} | ||
|
||
@Test | ||
void functionalTest2() throws DDIParsingException { | ||
Questionnaire lunaticQuestionnaire = mapDDIAndApplyPagination("lnycjn6n"); | ||
|
||
// Then | ||
assertEquals("3", lunaticQuestionnaire.getMaxPage()); | ||
|
||
// | ||
assertEquals(ComponentTypeEnum.LOOP, lunaticQuestionnaire.getComponents().get(0).getComponentType()); | ||
Loop loop1 = (Loop) lunaticQuestionnaire.getComponents().get(0); | ||
assertEquals("1", loop1.getPage()); | ||
assertNull(loop1.getMaxPage()); | ||
assertEquals(2, loop1.getComponents().size()); | ||
loop1.getComponents().forEach(component -> | ||
assertEquals("1", component.getPage())); | ||
|
||
// | ||
assertEquals(ComponentTypeEnum.LOOP, lunaticQuestionnaire.getComponents().get(1).getComponentType()); | ||
Loop loop2 = (Loop) lunaticQuestionnaire.getComponents().get(1); | ||
assertEquals("2", loop2.getPage()); | ||
assertEquals("492", loop2.getMaxPage()); | ||
assertEquals("2.1", loop2.getComponents().get(0).getPage()); | ||
assertEquals("2.2", loop2.getComponents().get(1).getPage()); | ||
assertEquals("2.3", loop2.getComponents().get(2).getPage()); | ||
// ... | ||
assertEquals("2.7", loop2.getComponents().get(6).getPage()); | ||
assertEquals(ComponentTypeEnum.SUBSEQUENCE, loop2.getComponents().get(7).getComponentType()); | ||
assertEquals("2.8", loop2.getComponents().get(7).getPage()); | ||
assertEquals("2.8", ((Subsequence) loop2.getComponents().get(7)).getGoToPage()); | ||
assertEquals("2.9", loop2.getComponents().get(8).getPage()); | ||
// ... | ||
|
||
// | ||
assertEquals(ComponentTypeEnum.SEQUENCE, lunaticQuestionnaire.getComponents().get(2).getComponentType()); | ||
assertEquals("3", lunaticQuestionnaire.getComponents().get(2).getPage()); | ||
} | ||
|
||
} |
146 changes: 146 additions & 0 deletions
146
...java/fr/insee/eno/core/processing/out/steps/lunatic/pagination/LunaticPaginationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
package fr.insee.eno.core.processing.out.steps.lunatic.pagination; | ||
|
||
import fr.insee.eno.core.parameter.LunaticParameters; | ||
import fr.insee.lunatic.model.flat.*; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Nested; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
/** | ||
* Other tests on the Lunatic pagination. | ||
*/ | ||
class LunaticPaginationTest { | ||
|
||
@Nested | ||
class LoopOnSequence { | ||
|
||
private Questionnaire questionnaire; | ||
|
||
@BeforeEach | ||
void createLoopWithSequence() { | ||
questionnaire = new Questionnaire(); | ||
Sequence sequence = new Sequence(); | ||
sequence.setComponentType(ComponentTypeEnum.SEQUENCE); | ||
Input input1 = new Input(); | ||
input1.setComponentType(ComponentTypeEnum.INPUT); | ||
Input input2 = new Input(); | ||
input2.setComponentType(ComponentTypeEnum.INPUT); | ||
Loop loop = new Loop(); | ||
loop.setComponentType(ComponentTypeEnum.LOOP); | ||
loop.setLines(new LinesLoop()); | ||
loop.getComponents().add(sequence); | ||
loop.getComponents().add(input1); | ||
loop.getComponents().add(input2); | ||
questionnaire.getComponents().add(loop); | ||
} | ||
|
||
@Test | ||
void questionMode() { | ||
// | ||
new LunaticAddPageNumbers(LunaticParameters.LunaticPaginationMode.QUESTION).apply(questionnaire); | ||
// | ||
assertEquals("question", questionnaire.getPagination()); | ||
assertEquals("1", questionnaire.getMaxPage()); | ||
Loop loop = (Loop) questionnaire.getComponents().get(0); | ||
assertFalse(loop.getPaginatedLoop()); | ||
// Non paginated loops don't have a "max page" property | ||
assertNull(loop.getMaxPage()); | ||
// Non paginated loops don't use "dotted" numbering | ||
loop.getComponents().forEach(loopComponent -> | ||
assertEquals("1", loopComponent.getPage())); | ||
} | ||
|
||
@Test | ||
void sequenceMode() { | ||
// | ||
new LunaticAddPageNumbers(LunaticParameters.LunaticPaginationMode.SEQUENCE).apply(questionnaire); | ||
// | ||
assertEquals("sequence", questionnaire.getPagination()); | ||
assertEquals("1", questionnaire.getMaxPage()); | ||
Loop loop = (Loop) questionnaire.getComponents().get(0); | ||
assertTrue(loop.getPaginatedLoop()); | ||
// Paginated loops have a "max page" | ||
assertEquals("1", loop.getMaxPage()); | ||
// Sequence mode: each component of the sequence is on the same page | ||
loop.getComponents().forEach(loopComponent -> | ||
assertEquals("1.1", loopComponent.getPage())); | ||
} | ||
} | ||
|
||
@Nested | ||
class LoopOnTwoSequences { | ||
|
||
private Questionnaire questionnaire; | ||
|
||
@BeforeEach | ||
void createLoopWithTwoSequences() { | ||
questionnaire = new Questionnaire(); | ||
Sequence sequence1 = new Sequence(); | ||
sequence1.setComponentType(ComponentTypeEnum.SEQUENCE); | ||
Input input1 = new Input(); | ||
input1.setComponentType(ComponentTypeEnum.INPUT); | ||
Sequence sequence2 = new Sequence(); | ||
sequence2.setComponentType(ComponentTypeEnum.SEQUENCE); | ||
Input input2 = new Input(); | ||
input2.setComponentType(ComponentTypeEnum.INPUT); | ||
Loop loop = new Loop(); | ||
loop.setComponentType(ComponentTypeEnum.LOOP); | ||
loop.setLines(new LinesLoop()); | ||
loop.getComponents().add(sequence1); | ||
loop.getComponents().add(input1); | ||
loop.getComponents().add(sequence2); | ||
loop.getComponents().add(input2); | ||
questionnaire.getComponents().add(loop); | ||
} | ||
|
||
@Test | ||
void questionMode() { | ||
// | ||
new LunaticAddPageNumbers(LunaticParameters.LunaticPaginationMode.QUESTION).apply(questionnaire); | ||
// | ||
assertEquals("question", questionnaire.getPagination()); | ||
assertEquals("1", questionnaire.getMaxPage()); | ||
Loop loop = (Loop) questionnaire.getComponents().get(0); | ||
assertFalse(loop.getPaginatedLoop()); | ||
// Non paginated loops don't have a "max page" property | ||
assertNull(loop.getMaxPage()); | ||
// Non paginated loops don't use "dotted" numbering | ||
loop.getComponents().forEach(loopComponent -> | ||
assertEquals("1", loopComponent.getPage())); | ||
} | ||
|
||
@Test | ||
void sequenceMode() { | ||
// | ||
new LunaticAddPageNumbers(LunaticParameters.LunaticPaginationMode.SEQUENCE).apply(questionnaire); | ||
// | ||
assertEquals("sequence", questionnaire.getPagination()); | ||
assertEquals("1", questionnaire.getMaxPage()); | ||
Loop loop = (Loop) questionnaire.getComponents().get(0); | ||
assertTrue(loop.getPaginatedLoop()); | ||
// Paginated loops have a "max page" | ||
assertEquals("2", loop.getMaxPage()); | ||
// Sequence mode: each component of the sequence is on the same page | ||
assertEquals("1.1", loop.getComponents().get(0).getPage()); | ||
assertEquals("1.1", loop.getComponents().get(1).getPage()); | ||
assertEquals("1.2", loop.getComponents().get(2).getPage()); | ||
assertEquals("1.2", loop.getComponents().get(3).getPage()); | ||
} | ||
} | ||
|
||
@Nested | ||
class LoopOnSubsequence { | ||
private Questionnaire questionnaire; | ||
@BeforeEach | ||
void createLoopWithSubsequence() { | ||
questionnaire = new Questionnaire(); | ||
} | ||
@Test | ||
void questionMode() { | ||
assertNotNull(questionnaire); | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.