Skip to content

Commit

Permalink
Replace form design exception test
Browse files Browse the repository at this point in the history
  • Loading branch information
lognaturel committed Oct 14, 2021
1 parent aff542f commit db60c32
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 95 deletions.
95 changes: 23 additions & 72 deletions collect_app/src/androidTest/assets/forms/form_design_error.xml
Original file line number Diff line number Diff line change
@@ -1,88 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<h:html xmlns:h="http://www.w3.org/1999/xhtml" xmlns="http://www.w3.org/2002/xforms" xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:jr="http://openrosa.org/javarosa" xmlns:odk="http://www.opendatakit.org/xforms" xmlns:orx="http://openrosa.org/xforms" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<?xml version="1.0"?>
<h:html xmlns="http://www.w3.org/2002/xforms" xmlns:h="http://www.w3.org/1999/xhtml" xmlns:jr="http://openrosa.org/javarosa" xmlns:odk="http://www.opendatakit.org/xforms">
<h:head>
<h:title>form_design_error</h:title>
<h:title>Relevance and calculate loop</h:title>
<model odk:xforms-version="1.0.0">
<instance>
<data id="form_design_error">
<data id="form-list-relevance-issue">
<group>
<select />
<select2 />
<name>A</name>
<fullName/>
<middleName>third</middleName>
</group>
<meta>
<instanceID />
<instanceID/>
</meta>
</data>
</instance>
<instance id="list">
<root>
<item>
<label>A</label>
<name>a</name>
</item>
<item>
<label>B</label>
<name>b</name>
</item>
<item>
<label>C</label>
<name>c</name>
</item>
</root>
</instance>
<instance id="list2">
<root>
<item>
<label>AA</label>
<list>a</list>
<name>aa</name>
</item>
<item>
<label>AB</label>
<list>a</list>
<name>ab</name>
</item>
<item>
<label>BA</label>
<list>b</list>
<name>ba</name>
</item>
<item>
<label>BB</label>
<list>b</list>
<name>bb</name>
</item>
</root>
</instance>
<bind nodeset="/data/group/select" type="string" />
<bind calculate="concat( /data/group/select , 'a')" nodeset="/data/group/select2" type="string" />
<bind jr:preload="uid" nodeset="/data/meta/instanceID" readonly="true()" type="string" />
<bind nodeset="/data/group/name" type="string"/>
<!-- The form design issue is that calculates can't be used as dynamic defaults because they're reevaluated continuously -->
<bind calculate=" /data/group/name " nodeset="/data/group/fullName" type="string"/>
<bind nodeset="/data/group/middleName" relevant=" /data/group/name != /data/group/fullName " type="string"/>
<bind jr:preload="uid" nodeset="/data/meta/instanceID" readonly="true()" type="string"/>
</model>
</h:head>
<h:body>
<group appearance="field-list" ref="/data/group">
<select1 appearance="minimal" ref="/data/group/select">
<label>Select</label>
<item>
<label>A</label>
<value>a</value>
</item>
<item>
<label>B</label>
<value>b</value>
</item>
<item>
<label>C</label>
<value>c</value>
</item>
</select1>
<select1 appearance="minimal" ref="/data/group/select2">
<label>Select2</label>
<itemset nodeset="instance('list2')/root/item[list= /data/group/select ]">
<value ref="name" />
<label ref="label" />
</itemset>
</select1>
<input ref="/data/group/name">
<label>What is your first name</label>
</input>
<input ref="/data/group/fullName">
<label>Please add your second name to have your full name</label>
</input>
<input ref="/data/group/middleName">
<label>Please add your middle name if you have one</label>
<hint>Display if full name is different than first name</hint>
</input>
</group>
</h:body>
</h:html>
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,14 @@ class CatchFormDesignExceptionsTest {
rule.startAtMainMenu()
.copyForm("form_design_error.xml")
.clickFillBlankForm()
.clickOnForm("form_design_error")
.openSelectMinimalDialog()
.clickOnText("A")
.clickOnForm("Relevance and calculate loop")
.answerQuestion(1, "B")
.scrollToAndAssertText("third")
.answerQuestion(2, "C")
// Answering C above triggers a recomputation round which resets fullName to name.
// They're then equal which makes the third question non-relevant. Trying to change the
// value of a non-relevant node throws an exception.
.answerQuestion(2, "D")
.assertText(R.string.update_widgets_error)
.clickOKOnDialog()
.assertOnPage(MainMenuPage())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ public class ContextMenuTest {
@Test
public void whenRemoveStringAnswer_ShouldAppropriateQuestionBeCleared() {
new FormEntryPage("string_widgets")
.putTextOnIndex(0, "TestString")
.putTextOnIndex(1, "1234")
.answerQuestion(0, "TestString")
.answerQuestion(1, "1234")
.assertText("TestString")
.assertText("1234")
.longPressOnView("Question1")
.removeResponse()
.assertTextDoesNotExist("TestString")
.assertText("1234")
.putTextOnIndex(0, "TestString")
.answerQuestion(0, "TestString")
.assertText("TestString")
.longPressOnView("Question2")
.removeResponse()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ public void invalidAnswer_ShouldDisplayAllQuestionsOnOnePage() {

new MainMenuPage()
.startBlankForm("OnePageFormShort")
.putTextOnIndex(0, "A")
.answerQuestion(0, "A")
.clickGoToArrow()
.clickJumpEndButton()
.clickSaveAndExitWithError()
.checkIsToastWithMessageDisplayed("Response length must be between 5 and 15")
.assertText("Integer")
.putTextOnIndex(0, "Aaaaa")
.answerQuestion(0, "Aaaaa")
.clickGoToArrow()
.clickJumpEndButton()
.clickSaveAndExit();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
package org.odk.collect.android.support.pages;

import androidx.appcompat.widget.AppCompatImageButton;
import androidx.test.espresso.Espresso;

import org.hamcrest.Matchers;
import org.odk.collect.android.R;
import org.odk.collect.android.support.ActivityHelpers;
import org.odk.collect.android.utilities.FlingRegister;

import java.util.concurrent.Callable;

import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.action.ViewActions.click;
import static androidx.test.espresso.action.ViewActions.longClick;
Expand All @@ -28,6 +18,16 @@
import static org.hamcrest.core.StringEndsWith.endsWith;
import static org.odk.collect.android.support.CustomMatchers.withIndex;

import androidx.appcompat.widget.AppCompatImageButton;
import androidx.test.espresso.Espresso;

import org.hamcrest.Matchers;
import org.odk.collect.android.R;
import org.odk.collect.android.support.ActivityHelpers;
import org.odk.collect.android.utilities.FlingRegister;

import java.util.concurrent.Callable;

public class FormEntryPage extends Page<FormEntryPage> {

private final String formName;
Expand Down Expand Up @@ -171,11 +171,6 @@ public FormEntryPage clickRankingButton() {
return this;
}

public FormEntryPage putTextOnIndex(int index, String text) {
onView(withIndex(withClassName(endsWith("Text")), index)).perform(replaceText(text));
return this;
}

public FormEntryPage deleteGroup(String questionText) {
onView(withText(questionText)).perform(longClick());
onView(withText(R.string.delete_repeat)).perform(click());
Expand Down Expand Up @@ -284,6 +279,11 @@ public FormEntryPage answerQuestion(String question, String answer) {
return this;
}

public FormEntryPage answerQuestion(int index, String answer) {
onView(withIndex(withClassName(endsWith("Text")), index)).perform(replaceText(answer));
return this;
}

public FormEntryPage assertQuestion(String text) {
waitForText(text);
return this;
Expand Down

0 comments on commit db60c32

Please sign in to comment.