Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed removing repeat groups #3327

Merged
merged 8 commits into from
Sep 13, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions collect_app/src/androidTest/assets/forms/repeat_groups.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<h:html xmlns="http://www.w3.org/2002/xforms" xmlns:h="http://www.w3.org/1999/xhtml" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:jr="http://openrosa.org/javarosa">
<h:head>
<h:title>repeatGroups</h:title>
<model>
<instance>
<data id="build_repeatGroups_1567117575">
<meta>
<instanceID/>
</meta>
<repeatGroup jr:template="">
<text1/>
<text2/>
</repeatGroup>
<repeatGroupFieldList jr:template="">
<number1/>
<number2/>
</repeatGroupFieldList>
</data>
</instance>
<itext>
<translation lang="English">
<text id="/data/repeatGroup:label">
<value>repeatGroup</value>
</text>
<text id="/data/repeatGroup/text1:label">
<value>text1</value>
</text>
<text id="/data/repeatGroup/text2:label">
<value>text2</value>
</text>
<text id="/data/repeatGroupFieldList:label">
<value>repeatGroupFieldList</value>
</text>
<text id="/data/repeatGroupFieldList/number1:label">
<value>number1</value>
</text>
<text id="/data/repeatGroupFieldList/number2:label">
<value>number2</value>
</text>
</translation>
</itext>
<bind nodeset="/data/meta/instanceID" type="string" readonly="true()" calculate="concat('uuid:', uuid())"/>
<bind nodeset="/data/repeatGroup/text1" type="string"/>
<bind nodeset="/data/repeatGroup/text2" type="string"/>
<bind nodeset="/data/repeatGroupFieldList/number1" type="int"/>
<bind nodeset="/data/repeatGroupFieldList/number2" type="int"/>
</model>
</h:head>
<h:body>
<group ref="/data/repeatGroup">
<label ref="jr:itext('/data/repeatGroup:label')"/>
<repeat nodeset="/data/repeatGroup">
<input ref="/data/repeatGroup/text1">
<label ref="jr:itext('/data/repeatGroup/text1:label')"/>
</input>
<input ref="/data/repeatGroup/text2">
<label ref="jr:itext('/data/repeatGroup/text2:label')"/>
</input>
</repeat>
</group>
<group ref="/data/repeatGroupFieldList">
<label ref="jr:itext('/data/repeatGroupFieldList:label')"/>
<repeat appearance="field-list" nodeset="/data/repeatGroupFieldList">
<input ref="/data/repeatGroupFieldList/number1">
<label ref="jr:itext('/data/repeatGroupFieldList/number1:label')"/>
</input>
<input ref="/data/repeatGroupFieldList/number2">
<label ref="jr:itext('/data/repeatGroupFieldList/number2:label')"/>
</input>
</repeat>
</group>
</h:body>
</h:html>
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ public static void clickDeleteChildIcon() {
onView(withId(R.id.menu_delete_child)).perform(click());
}

public static void clickGoUpIcon() {
onView(withId(R.id.menu_go_up)).perform(click());
}

