Fix UI test for settings screen

pull/87/head
Alinson S. Xavier 10 years ago
parent fcee8552f0
commit e2bb4371d3

@ -43,10 +43,20 @@ dependencies {
compile files('libs/ActiveAndroid.jar')
androidTestCompile 'com.android.support:support-annotations:23.2.1'
androidTestCompile 'com.android.support.test:runner:0.4.1'
androidTestCompile 'com.android.support.test:rules:0.4.1'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1'
androidTestCompile 'com.android.support.test.espresso:espresso-intents:2.2.1'
androidTestCompile 'com.android.support.test:runner:0.5'
androidTestCompile 'com.android.support.test:rules:0.5'
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.1') {
exclude group: 'com.android.support'
}
androidTestCompile('com.android.support.test.espresso:espresso-intents:2.2.1') {
exclude group: 'com.android.support'
}
androidTestCompile('com.android.support.test.espresso:espresso-contrib:2.2.1') {
exclude group: 'com.android.support'
}
}

@ -20,9 +20,8 @@
package org.isoron.uhabits.ui;
import android.support.test.espresso.NoMatchingViewException;
import android.view.View;
import android.support.test.espresso.contrib.RecyclerViewActions;
import org.hamcrest.Matcher;
import org.isoron.uhabits.R;
import org.isoron.uhabits.models.Habit;
@ -40,7 +39,7 @@ import static android.support.test.espresso.action.ViewActions.replaceText;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.RootMatchers.isPlatformPopup;
import static android.support.test.espresso.matcher.ViewMatchers.Visibility.VISIBLE;
import static android.support.test.espresso.matcher.ViewMatchers.isCompletelyDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.hasDescendant;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withClassName;
import static android.support.test.espresso.matcher.ViewMatchers.withContentDescription;
@ -59,9 +58,6 @@ import static org.isoron.uhabits.ui.HabitMatchers.withName;
public class MainActivityActions
{
private static final Matcher<View> OVERFLOW_BUTTON_MATCHER =
allOf(isCompletelyDisplayed(), withContentDescription("More options"));
public static String addHabit()
{
return addHabit(false);
@ -218,4 +214,12 @@ public class MainActivityActions
onView(withText(stringId)).perform(click());
}
public static void clickSettingsItem(String text)
{
onView(withClassName(containsString("RecyclerView")))
.perform(RecyclerViewActions.actionOnItem(
hasDescendant(withText(containsString(text))),
click()));
}
}

@ -67,7 +67,6 @@ import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.startsWith;
import static org.isoron.uhabits.ui.HabitMatchers.isPreferenceWithText;
import static org.isoron.uhabits.ui.HabitMatchers.withName;
import static org.isoron.uhabits.ui.HabitViewActions.clickAtRandomLocations;
import static org.isoron.uhabits.ui.HabitViewActions.toggleAllCheckmarks;
@ -76,6 +75,7 @@ import static org.isoron.uhabits.ui.MainActivityActions.assertHabitExists;
import static org.isoron.uhabits.ui.MainActivityActions.assertHabitsDontExist;
import static org.isoron.uhabits.ui.MainActivityActions.assertHabitsExist;
import static org.isoron.uhabits.ui.MainActivityActions.clickMenuItem;
import static org.isoron.uhabits.ui.MainActivityActions.clickSettingsItem;
import static org.isoron.uhabits.ui.MainActivityActions.deleteHabit;
import static org.isoron.uhabits.ui.MainActivityActions.deleteHabits;
import static org.isoron.uhabits.ui.MainActivityActions.selectHabit;
@ -303,13 +303,13 @@ public class MainTest
String date = DateHelper.getBackupDateFormat().format(DateHelper.getLocalTime());
date = date.substring(0, date.length() - 2);
onData(isPreferenceWithText("Export full backup")).perform(click());
clickSettingsItem("Export full backup");
intended(hasAction(Intent.ACTION_SEND));
deleteHabit(name);
clickMenuItem(R.string.settings);
onData(isPreferenceWithText("Import data")).perform(click());
clickSettingsItem("Import data");
onData(allOf(is(instanceOf(String.class)), startsWith("Backups")))
.perform(click());
@ -329,7 +329,7 @@ public class MainTest
{
addHabit();
clickMenuItem(R.string.settings);
onData(isPreferenceWithText("Export as CSV")).perform(click());
clickSettingsItem("Export as CSV");
intended(hasAction(Intent.ACTION_SEND));
}
@ -340,7 +340,7 @@ public class MainTest
public void testGenerateBugReport()
{
clickMenuItem(R.string.settings);
onData(isPreferenceWithText("Generate bug report")).perform(click());
clickSettingsItem("Generate bug report");
intended(hasAction(Intent.ACTION_SENDTO));
}
}

Loading…
Cancel
Save