summaryrefslogtreecommitdiff
path: root/app/src/androidTest/java/de/test/antennapod
diff options
context:
space:
mode:
authororionlee <orionlee@yahoo.com>2019-09-04 16:04:03 -0700
committerorionlee <orionlee@yahoo.com>2019-09-28 15:50:11 -0700
commit11270d91a633f757e2fbf80759991323ba0c91b7 (patch)
tree399356d57a21b23fbe3af7c779b5b1fa9f5dc01c /app/src/androidTest/java/de/test/antennapod
parent3e01d66cbdd14f141a4e75799731d0dc0de33b81 (diff)
downloadAntennaPod-11270d91a633f757e2fbf80759991323ba0c91b7.zip
#3383 Fix skip last episode in queue: android test to reproduce it.
Diffstat (limited to 'app/src/androidTest/java/de/test/antennapod')
-rw-r--r--app/src/androidTest/java/de/test/antennapod/ui/PlaybackTest.java69
1 files changed, 67 insertions, 2 deletions
diff --git a/app/src/androidTest/java/de/test/antennapod/ui/PlaybackTest.java b/app/src/androidTest/java/de/test/antennapod/ui/PlaybackTest.java
index b302bcc91..34a7fc382 100644
--- a/app/src/androidTest/java/de/test/antennapod/ui/PlaybackTest.java
+++ b/app/src/androidTest/java/de/test/antennapod/ui/PlaybackTest.java
@@ -29,7 +29,11 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
+import static org.hamcrest.Matchers.hasItems;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.not;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
/**
@@ -96,6 +100,18 @@ public class PlaybackTest {
prefs.edit().putBoolean(UserPreferences.PREF_FOLLOW_QUEUE, value).commit();
}
+ private void setSkipKeepsEpisodePreference(boolean value) {
+ SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
+ prefs.edit().putBoolean(UserPreferences.PREF_SKIP_KEEPS_EPISODE, value).commit();
+ }
+
+ private void setSmartMarkAsPlayedPreference(int smartMarkAsPlayedSecs) {
+ SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
+ prefs.edit().putString(UserPreferences.PREF_SMART_MARK_AS_PLAYED_SECS,
+ Integer.toString(smartMarkAsPlayedSecs, 10))
+ .commit();
+ }
+
private void skipEpisode() {
Intent skipIntent = new Intent(PlaybackService.ACTION_SKIP_CURRENT_EPISODE);
context.sendBroadcast(skipIntent);
@@ -130,6 +146,11 @@ public class PlaybackTest {
}
private void startLocalPlaybackFromQueue() {
+ gotoQueueScreen();
+ playFromQueue(0);
+ }
+
+ private void gotoQueueScreen() {
openNavDrawer();
// if we try to just click on plain old text then
// we might wind up clicking on the fragment title and not
@@ -140,11 +161,17 @@ public class PlaybackTest {
solo.waitForView(targetView);
solo.clickOnView(targetView);
assertTrue(solo.waitForView(solo.getView(R.id.butSecondaryAction)));
+ }
+ /**
+ *
+ * @param itemIdx The 0-based index of the episode to be played in the queue.
+ */
+ private void playFromQueue(int itemIdx) {
final List<FeedItem> queue = DBReader.getQueue();
- solo.clickOnImageButton(1);
+ solo.clickOnImageButton(itemIdx + 1);
assertTrue(solo.waitForView(solo.getView(R.id.butPlay)));
- long mediaId = queue.get(0).getMedia().getId();
+ long mediaId = queue.get(itemIdx).getMedia().getId();
boolean playing = solo.waitForCondition(() -> {
if(uiTestUtils.getCurrentMedia(getActivity()) != null) {
return uiTestUtils.getCurrentMedia(getActivity()).getId() == mediaId;
@@ -269,4 +296,42 @@ public class PlaybackTest {
public void testReplayEpisodeContinuousPlaybackOff() throws Exception {
replayEpisodeCheck(false);
}
+
+ @Test
+ public void testSmartMarkAsPlayed_Skip_Average() throws Exception {
+ doTestSmartMarkAsPlayed_Skip_ForEpisode(0);
+ }
+
+ @Test
+ public void testSmartMarkAsPlayed_Skip_LastEpisodeInQueue() throws Exception {
+ // TODO: The test fails for now: doTestSmartMarkAsPlayed_Skip_ForEpisode(-1);
+ }
+
+ private void doTestSmartMarkAsPlayed_Skip_ForEpisode(int itemIdxNegAllowed) throws Exception {
+ setSmartMarkAsPlayedPreference(60);
+ // ensure when an episode is skipped, it is removed due to smart as played
+ setSkipKeepsEpisodePreference(false);
+
+ uiTestUtils.addLocalFeedData(true);
+
+ int fiIdx;
+ if (itemIdxNegAllowed >= 0) {
+ fiIdx = itemIdxNegAllowed;
+ } else { // negative index: count from the end, with -1 being the last one, etc.
+ fiIdx = DBReader.getQueue().size() + itemIdxNegAllowed;
+ }
+ final FeedItem feedItem = DBReader.getQueue().get(fiIdx);
+
+ gotoQueueScreen();
+ playFromQueue(fiIdx);
+
+ skipEpisode();
+ Thread.sleep(1000); // ensure the skip is processed
+
+ // assert item no longer in queue
+ assertThat("Ensure smart mark as play will lead to the item removed from the queue",
+ DBReader.getQueue(), not(hasItems(feedItem)));
+ assertThat(DBReader.getFeedItem(feedItem.getId()).isPlayed(), is(true));
+ }
+
}