From 11270d91a633f757e2fbf80759991323ba0c91b7 Mon Sep 17 00:00:00 2001 From: orionlee Date: Wed, 4 Sep 2019 16:04:03 -0700 Subject: #3383 Fix skip last episode in queue: android test to reproduce it. --- .../java/de/test/antennapod/ui/PlaybackTest.java | 69 +++++++++++++++++++++- 1 file changed, 67 insertions(+), 2 deletions(-) (limited to 'app/src/androidTest/java/de/test/antennapod') 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 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)); + } + } -- cgit v1.2.3