diff --git a/app/src/androidTest/java/de/test/antennapod/EspressoTestUtils.java b/app/src/androidTest/java/de/test/antennapod/EspressoTestUtils.java index 02ee9a487..9e86275fc 100644 --- a/app/src/androidTest/java/de/test/antennapod/EspressoTestUtils.java +++ b/app/src/androidTest/java/de/test/antennapod/EspressoTestUtils.java @@ -1,6 +1,7 @@ package de.test.antennapod; import android.content.Context; +import android.content.SharedPreferences; import android.support.annotation.StringRes; import android.support.test.InstrumentationRegistry; import android.support.test.espresso.PerformException; @@ -15,6 +16,7 @@ import de.danoeh.antennapod.R; import de.danoeh.antennapod.activity.MainActivity; import de.danoeh.antennapod.core.storage.PodDBAdapter; import de.danoeh.antennapod.dialog.RatingDialog; +import de.danoeh.antennapod.fragment.QueueFragment; import org.hamcrest.Matcher; import java.io.File; @@ -97,6 +99,13 @@ public class EspressoTestUtils { RatingDialog.saveRated(); } + public static void setLastNavFragment(String tag) { + InstrumentationRegistry.getTargetContext().getSharedPreferences(MainActivity.PREF_NAME, Context.MODE_PRIVATE) + .edit() + .putString(MainActivity.PREF_LAST_FRAGMENT_TAG, tag) + .commit(); + } + public static void clearDatabase() { PodDBAdapter.init(InstrumentationRegistry.getTargetContext()); PodDBAdapter.deleteDatabase(); diff --git a/app/src/androidTest/java/de/test/antennapod/ui/QueueFragmentTest.java b/app/src/androidTest/java/de/test/antennapod/ui/QueueFragmentTest.java new file mode 100644 index 000000000..d1023dd9e --- /dev/null +++ b/app/src/androidTest/java/de/test/antennapod/ui/QueueFragmentTest.java @@ -0,0 +1,58 @@ +package de.test.antennapod.ui; + +import android.content.Intent; +import android.support.test.espresso.Espresso; +import android.support.test.espresso.intent.rule.IntentsTestRule; +import android.support.test.runner.AndroidJUnit4; +import de.danoeh.antennapod.R; +import de.danoeh.antennapod.activity.MainActivity; +import de.danoeh.antennapod.fragment.QueueFragment; +import de.test.antennapod.EspressoTestUtils; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; + +import static android.support.test.espresso.Espresso.onView; +import static android.support.test.espresso.action.ViewActions.click; +import static android.support.test.espresso.matcher.ViewMatchers.withContentDescription; +import static android.support.test.espresso.matcher.ViewMatchers.withText; + +/** + * User interface tests for queue fragment + */ +@RunWith(AndroidJUnit4.class) +public class QueueFragmentTest { + + @Rule + public IntentsTestRule mActivityRule = new IntentsTestRule<>(MainActivity.class, false, false); + + @Before + public void setUp() { + EspressoTestUtils.clearPreferences(); + EspressoTestUtils.makeNotFirstRun(); + EspressoTestUtils.clearDatabase(); + EspressoTestUtils.setLastNavFragment(QueueFragment.TAG); + mActivityRule.launchActivity(new Intent()); + } + + @Test + public void testLockEmptyQueue() { + onView(withContentDescription(R.string.lock_queue)).perform(click()); + onView(withContentDescription(R.string.unlock_queue)).perform(click()); + } + + @Test + public void testSortEmptyQueue() { + Espresso.openContextualActionModeOverflowMenu(); + onView(withText(R.string.sort)).perform(click()); + onView(withText(R.string.random)).perform(click()); + } + + @Test + public void testKeepEmptyQueueSorted() { + Espresso.openContextualActionModeOverflowMenu(); + onView(withText(R.string.sort)).perform(click()); + onView(withText(R.string.keep_sorted)).perform(click()); + } +} diff --git a/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java index ab4f584fe..339ce01c2 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java @@ -87,7 +87,7 @@ public class MainActivity extends CastEnabledActivity implements NavDrawerActivi public static final String PREF_NAME = "MainActivityPrefs"; public static final String PREF_IS_FIRST_LAUNCH = "prefMainActivityIsFirstLaunch"; - private static final String PREF_LAST_FRAGMENT_TAG = "prefMainActivityLastFragmentTag"; + public static final String PREF_LAST_FRAGMENT_TAG = "prefMainActivityLastFragmentTag"; public static final String EXTRA_NAV_TYPE = "nav_type"; public static final String EXTRA_NAV_INDEX = "nav_index"; diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java index 4f07e1b59..9763f8f2d 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java @@ -378,8 +378,10 @@ public class QueueFragment extends Fragment { if (keepSortedNew) { SortOrder sortOrder = UserPreferences.getQueueKeepSortedOrder(); QueueSorter.sort(sortOrder, true); - recyclerAdapter.setLocked(true); - } else { + if (recyclerAdapter != null) { + recyclerAdapter.setLocked(true); + } + } else if (recyclerAdapter != null) { recyclerAdapter.setLocked(UserPreferences.isQueueLocked()); } getActivity().invalidateOptionsMenu();