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 5 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
75 changes: 75 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,75 @@
<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>
<text1>1</text1>
</repeatGroup>
<repeatGroup>
<text1>2</text1>
</repeatGroup>
<repeatGroup>
<text1>3</text1>
</repeatGroup>
<repeatGroup>
<text1>4</text1>
</repeatGroup>
<repeatGroupFieldList>
<number1>1</number1>
</repeatGroupFieldList>
<repeatGroupFieldList>
<number1>2</number1>
</repeatGroupFieldList>
<repeatGroupFieldList>
<number1>3</number1>
</repeatGroupFieldList>
<repeatGroupFieldList>
<number1>4</number1>
</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/repeatGroupFieldList:label">
<value>repeatGroupFieldList</value>
</text>
<text id="/data/repeatGroupFieldList/number1:label">
<value>number1</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/repeatGroupFieldList/number1" 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>
</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>
</repeat>
</group>
</h:body>
</h:html>
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import static androidx.test.espresso.Espresso.onData;
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.action.ViewActions.replaceText;
import static androidx.test.espresso.action.ViewActions.swipeLeft;
import static androidx.test.espresso.action.ViewActions.swipeRight;
Expand Down Expand Up @@ -85,12 +86,8 @@ public static void clickGoToIconInForm() {
onView(withId(R.id.menu_goto)).perform(click());
}

public static void clickDeleteChildIcon() {
onView(withId(R.id.menu_delete_child)).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()));
public static void clickGoUpIcon() {
onView(withId(R.id.menu_go_up)).perform(click());
}

