Commits

Anonymous committed 1ba25fa

Add a test for the relevance bug with looped groups.

Comments (0)

Files changed (3)

core/test/org/javarosa/core/model/test/FormDefTest.java

 import j2meunit.framework.TestMethod;
 import j2meunit.framework.TestSuite;
 
+import java.io.File;
+import java.net.URL;
+
 import org.javarosa.core.model.FormElementStateListener;
 import org.javarosa.core.model.FormIndex;
 import org.javarosa.core.model.IDataReference;
 import org.javarosa.core.model.IFormElement;
 import org.javarosa.core.model.QuestionDef;
+import org.javarosa.core.model.SelectChoice;
 import org.javarosa.core.model.data.IntegerData;
+import org.javarosa.core.model.data.SelectOneData;
+import org.javarosa.core.model.data.helper.Selection;
 import org.javarosa.core.model.instance.TreeElement;
+import org.javarosa.core.model.instance.TreeReference;
 import org.javarosa.core.services.PrototypeManager;
 import org.javarosa.core.test.FormParseInit;
 import org.javarosa.core.util.externalizable.ExtUtil;
 import org.javarosa.core.util.externalizable.PrototypeFactory;
 import org.javarosa.form.api.FormEntryController;
+import org.javarosa.form.api.FormEntryModel;
 import org.javarosa.form.api.FormEntryPrompt;
 
 /**
 	}	
 	
 	public void initStuff(){
-		fpi = new FormParseInit();
+		URL u = this.getClass().getResource("/");
+		
+		if (u != null)
+		{
+			File formFile = new File(u.getPath(), "../../" +
+					"j2me/buildfiles/test/resources/ImageSelectTester.xhtml");
+			fpi = new FormParseInit(formFile.getAbsolutePath());
+		}
+		else
+		{
+			fpi = new FormParseInit();
+		}
+		
 		q = fpi.getFirstQuestionDef();
 		fep = new FormEntryPrompt(fpi.getFormDef(), fpi.getFormEntryModel().getFormIndex());
 	}
 		//ExternalizableTest.testExternalizable(q, this, pf, "QuestionDef [" + msg + "]");
 	}
 	
-	public final static int NUM_TESTS = 1;
+	public final static int NUM_TESTS = 2;
 	public void doTest (int i) {
 		switch (i) {
-		case 1: testAnswerConstraint();break;
+		case 1: testAnswerConstraint(); break;
+		case 2: testRelevanceTriggerWithLoopedGroup(); break;
 		}
 	}
 	
 		}
 	}
 
+	public void testRelevanceTriggerWithLoopedGroup()
+	{
+		File formFile = new File(getClass().getResource("fixtures/" +
+				"testRelevanceTriggerWithLoopedGroup.xml").getPath()); 
+		fpi = new FormParseInit(formFile.getAbsolutePath());
+		
+		FormEntryController fec = fpi.getFormEntryController();
+		FormEntryModel fem = fpi.getFormEntryModel();
+
+		fec.jumpToIndex(FormIndex.createBeginningOfFormIndex());
+		fec.stepToNextEvent();
+		FormIndex show_optional_index = fem.getFormIndex();
+		
+		// TreeReference ref = (TreeReference) fem.getQuestionPrompt().getFormElement().getBind().getReference();
+		QuestionDef show_optional = fpi.getCurrentQuestion();
+		TreeReference ref = (TreeReference) show_optional.getBind().getReference();
+		assertEquals("/javarosa_test/show_optional", ref.toString());
+		
+		SelectChoice yes = show_optional.getChoiceForValue("yes"),
+			no = show_optional.getChoiceForValue("no");
+		fec.answerQuestion(new SelectOneData(new Selection(yes)));
+
+		fec.stepToNextEvent();
+		FormIndex optional_loop = fem.getFormIndex();
+		assertEquals("/javarosa_test/optional_loop",
+				fem.getCaptionPrompt().getFormElement().getBind().getReference().toString());
+		assertTrue(fem.isIndexRelevant(optional_loop));
+		
+		fec.stepToNextEvent();
+		FormIndex optional_note = fem.getFormIndex();
+		assertEquals("/javarosa_test/optional_note",
+				fem.getCaptionPrompt().getFormElement().getBind().getReference().toString());
+		assertTrue(fem.isIndexRelevant(optional_note));
+		
+		fem.setQuestionIndex(show_optional_index);
+		fec.answerQuestion(new SelectOneData(new Selection(no)));
+		assertEquals(false, fem.isIndexRelevant(optional_loop));
+		assertEquals(false, fem.isIndexRelevant(optional_note));
+	}
 
 }

core/test/org/javarosa/core/model/test/QuestionDefTest.java

 
 import org.javarosa.core.model.Constants;
 import org.javarosa.core.model.FormElementStateListener;
-import org.javarosa.core.model.FormIndex;
 import org.javarosa.core.model.IDataReference;
 import org.javarosa.core.model.IFormElement;
 import org.javarosa.core.model.QuestionDef;
-import org.javarosa.core.model.SelectChoice;
 import org.javarosa.core.model.instance.TreeElement;
 import org.javarosa.core.reference.InvalidReferenceException;
 import org.javarosa.core.reference.Reference;
 import org.javarosa.core.reference.RootTranslator;
 import org.javarosa.core.services.PrototypeManager;
 import org.javarosa.core.services.locale.Localizer;
-import org.javarosa.core.services.locale.TableLocaleSource;
 import org.javarosa.core.test.FormParseInit;
 import org.javarosa.core.util.externalizable.ExtUtil;
 import org.javarosa.core.util.externalizable.PrototypeFactory;
-import org.javarosa.form.api.FormEntryCaption;
-import org.javarosa.form.api.FormEntryController;
 import org.javarosa.form.api.FormEntryPrompt;
 
 public class QuestionDefTest extends TestCase {

core/test/org/javarosa/core/model/test/fixtures/testRelevanceTriggerWithLoopedGroup.xml

+<h:html xmlns="http://www.w3.org/2002/xforms" xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:h="http://www.w3.org/1999/xhtml" xmlns:jr="http://openrosa.org/javarosa" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
+  <h:head>
+    <h:title>JavaRosa-Test</h:title>
+    <model>
+      <instance>
+        <javarosa_test id="javarosa_test">
+          <show_optional/>
+          <optional_loop jr:template="">
+            <optional_loop_note/>
+          </optional_loop>
+          <optional_note/>
+        </javarosa_test>
+      </instance>
+      <bind nodeset="/javarosa_test/show_optional" required="true()" type="select1"/>
+      <bind nodeset="/javarosa_test/optional_loop" relevant="selected(/javarosa_test/show_optional, 'yes')"/>
+      <bind nodeset="/javarosa_test/optional_loop/optional_loop_note" readonly="true()" type="string"/>
+      <bind nodeset="/javarosa_test/optional_note" readonly="true()" relevant="selected(/javarosa_test/show_optional, 'yes')" type="string"/>
+    </model>
+  </h:head>
+  <h:body>
+    <select1 ref="/javarosa_test/show_optional">
+      <label>Do you want to see the optional pages?</label>
+      <item>
+        <label>Yes</label>
+        <value>yes</value>
+      </item>
+      <item>
+        <label>No</label>
+        <value>no</value>
+      </item>
+    </select1>
+    <group ref="/javarosa_test/optional_loop">
+      <label>Optional Loop</label>
+      <repeat nodeset="/javarosa_test/optional_loop">
+        <input ref="/javarosa_test/optional_loop/optional_loop_note">
+          <label>This should be hidden</label>
+        </input>
+      </repeat>
+    </group>
+    <input ref="/javarosa_test/optional_note">
+      <label>This should also be hidden</label>
+    </input>
+  </h:body>
+</h:html>