#3383 Fix skip last episode in queue: android test to reproduce it.

This commit is contained in:
orionlee 2019-09-04 16:04:03 -07:00
parent 3e01d66cbd
commit 11270d91a6
2 changed files with 68 additions and 3 deletions

View File

@ -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));
}
}

View File

@ -71,7 +71,7 @@ public class UserPreferences {
private static final String PREF_HARDWARE_FOWARD_BUTTON_SKIPS = "prefHardwareForwardButtonSkips";
private static final String PREF_HARDWARE_PREVIOUS_BUTTON_RESTARTS = "prefHardwarePreviousButtonRestarts";
public static final String PREF_FOLLOW_QUEUE = "prefFollowQueue";
private static final String PREF_SKIP_KEEPS_EPISODE = "prefSkipKeepsEpisode";
public static final String PREF_SKIP_KEEPS_EPISODE = "prefSkipKeepsEpisode";
private static final String PREF_FAVORITE_KEEPS_EPISODE = "prefFavoriteKeepsEpisode";
private static final String PREF_AUTO_DELETE = "prefAutoDelete";
public static final String PREF_SMART_MARK_AS_PLAYED_SECS = "prefSmartMarkAsPlayedSecs";