Skip to content

Commit

Permalink
test for default captions
Browse files Browse the repository at this point in the history
  • Loading branch information
shubham1g5 committed Aug 21, 2024
1 parent 2a8ed9f commit 3c381eb
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
24 changes: 19 additions & 5 deletions src/test/java/org/commcare/formplayer/tests/RepeatTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void testRepeatNonCountedSimple() throws Exception {
NewFormResponse newSessionResponse = startNewForm("requests/new_form/new_form.json",
"xforms/repeat.xml");
QuestionBean[] tree = newSessionResponse.getTree();
assert (tree.length == 2);
assert (tree.length == 3);
QuestionBean dummyNode = tree[1];
assertEquals("false", dummyNode.getExists());
assertEquals("Add Empty Caption Label", dummyNode.getAddChoice());
Expand All @@ -53,7 +53,7 @@ public void testRepeatNonCountedSimple() throws Exception {

// Verify the repeat has been added to form tree correctly
tree = newRepeatResponseBean.getTree();
assert (tree.length == 3);
assert (tree.length == 4);
QuestionBean firstRepeat = tree[1];
assertEquals("true", firstRepeat.getExists());
assertEquals(true, firstRepeat.isDelete());
Expand All @@ -73,7 +73,7 @@ public void testRepeatNonCountedSimple() throws Exception {
// Add another repeat and verify the form tree accordingly
newRepeatResponseBean = newRepeatRequest(sessionId, "1_1");
tree = newRepeatResponseBean.getTree();
assert (tree.length == 4);
assert (tree.length == 5);
secondRepeat = tree[2];
assertEquals("true", secondRepeat.getExists());
assert (secondRepeat.getChildren().length == 1);
Expand All @@ -94,7 +94,7 @@ public void testRepeatNonCountedSimple() throws Exception {

// Verify that we deleted the repeat at right index
tree = deleteRepeatResponseBean.getTree();
assert (tree.length == 4);
assert (tree.length == 5);
firstRepeat = tree[1];
secondRepeat = tree[2];
thirdRepeat = tree[3];
Expand All @@ -106,7 +106,7 @@ public void testRepeatNonCountedSimple() throws Exception {
// delete second repeat again from the new tree
deleteRepeatResponseBean = deleteRepeatRequest(sessionId, "1_1,0");
tree = deleteRepeatResponseBean.getTree();
assert (tree.length == 3);
assert (tree.length == 4);
firstRepeat = tree[1];
secondRepeat = tree[2];
assertEquals(firstRepeat.getChildren()[0].getAnswer(),"repeat 1");
Expand Down Expand Up @@ -239,4 +239,18 @@ public void testNestedRepeatDeletionRegression() throws Exception {
assertEquals("bed 2", beds[0].getChildren()[0].getChildren()[0].getAnswer());
assertEquals("false", beds[1].getExists());
}

@Test
public void testDefaultRepeatCaption() throws Exception {
NewFormResponse newSessionResponse = startNewForm("requests/new_form/new_form.json",
"xforms/repeat.xml");
QuestionBean[] tree = newSessionResponse.getTree();
assertEquals("Add a new question4", tree[2].getAddChoice());
String sessionId = newSessionResponse.getSessionId();
FormEntryResponseBean newRepeatResponseBean = newRepeatRequest(sessionId, "2_0");

// Verify the repeat has been added to form tree correctly
tree = newRepeatResponseBean.getTree();
assertEquals("Add another question4", tree[3].getAddChoice());
}
}
17 changes: 17 additions & 0 deletions src/test/resources/xforms/repeat.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
<question3 jr:template="">
<repeat_text/>
</question3>
<question4 jr:template="">
<repeat_text/>
</question4>
<orx:meta xmlns:cc="http://commcarehq.org/xforms"><orx:deviceID/><orx:timeStart/><orx:timeEnd/><orx:username/><orx:userID/><orx:instanceID/><cc:appVersion/><cc:location/></orx:meta></data>
</instance><instance id="commcaresession" src="jr://instance/session"/>
<bind nodeset="/data/q_name" type="xsd:string" required="true()"/>
Expand All @@ -31,6 +34,12 @@
<text id="question3/add-empty-caption-label">
<value>Add Empty Caption Label</value>
</text>
<text id="question4-label">
<value>question4</value>
</text>
<text id="question4/repeat_text-label">
<value>repeat_text</value>
</text>
</translation>
<translation lang="hin">
<text id="q_name-label">
Expand Down Expand Up @@ -60,5 +69,13 @@
</input>
</repeat>
</group>
<group>
<label ref="jr:itext('question4-label')"/>
<repeat nodeset="/data/question4">
<input ref="/data/question4/repeat_text">
<label ref="jr:itext('question4/repeat_text-label')"/>
</input>
</repeat>
</group>
</h:body>
</h:html>

0 comments on commit 3c381eb

Please sign in to comment.