public static void checkIsToastWithStringDisplayes(int value, ActivityTestRule main) {
onView(withText(getInstrumentation().getTargetContext().getString(value))).inRoot(withDecorView(not(is(main.getActivity().getWindow().getDecorView())))).check(matches(isDisplayed()));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,282 @@
package org.odk.collect.android.formentry;

import android.Manifest;

import androidx.test.espresso.intent.rule.IntentsTestRule;
import androidx.test.rule.GrantPermissionRule;

import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.RuleChain;
import org.odk.collect.android.R;
import org.odk.collect.android.activities.FormEntryActivity;
import org.odk.collect.android.espressoutils.FormEntry;
import org.odk.collect.android.support.CopyFormRule;
import org.odk.collect.android.support.ResetStateRule;
import org.odk.collect.android.support.matchers.RecyclerViewMatcher;
import org.odk.collect.android.test.FormLoadingUtils;

import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.action.ViewActions.click;
import static androidx.test.espresso.action.ViewActions.longClick;
import static androidx.test.espresso.assertion.ViewAssertions.matches;
import static androidx.test.espresso.matcher.ViewMatchers.withId;
import static androidx.test.espresso.matcher.ViewMatchers.withText;

public class DeletingRepeatGroupsTest {
private static final String TEST_FORM = "repeat_groups.xml";

@Rule
public IntentsTestRule<FormEntryActivity> activityTestRule = FormLoadingUtils.getFormActivityTestRuleFor(TEST_FORM);

@Rule
public RuleChain copyFormChain = RuleChain
.outerRule(GrantPermissionRule.grant(
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE
)
)
.around(new ResetStateRule())
.around(new CopyFormRule(TEST_FORM, null));

@Test
public void testDeletingRepeatGroupsInForm() {
lognaturel marked this conversation as resolved.
Show resolved Hide resolved
FormEntry.clickOnString(R.string.add_another);
FormEntry.putText("11");
FormEntry.swipeToNextQuestion();
FormEntry.putText("12");
FormEntry.swipeToNextQuestion();
FormEntry.clickOnString(R.string.add_another);
FormEntry.putText("21");
FormEntry.swipeToNextQuestion();
FormEntry.putText("22");
FormEntry.swipeToNextQuestion();
FormEntry.clickOnString(R.string.add_another);
FormEntry.putText("31");
FormEntry.swipeToNextQuestion();
FormEntry.putText("32");
FormEntry.swipeToNextQuestion();
FormEntry.clickOnString(R.string.add_another);
FormEntry.putText("41");
FormEntry.swipeToNextQuestion();
FormEntry.putText("42");
FormEntry.swipeToPrevoiusQuestion();
lognaturel marked this conversation as resolved.
Show resolved Hide resolved
FormEntry.swipeToPrevoiusQuestion();
FormEntry.swipeToPrevoiusQuestion();
FormEntry.swipeToPrevoiusQuestion();
FormEntry.swipeToPrevoiusQuestion();
FormEntry.swipeToPrevoiusQuestion();
FormEntry.swipeToPrevoiusQuestion();
onView(withText("text1")).perform(longClick());
onView(withText(R.string.delete_repeat)).perform(click());
onView(withText(R.string.discard_group)).perform(click());
FormEntry.checkIsTextDisplayed("21");
FormEntry.swipeToNextQuestion();
FormEntry.checkIsTextDisplayed("22");
FormEntry.swipeToNextQuestion();
FormEntry.checkIsTextDisplayed("31");
FormEntry.swipeToNextQuestion();
FormEntry.checkIsTextDisplayed("32");
FormEntry.swipeToNextQuestion();
FormEntry.checkIsTextDisplayed("41");
FormEntry.swipeToNextQuestion();
FormEntry.checkIsTextDisplayed("42");
FormEntry.swipeToPrevoiusQuestion();
FormEntry.swipeToPrevoiusQuestion();
onView(withText("text2")).perform(longClick());
onView(withText(R.string.delete_repeat)).perform(click());
onView(withText(R.string.discard_group)).perform(click());
FormEntry.checkIsTextDisplayed("41");
FormEntry.swipeToNextQuestion();
FormEntry.checkIsTextDisplayed("42");
onView(withText("text2")).perform(longClick());
onView(withText(R.string.delete_repeat)).perform(click());
onView(withText(R.string.discard_group)).perform(click());
FormEntry.clickOnString(R.string.add_repeat_no);
FormEntry.swipeToPrevoiusQuestion();
FormEntry.checkIsTextDisplayed("22");
FormEntry.swipeToPrevoiusQuestion();
FormEntry.checkIsTextDisplayed("21");
onView(withText("text1")).perform(longClick());
onView(withText(R.string.delete_repeat)).perform(click());
onView(withText(R.string.discard_group)).perform(click());
FormEntry.checkIsStringDisplayed(R.string.entering_repeat_ask);
}

@Test
public void testDeletingRepeatGroupsInHierarchy() {
FormEntry.clickOnString(R.string.add_another);
FormEntry.putText("11");
FormEntry.swipeToNextQuestion();
FormEntry.putText("12");
FormEntry.swipeToNextQuestion();
FormEntry.clickOnString(R.string.add_another);
FormEntry.putText("21");
FormEntry.swipeToNextQuestion();
FormEntry.putText("22");
FormEntry.swipeToNextQuestion();
FormEntry.clickOnString(R.string.add_another);
FormEntry.putText("31");
FormEntry.swipeToNextQuestion();
FormEntry.putText("32");
FormEntry.swipeToNextQuestion();
FormEntry.clickOnString(R.string.add_another);
FormEntry.putText("41");
FormEntry.swipeToNextQuestion();
FormEntry.putText("42");
FormEntry.clickGoToIconInForm();
FormEntry.checkIsTextDisplayed("41");
FormEntry.checkIsTextDisplayed("42");
FormEntry.clickGoUpIcon();
onView(withId(R.id.list)).check(matches(RecyclerViewMatcher.withListSize(4)));
FormEntry.clickOnText("repeatGroup > 1");
FormEntry.checkIsTextDisplayed("11");
FormEntry.checkIsTextDisplayed("12");
FormEntry.clickDeleteChildIcon();
FormEntry.clickOnString(R.string.delete_repeat);
onView(withId(R.id.list)).check(matches(RecyclerViewMatcher.withListSize(3)));
FormEntry.clickOnText("repeatGroup > 1");
FormEntry.checkIsTextDisplayed("21");
FormEntry.checkIsTextDisplayed("22");
FormEntry.clickGoUpIcon();
FormEntry.clickOnText("repeatGroup > 2");
FormEntry.checkIsTextDisplayed("31");
FormEntry.checkIsTextDisplayed("32");
FormEntry.clickGoUpIcon();
FormEntry.clickOnText("repeatGroup > 3");
FormEntry.checkIsTextDisplayed("41");
FormEntry.checkIsTextDisplayed("42");
FormEntry.clickGoUpIcon();
FormEntry.clickOnText("repeatGroup > 2");
FormEntry.clickDeleteChildIcon();
FormEntry.clickOnString(R.string.delete_repeat);
onView(withId(R.id.list)).check(matches(RecyclerViewMatcher.withListSize(2)));
FormEntry.clickOnText("repeatGroup > 1");
FormEntry.checkIsTextDisplayed("21");
FormEntry.checkIsTextDisplayed("22");
FormEntry.clickGoUpIcon();
FormEntry.clickOnText("repeatGroup > 2");
FormEntry.checkIsTextDisplayed("41");
FormEntry.checkIsTextDisplayed("42");
FormEntry.clickDeleteChildIcon();
FormEntry.clickOnString(R.string.delete_repeat);
onView(withId(R.id.list)).check(matches(RecyclerViewMatcher.withListSize(1)));
FormEntry.clickOnText("repeatGroup > 1");
FormEntry.checkIsTextDisplayed("21");
FormEntry.checkIsTextDisplayed("22");
FormEntry.clickDeleteChildIcon();
FormEntry.clickOnString(R.string.delete_repeat);
}

@Test
public void testDeletingRepeatGroupsWithFieldListInForm() {
FormEntry.clickOnString(R.string.add_repeat_no);
FormEntry.clickOnString(R.string.add_another);
FormEntry.putTextOnIndex(0, "11");
FormEntry.putTextOnIndex(1, "12");
FormEntry.swipeToNextQuestion();
FormEntry.clickOnString(R.string.add_another);
FormEntry.putTextOnIndex(0, "21");
FormEntry.putTextOnIndex(1, "22");
FormEntry.swipeToNextQuestion();
FormEntry.clickOnString(R.string.add_another);
FormEntry.putTextOnIndex(0, "31");
FormEntry.putTextOnIndex(1, "32");
FormEntry.swipeToNextQuestion();
FormEntry.clickOnString(R.string.add_another);
FormEntry.putTextOnIndex(0, "41");
FormEntry.putTextOnIndex(1, "42");
FormEntry.swipeToPrevoiusQuestion();
FormEntry.swipeToPrevoiusQuestion();
FormEntry.swipeToPrevoiusQuestion();
onView(withText("number1")).perform(longClick());
onView(withText(R.string.delete_repeat)).perform(click());
onView(withText(R.string.discard_group)).perform(click());
FormEntry.checkIsTextDisplayed("21");
FormEntry.checkIsTextDisplayed("22");
FormEntry.swipeToNextQuestion();
FormEntry.checkIsTextDisplayed("31");
FormEntry.checkIsTextDisplayed("32");
FormEntry.swipeToNextQuestion();
FormEntry.checkIsTextDisplayed("41");
FormEntry.checkIsTextDisplayed("42");
FormEntry.swipeToPrevoiusQuestion();
onView(withText("number2")).perform(longClick());
onView(withText(R.string.delete_repeat)).perform(click());
onView(withText(R.string.discard_group)).perform(click());
FormEntry.checkIsTextDisplayed("41");
FormEntry.checkIsTextDisplayed("42");
onView(withText("number2")).perform(longClick());
onView(withText(R.string.delete_repeat)).perform(click());
onView(withText(R.string.discard_group)).perform(click());
FormEntry.swipeToPrevoiusQuestion();
FormEntry.checkIsTextDisplayed("22");
FormEntry.checkIsTextDisplayed("21");
onView(withText("number1")).perform(longClick());
onView(withText(R.string.delete_repeat)).perform(click());
onView(withText(R.string.discard_group)).perform(click());
FormEntry.checkIsStringDisplayed(R.string.quit_entry);
}

@Test
public void testDeletingRepeatGroupsWithFieldListInHierarchy() {
FormEntry.clickOnString(R.string.add_repeat_no);
FormEntry.clickOnString(R.string.add_another);
FormEntry.putTextOnIndex(0, "11");
FormEntry.putTextOnIndex(1, "12");
FormEntry.swipeToNextQuestion();
FormEntry.clickOnString(R.string.add_another);
FormEntry.putTextOnIndex(0, "21");
FormEntry.putTextOnIndex(1, "22");
FormEntry.swipeToNextQuestion();
FormEntry.clickOnString(R.string.add_another);
FormEntry.putTextOnIndex(0, "31");
FormEntry.putTextOnIndex(1, "32");
FormEntry.swipeToNextQuestion();
FormEntry.clickOnString(R.string.add_another);
FormEntry.putTextOnIndex(0, "41");
FormEntry.putTextOnIndex(1, "42");
FormEntry.clickGoToIconInForm();
FormEntry.checkIsTextDisplayed("41");
FormEntry.checkIsTextDisplayed("42");
FormEntry.clickGoUpIcon();
onView(withId(R.id.list)).check(matches(RecyclerViewMatcher.withListSize(4)));
FormEntry.clickOnText("repeatGroupFieldList > 1");
FormEntry.checkIsTextDisplayed("11");
FormEntry.checkIsTextDisplayed("12");
FormEntry.clickDeleteChildIcon();
FormEntry.clickOnString(R.string.delete_repeat);
onView(withId(R.id.list)).check(matches(RecyclerViewMatcher.withListSize(3)));
FormEntry.clickOnText("repeatGroupFieldList > 1");
FormEntry.checkIsTextDisplayed("21");
FormEntry.checkIsTextDisplayed("22");
FormEntry.clickGoUpIcon();
FormEntry.clickOnText("repeatGroupFieldList > 2");
FormEntry.checkIsTextDisplayed("31");
FormEntry.checkIsTextDisplayed("32");
FormEntry.clickGoUpIcon();
FormEntry.clickOnText("repeatGroupFieldList > 3");
FormEntry.checkIsTextDisplayed("41");
FormEntry.checkIsTextDisplayed("42");
FormEntry.clickGoUpIcon();
FormEntry.clickOnText("repeatGroupFieldList > 2");
FormEntry.clickDeleteChildIcon();
FormEntry.clickOnString(R.string.delete_repeat);
onView(withId(R.id.list)).check(matches(RecyclerViewMatcher.withListSize(2)));
FormEntry.clickOnText("repeatGroupFieldList > 1");
FormEntry.checkIsTextDisplayed("21");
FormEntry.checkIsTextDisplayed("22");
FormEntry.clickGoUpIcon();
FormEntry.clickOnText("repeatGroupFieldList > 2");
FormEntry.checkIsTextDisplayed("41");
FormEntry.checkIsTextDisplayed("42");
FormEntry.clickDeleteChildIcon();
FormEntry.clickOnString(R.string.delete_repeat);
onView(withId(R.id.list)).check(matches(RecyclerViewMatcher.withListSize(1)));
FormEntry.clickOnText("repeatGroupFieldList > 1");
FormEntry.checkIsTextDisplayed("21");
FormEntry.checkIsTextDisplayed("22");
FormEntry.clickDeleteChildIcon();
FormEntry.clickOnString(R.string.delete_repeat);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1786,10 +1786,13 @@ public void onClick(DialogInterface dialog, int i) {
*/
private void createDeleteRepeatConfirmDialog() {
DialogUtils.showDeleteRepeatConfirmDialog(this, () -> {
showNextView();
}, () -> {
refreshCurrentView();
});
FormController formController = getFormController();
if (formController != null && !formController.indexIsInFieldList()) {
showNextView();
} else {
refreshCurrentView();
}
}, this::refreshCurrentView);
}

/**
Expand Down