Skip to content

Commit

Permalink
Realized we had no basic form tests that itemsets aren't broken
Browse files Browse the repository at this point in the history
  • Loading branch information
ctsims committed Jul 17, 2017
1 parent 2996dfb commit eb7afb0
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/test/java/org/javarosa/core/model/test/FormDefTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -614,4 +614,31 @@ public boolean rawArgs() {
fec.answerQuestion(new SelectOneData(new Selection("yes")));
} while (fec.stepToNextEvent() != FormEntryController.EVENT_END_OF_FORM);
}

@Test
public void testItemsetPopulationAndFilter() {
FormParseInit fpi = new FormParseInit("/xform_tests/itemset_population_test.xhtml");

FormEntryController fec = fpi.getFormEntryController();

do {
QuestionDef q = fpi.getCurrentQuestion();
if (q == null) {
continue;
}
TreeReference currentRef = fec.getModel().getFormIndex().getReference();
if(currentRef == null) { continue; }

if(currentRef.genericize().toString().equals("/data/filter")) {
fec.answerQuestion(new SelectOneData(new Selection("a")));
}

if(currentRef.genericize().toString().equals("/data/question")) {
assertEquals("Itemset Filter returned the wrong size",
fec.getModel().getQuestionPrompt().getSelectChoices().size(),
3);
}

} while (fec.stepToNextEvent() != FormEntryController.EVENT_END_OF_FORM);
}
}
65 changes: 65 additions & 0 deletions src/test/resources/xform_tests/itemset_population_test.xhtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<h:html xmlns:h="http://www.w3.org/1999/xhtml"
xmlns="http://www.w3.org/2002/xforms"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:jr="http://openrosa.org/javarosa"
>
<h:head>
<h:title>Itemset Test</h:title>
<model>
<instance>
<data
xmlns="http://openrosa.org/formdesigner/itemset-test"
uiVersion="1" version="1" name="Itemset Test">
<filter/>
<question/>
</data>
</instance>

<instance id="itemset_data">
<item_list>
<i filter="a">
<label>1A</label>
<value>1_a</value>
</i>
<i filter="a">
<label>2A</label>
<value>2_a</value>
</i>
<i filter="a">
<label>3A</label>
<value>3_a</value>
</i>

<i filter="b">
<label>1B</label>
<value>1_b</value>
</i>
<i filter="b">
<label>2B</label>
<value>2_b</value>
</i>
</item_list>
</instance>
</model>
</h:head>
<h:body>
<select1 ref="/data/filter">
<label>Filter</label>
<item>
<label>A</label>
<value>a</value>
</item>
<item>
<label>B</label>
<value>b</value>
</item>
</select1>
<select1 ref="/data/question">
<label>Filter</label>
<itemset nodeset="instance('itemset_data')/item_list/i[@filter = /data/filter]">
<label ref="label"/>
<value ref="value"/>
</itemset>
</select1>
</h:body>
</h:html>

0 comments on commit eb7afb0

Please sign in to comment.