public static void clickSaveAndExit() {
Expand All @@ -113,7 +110,7 @@ public static void swipeToNextQuestion() {
onView(withId(R.id.questionholder)).perform(swipeLeft());
}

public static void swipeToPrevoiusQuestion() {
public static void swipeToPreviousQuestion() {
onView(withId(R.id.questionholder)).perform(swipeRight());
}

Expand Down Expand Up @@ -150,6 +147,17 @@ public static void checkAreNavigationButtonsDisplayed() {
onView(withId(R.id.form_back_button)).check(matches(isDisplayed()));
}

public static void deleteGroup(String questionText) {
onView(withText(questionText)).perform(longClick());
onView(withText(R.string.delete_repeat)).perform(click());
onView(withText(R.string.discard_group)).perform(click());
}

public static void deleteGroup() {
onView(withId(R.id.menu_delete_child)).perform(click());
onView(withText(R.string.delete_repeat)).perform(click());
}

public static void waitForRotationToEnd() {
try {
Thread.sleep(2000);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
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.assertion.ViewAssertions.matches;
import static androidx.test.espresso.matcher.ViewMatchers.withId;

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 requestingDeletionOfFirstRepeat_deletesFirstRepeat() {
FormEntry.deleteGroup("text1");
FormEntry.checkIsTextDisplayed("2");
}

@Test
public void requestingDeletionOfMiddleRepeat_deletesMiddleRepeat() {
FormEntry.swipeToNextQuestion();
FormEntry.deleteGroup("text1");
FormEntry.checkIsTextDisplayed("3");
}

@Test
public void requestingDeletionOfLastRepeat_deletesFirstRepeat() {
grzesiek2010 marked this conversation as resolved.
Show resolved Hide resolved
FormEntry.swipeToNextQuestion();
FormEntry.swipeToNextQuestion();
FormEntry.swipeToNextQuestion();
FormEntry.deleteGroup("text1");
FormEntry.checkIsTextDisplayed("number1");
}

@Test
public void requestingDeletionOfFirstRepeatInHierarchy_deletesFirstRepeat() {
FormEntry.clickGoToIconInForm();
FormEntry.clickGoUpIcon();
onView(withId(R.id.list)).check(matches(RecyclerViewMatcher.withListSize(4)));
FormEntry.clickOnText("repeatGroup > 1");
FormEntry.checkIsTextDisplayed("1");
FormEntry.deleteGroup();
onView(withId(R.id.list)).check(matches(RecyclerViewMatcher.withListSize(3)));
FormEntry.clickOnText("repeatGroup > 1");
FormEntry.checkIsTextDisplayed("2");
}

@Test
public void requestingDeletionOfMiddleRepeatInHierarchy_deletesMiddleRepeat() {
FormEntry.clickGoToIconInForm();
FormEntry.clickGoUpIcon();
onView(withId(R.id.list)).check(matches(RecyclerViewMatcher.withListSize(4)));
FormEntry.clickOnText("repeatGroup > 2");
FormEntry.checkIsTextDisplayed("2");
FormEntry.deleteGroup();
onView(withId(R.id.list)).check(matches(RecyclerViewMatcher.withListSize(3)));
FormEntry.clickOnText("repeatGroup > 2");
FormEntry.checkIsTextDisplayed("3");
}

@Test
public void requestingDeletionOfLastRepeatInHierarchy_deletesFirstRepeat() {
grzesiek2010 marked this conversation as resolved.
Show resolved Hide resolved
FormEntry.clickGoToIconInForm();
FormEntry.clickGoUpIcon();
onView(withId(R.id.list)).check(matches(RecyclerViewMatcher.withListSize(4)));
FormEntry.clickOnText("repeatGroup > 4");
FormEntry.checkIsTextDisplayed("4");
FormEntry.deleteGroup();
onView(withId(R.id.list)).check(matches(RecyclerViewMatcher.withListSize(3)));
FormEntry.clickOnText("repeatGroup > 3");
FormEntry.checkIsTextDisplayed("3");
}

@Test
public void requestingDeletionOfFirstRepeatWithFieldList_deletesFirstRepeat() {
FormEntry.clickGoToIconInForm();
FormEntry.clickGoUpIcon();
FormEntry.clickGoUpIcon();
FormEntry.clickOnText("repeatGroupFieldList");
FormEntry.clickOnText("repeatGroupFieldList > 1");
FormEntry.clickOnText("number1");
FormEntry.deleteGroup("number1");
FormEntry.checkIsTextDisplayed("2");
}

@Test
public void requestingDeletionOfMiddleRepeatWithFieldList_deletesMiddleRepeat() {
FormEntry.clickGoToIconInForm();
FormEntry.clickGoUpIcon();
FormEntry.clickGoUpIcon();
FormEntry.clickOnText("repeatGroupFieldList");
FormEntry.clickOnText("repeatGroupFieldList > 2");
FormEntry.clickOnText("number1");
FormEntry.deleteGroup("number1");
FormEntry.checkIsTextDisplayed("3");
}

@Test
public void requestingDeletionOfLastRepeatWithFieldList_deletesFirstRepeat() {
grzesiek2010 marked this conversation as resolved.
Show resolved Hide resolved
FormEntry.clickGoToIconInForm();
FormEntry.clickGoUpIcon();
FormEntry.clickGoUpIcon();
FormEntry.clickOnText("repeatGroupFieldList");
FormEntry.clickOnText("repeatGroupFieldList > 4");
FormEntry.clickOnText("number1");
FormEntry.deleteGroup("number1");
FormEntry.checkIsStringDisplayed(R.string.quit_entry);
}

@Test
public void requestingDeletionOfFirstRepeatWithFieldListInHierarchy_deletesFirstRepeat() {
FormEntry.clickGoToIconInForm();
FormEntry.clickGoUpIcon();
FormEntry.clickGoUpIcon();
FormEntry.clickOnText("repeatGroupFieldList");
onView(withId(R.id.list)).check(matches(RecyclerViewMatcher.withListSize(4)));
FormEntry.clickOnText("repeatGroupFieldList > 1");
FormEntry.deleteGroup();
onView(withId(R.id.list)).check(matches(RecyclerViewMatcher.withListSize(3)));
FormEntry.clickOnText("repeatGroupFieldList > 1");
FormEntry.checkIsTextDisplayed("2");
}

@Test
public void requestingDeletionOfMiddleRepeatWithFieldListInHierarchy_deletesMiddleRepeat() {
FormEntry.clickGoToIconInForm();
FormEntry.clickGoUpIcon();
FormEntry.clickGoUpIcon();
FormEntry.clickOnText("repeatGroupFieldList");
onView(withId(R.id.list)).check(matches(RecyclerViewMatcher.withListSize(4)));
FormEntry.clickOnText("repeatGroupFieldList > 2");
FormEntry.deleteGroup();
onView(withId(R.id.list)).check(matches(RecyclerViewMatcher.withListSize(3)));
FormEntry.clickOnText("repeatGroupFieldList > 2");
FormEntry.checkIsTextDisplayed("3");
}

@Test
public void requestingDeletionOfLastRepeatWithFieldListInHierarchy_deletesFirstRepeat() {
grzesiek2010 marked this conversation as resolved.
Show resolved Hide resolved
FormEntry.clickGoToIconInForm();
FormEntry.clickGoUpIcon();
FormEntry.clickGoUpIcon();
FormEntry.clickOnText("repeatGroupFieldList");
onView(withId(R.id.list)).check(matches(RecyclerViewMatcher.withListSize(4)));
FormEntry.clickOnText("repeatGroupFieldList > 4");
FormEntry.deleteGroup();
onView(withId(R.id.list)).check(matches(RecyclerViewMatcher.withListSize(3)));
FormEntry.clickOnText("repeatGroupFieldList > 3");
FormEntry.checkIsTextDisplayed("3");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,7 @@ public void deletingLastGroupShouldNotBreakHierarchy() {
FormEntry.clickOnText("Repeat Group 1 > 1");
FormEntry.clickOnText("Repeat Group 1_1");
FormEntry.clickOnText("Repeat Group 1_1 > 2");
FormEntry.clickDeleteChildIcon();
FormEntry.clickOnString(R.string.delete_repeat);
FormEntry.deleteGroup();
onView(withId(R.id.list)).check(matches(RecyclerViewMatcher.withListSize(1)));
FormEntry.checkIsTextDisplayed("Repeat Group 1_1 > 1");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public void answers_ShouldBeSuggestedInComplianceWithSelectedLetters() {
FormEntry.putText("Abi");
FormEntry.swipeToNextQuestion();
FormEntry.checkIsTextDisplayed("Abies");
FormEntry.swipeToPrevoiusQuestion();
FormEntry.swipeToPreviousQuestion();
FormEntry.putText("Abr");
FormEntry.swipeToNextQuestion();
FormEntry.checkIsTextDisplayed("Abrotanum alpestre");
Expand Down Expand Up @@ -212,11 +212,11 @@ public void searchExpression_ShouldDisplayWhenItContainsOtherAppearanceName() {
FormEntry.clickOnText("Mountain pine beetle");
FormEntry.swipeToNextQuestion();
FormEntry.checkIsTextDisplayed("2018-COE-MPB-001 @ Wellington");
FormEntry.swipeToPrevoiusQuestion();
FormEntry.swipeToPreviousQuestion();
FormEntry.clickOnText("Invasive alien species");
FormEntry.swipeToNextQuestion();
FormEntry.checkIsTextDisplayed("2018-COE-IAS-e-001 @ Coronation");
FormEntry.swipeToPrevoiusQuestion();
FormEntry.swipeToPreviousQuestion();
FormEntry.clickOnText("Longhorn beetles");
FormEntry.swipeToNextQuestion();
FormEntry.checkIsTextDisplayed("2018-COE-LGH-M-001 @ Acheson");
Expand Down
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