mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-07 09:38:52 -06:00
Switch to compat ActionMode; fix tests
This commit is contained in:
@@ -20,7 +20,9 @@
|
||||
package org.isoron.uhabits.ui;
|
||||
|
||||
import android.support.test.espresso.NoMatchingViewException;
|
||||
import android.view.View;
|
||||
|
||||
import org.hamcrest.Matcher;
|
||||
import org.isoron.uhabits.R;
|
||||
import org.isoron.uhabits.models.Habit;
|
||||
|
||||
@@ -31,7 +33,6 @@ import java.util.Random;
|
||||
|
||||
import static android.support.test.espresso.Espresso.onData;
|
||||
import static android.support.test.espresso.Espresso.onView;
|
||||
import static android.support.test.espresso.Espresso.openContextualActionModeOverflowMenu;
|
||||
import static android.support.test.espresso.Espresso.pressBack;
|
||||
import static android.support.test.espresso.action.ViewActions.click;
|
||||
import static android.support.test.espresso.action.ViewActions.longClick;
|
||||
@@ -39,12 +40,16 @@ 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.isDisplayed;
|
||||
import static android.support.test.espresso.matcher.ViewMatchers.withClassName;
|
||||
import static android.support.test.espresso.matcher.ViewMatchers.withContentDescription;
|
||||
import static android.support.test.espresso.matcher.ViewMatchers.withEffectiveVisibility;
|
||||
import static android.support.test.espresso.matcher.ViewMatchers.withId;
|
||||
import static android.support.test.espresso.matcher.ViewMatchers.withParent;
|
||||
import static android.support.test.espresso.matcher.ViewMatchers.withText;
|
||||
import static org.hamcrest.Matchers.allOf;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
@@ -54,6 +59,9 @@ 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);
|
||||
@@ -168,13 +176,13 @@ public class MainActivityActions
|
||||
public static void deleteHabits(List<String> names)
|
||||
{
|
||||
selectHabits(names);
|
||||
clickActionModeMenuItem(R.string.delete);
|
||||
clickMenuItem(R.string.delete);
|
||||
onView(withText("OK"))
|
||||
.perform(click());
|
||||
assertHabitsDontExist(names);
|
||||
}
|
||||
|
||||
public static void clickActionModeMenuItem(int stringId)
|
||||
public static void clickMenuItem(int stringId)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -188,9 +196,26 @@ public class MainActivityActions
|
||||
}
|
||||
catch(Exception e2)
|
||||
{
|
||||
openContextualActionModeOverflowMenu();
|
||||
onView(withText(stringId)).perform(click());
|
||||
clickHiddenMenuItem(stringId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void clickHiddenMenuItem(int stringId)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Try the ActionMode overflow menu first
|
||||
onView(allOf(withContentDescription("More options"), withParent(withParent(
|
||||
withClassName(containsString("Action")))))).perform(click());
|
||||
}
|
||||
catch (Exception e1)
|
||||
{
|
||||
// Try the toolbar overflow menu
|
||||
onView(allOf(withContentDescription("More options"), withParent(withParent(
|
||||
withClassName(containsString("Toolbar")))))).perform(click());
|
||||
}
|
||||
|
||||
onView(withText(stringId)).perform(click());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,7 +45,6 @@ import java.util.Random;
|
||||
|
||||
import static android.support.test.espresso.Espresso.onData;
|
||||
import static android.support.test.espresso.Espresso.onView;
|
||||
import static android.support.test.espresso.Espresso.openActionBarOverflowOrOptionsMenu;
|
||||
import static android.support.test.espresso.Espresso.pressBack;
|
||||
import static android.support.test.espresso.action.ViewActions.click;
|
||||
import static android.support.test.espresso.action.ViewActions.longClick;
|
||||
@@ -61,7 +60,6 @@ import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
|
||||
import static android.support.test.espresso.matcher.ViewMatchers.isRoot;
|
||||
import static android.support.test.espresso.matcher.ViewMatchers.withClassName;
|
||||
import static android.support.test.espresso.matcher.ViewMatchers.withId;
|
||||
import static android.support.test.espresso.matcher.ViewMatchers.withText;
|
||||
import static org.hamcrest.Matchers.allOf;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.endsWith;
|
||||
@@ -77,7 +75,7 @@ import static org.isoron.uhabits.ui.MainActivityActions.addHabit;
|
||||
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.clickActionModeMenuItem;
|
||||
import static org.isoron.uhabits.ui.MainActivityActions.clickMenuItem;
|
||||
import static org.isoron.uhabits.ui.MainActivityActions.deleteHabit;
|
||||
import static org.isoron.uhabits.ui.MainActivityActions.deleteHabits;
|
||||
import static org.isoron.uhabits.ui.MainActivityActions.selectHabit;
|
||||
@@ -152,20 +150,16 @@ public class MainTest
|
||||
|
||||
selectHabits(names);
|
||||
|
||||
clickActionModeMenuItem(R.string.archive);
|
||||
clickMenuItem(R.string.archive);
|
||||
assertHabitsDontExist(names);
|
||||
|
||||
openActionBarOverflowOrOptionsMenu(targetContext);
|
||||
onView(withText(R.string.show_archived))
|
||||
.perform(click());
|
||||
clickMenuItem(R.string.show_archived);
|
||||
|
||||
assertHabitsExist(names);
|
||||
selectHabits(names);
|
||||
clickActionModeMenuItem(R.string.unarchive);
|
||||
clickMenuItem(R.string.unarchive);
|
||||
|
||||
openActionBarOverflowOrOptionsMenu(targetContext);
|
||||
onView(withText(R.string.show_archived))
|
||||
.perform(click());
|
||||
clickMenuItem(R.string.show_archived);
|
||||
|
||||
assertHabitsExist(names);
|
||||
deleteHabits(names);
|
||||
@@ -227,7 +221,7 @@ public class MainTest
|
||||
.onChildView(withId(R.id.label))
|
||||
.perform(longClick());
|
||||
|
||||
clickActionModeMenuItem(R.string.edit);
|
||||
clickMenuItem(R.string.edit);
|
||||
|
||||
String modifiedName = "Modified " + new Random().nextInt(10000);
|
||||
typeHabitData(modifiedName, "", "1", "1");
|
||||
@@ -238,7 +232,7 @@ public class MainTest
|
||||
assertHabitExists(modifiedName);
|
||||
|
||||
selectHabit(modifiedName);
|
||||
clickActionModeMenuItem(R.string.color_picker_default_title);
|
||||
clickMenuItem(R.string.color_picker_default_title);
|
||||
pressBack();
|
||||
|
||||
deleteHabit(modifiedName);
|
||||
@@ -272,8 +266,7 @@ public class MainTest
|
||||
@Test
|
||||
public void testSettings()
|
||||
{
|
||||
openActionBarOverflowOrOptionsMenu(targetContext);
|
||||
onView(withText(R.string.settings)).perform(click());
|
||||
clickMenuItem(R.string.settings);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -282,8 +275,7 @@ public class MainTest
|
||||
@Test
|
||||
public void testAbout()
|
||||
{
|
||||
openActionBarOverflowOrOptionsMenu(targetContext);
|
||||
onView(withText(R.string.about)).perform(click());
|
||||
clickMenuItem(R.string.about);
|
||||
onView(isRoot()).perform(swipeUp());
|
||||
}
|
||||
|
||||
@@ -293,8 +285,7 @@ public class MainTest
|
||||
@Test
|
||||
public void testHelp()
|
||||
{
|
||||
openActionBarOverflowOrOptionsMenu(targetContext);
|
||||
onView(withText(R.string.help)).perform(click());
|
||||
clickMenuItem(R.string.help);
|
||||
intended(hasAction(Intent.ACTION_VIEW));
|
||||
}
|
||||
|
||||
@@ -307,8 +298,7 @@ public class MainTest
|
||||
{
|
||||
String name = addHabit();
|
||||
|
||||
openActionBarOverflowOrOptionsMenu(targetContext);
|
||||
onView(withText(R.string.settings)).perform(click());
|
||||
clickMenuItem(R.string.settings);
|
||||
|
||||
String date = DateHelper.getBackupDateFormat().format(DateHelper.getLocalTime());
|
||||
date = date.substring(0, date.length() - 2);
|
||||
@@ -318,8 +308,7 @@ public class MainTest
|
||||
|
||||
deleteHabit(name);
|
||||
|
||||
openActionBarOverflowOrOptionsMenu(targetContext);
|
||||
onView(withText(R.string.settings)).perform(click());
|
||||
clickMenuItem(R.string.settings);
|
||||
onData(isPreferenceWithText("Import data")).perform(click());
|
||||
|
||||
onData(allOf(is(instanceOf(String.class)), startsWith("Backups")))
|
||||
@@ -339,8 +328,7 @@ public class MainTest
|
||||
public void testExportCSV()
|
||||
{
|
||||
addHabit();
|
||||
openActionBarOverflowOrOptionsMenu(targetContext);
|
||||
onView(withText(R.string.settings)).perform(click());
|
||||
clickMenuItem(R.string.settings);
|
||||
onData(isPreferenceWithText("Export as CSV")).perform(click());
|
||||
intended(hasAction(Intent.ACTION_SEND));
|
||||
}
|
||||
@@ -351,8 +339,7 @@ public class MainTest
|
||||
@Test
|
||||
public void testGenerateBugReport()
|
||||
{
|
||||
openActionBarOverflowOrOptionsMenu(targetContext);
|
||||
onView(withText(R.string.settings)).perform(click());
|
||||
clickMenuItem(R.string.settings);
|
||||
onData(isPreferenceWithText("Generate bug report")).perform(click());
|
||||
intended(hasAction(Intent.ACTION_SENDTO));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user