mirror of
https://github.com/AntennaPod/AntennaPod.git
synced 2024-12-23 07:25:25 +01:00
Fixed tests on small screens
In general, made some tests more stable
This commit is contained in:
parent
f7ae08325b
commit
e51a107083
@ -1,6 +1,7 @@
|
||||
package de.test.antennapod;
|
||||
|
||||
import android.content.Context;
|
||||
import androidx.annotation.IdRes;
|
||||
import androidx.annotation.StringRes;
|
||||
import androidx.test.InstrumentationRegistry;
|
||||
import androidx.test.espresso.PerformException;
|
||||
@ -76,6 +77,31 @@ public class EspressoTestUtils {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform action of waiting for a specific view id.
|
||||
* https://stackoverflow.com/a/30338665/
|
||||
* @param id The id of the child to click.
|
||||
*/
|
||||
public static ViewAction clickChildViewWithId(final @IdRes int id) {
|
||||
return new ViewAction() {
|
||||
@Override
|
||||
public Matcher<View> getConstraints() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Click on a child view with specified id.";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void perform(UiController uiController, View view) {
|
||||
View v = view.findViewById(id);
|
||||
v.performClick();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear all app databases
|
||||
*/
|
||||
@ -127,11 +153,6 @@ public class EspressoTestUtils {
|
||||
onView(withId(R.id.drawer_layout)).perform(DrawerActions.open());
|
||||
}
|
||||
|
||||
public static void closeNavDrawer() {
|
||||
onView(isRoot()).perform(waitForView(withId(R.id.drawer_layout), 1000));
|
||||
onView(withId(R.id.drawer_layout)).perform(DrawerActions.close());
|
||||
}
|
||||
|
||||
public static ViewInteraction onDrawerItem(Matcher<View> viewMatcher) {
|
||||
return onView(allOf(viewMatcher, withId(R.id.txtvTitle)));
|
||||
}
|
||||
|
@ -11,10 +11,6 @@ public class NthMatcher {
|
||||
return nth(matcher, 1);
|
||||
}
|
||||
|
||||
public static <T> Matcher<T> second(final Matcher<T> matcher) {
|
||||
return nth(matcher, 2);
|
||||
}
|
||||
|
||||
public static <T> Matcher<T> nth(final Matcher<T> matcher, final int index) {
|
||||
return new BaseMatcher<T>() {
|
||||
AtomicInteger count = new AtomicInteger(0);
|
||||
@ -31,7 +27,8 @@ public class NthMatcher {
|
||||
|
||||
@Override
|
||||
public void describeTo(final Description description) {
|
||||
description.appendText("should return first matching item");
|
||||
description.appendText("Item #" + index + " ");
|
||||
description.appendDescriptionOf(matcher);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -27,18 +27,18 @@ import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static androidx.test.espresso.Espresso.onView;
|
||||
import static androidx.test.espresso.action.ViewActions.click;
|
||||
import static androidx.test.espresso.contrib.RecyclerViewActions.actionOnItemAtPosition;
|
||||
import static androidx.test.espresso.matcher.ViewMatchers.isRoot;
|
||||
import static androidx.test.espresso.matcher.ViewMatchers.withId;
|
||||
import static androidx.test.espresso.matcher.ViewMatchers.withText;
|
||||
import static de.test.antennapod.EspressoTestUtils.clickChildViewWithId;
|
||||
import static de.test.antennapod.EspressoTestUtils.onDrawerItem;
|
||||
import static de.test.antennapod.EspressoTestUtils.openNavDrawer;
|
||||
import static de.test.antennapod.EspressoTestUtils.waitForView;
|
||||
import static de.test.antennapod.NthMatcher.first;
|
||||
import static de.test.antennapod.NthMatcher.nth;
|
||||
import static java.util.concurrent.TimeUnit.MILLISECONDS;
|
||||
import static org.hamcrest.Matchers.hasItems;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
@ -78,23 +78,9 @@ public abstract class PlaybackTest {
|
||||
setContinuousPlaybackPreference(false);
|
||||
uiTestUtils.addLocalFeedData(true);
|
||||
activityTestRule.launchActivity(new Intent());
|
||||
List<FeedItem> queue = DBReader.getQueue();
|
||||
final FeedItem first = queue.get(0);
|
||||
playFromQueue(0);
|
||||
Awaitility.await().atMost(5, TimeUnit.SECONDS).until(() -> {
|
||||
if (uiTestUtils.getPlaybackController(getActivity()).getStatus()
|
||||
!= PlayerStatus.PLAYING) {
|
||||
return true;
|
||||
} else if (uiTestUtils.getCurrentMedia(getActivity()) != null) {
|
||||
return uiTestUtils.getCurrentMedia(getActivity()).getId()
|
||||
!= first.getMedia().getId();
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
Thread.sleep(1000);
|
||||
assertNotEquals(PlayerStatus.PLAYING, uiTestUtils.getPlaybackController(getActivity()).getStatus());
|
||||
Awaitility.await().atMost(5, TimeUnit.SECONDS).until(
|
||||
() -> uiTestUtils.getPlaybackController(getActivity()).getStatus() == PlayerStatus.INITIALIZED);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -225,7 +211,7 @@ public abstract class PlaybackTest {
|
||||
protected void startLocalPlayback() {
|
||||
openNavDrawer();
|
||||
onDrawerItem(withText(R.string.episodes_label)).perform(click());
|
||||
onView(isRoot()).perform(waitForView(withId(R.id.emptyViewTitle), 1000));
|
||||
onView(isRoot()).perform(waitForView(withText(R.string.all_episodes_short_label), 1000));
|
||||
onView(withText(R.string.all_episodes_short_label)).perform(click());
|
||||
|
||||
final List<FeedItem> episodes = DBReader.getRecentlyPublishedEpisodes(0, 10);
|
||||
@ -249,7 +235,9 @@ public abstract class PlaybackTest {
|
||||
protected void playFromQueue(int itemIdx) {
|
||||
final List<FeedItem> queue = DBReader.getQueue();
|
||||
|
||||
onView(nth(withId(R.id.butSecondaryAction), itemIdx + 1)).perform(click());
|
||||
onView(withId(R.id.recyclerView)).perform(
|
||||
actionOnItemAtPosition(itemIdx, clickChildViewWithId(R.id.butSecondaryAction)));
|
||||
|
||||
onView(isRoot()).perform(waitForView(withId(R.id.butPlay), 1000));
|
||||
long mediaId = queue.get(itemIdx).getMedia().getId();
|
||||
Awaitility.await().atMost(1, TimeUnit.SECONDS).until(() -> {
|
||||
|
@ -5,6 +5,7 @@ import androidx.annotation.Nullable;
|
||||
import androidx.test.InstrumentationRegistry;
|
||||
import androidx.test.runner.AndroidJUnit4;
|
||||
|
||||
import de.test.antennapod.EspressoTestUtils;
|
||||
import org.awaitility.Awaitility;
|
||||
import org.awaitility.core.ConditionTimeoutException;
|
||||
import org.junit.After;
|
||||
@ -53,6 +54,8 @@ public class DownloadServiceTest {
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
EspressoTestUtils.clearDatabase();
|
||||
EspressoTestUtils.clearPreferences();
|
||||
origFactory = DownloadService.getDownloaderFactory();
|
||||
testFeed = setUpTestFeeds();
|
||||
testMedia11 = testFeed.getItemAtIndex(0).getMedia();
|
||||
@ -171,7 +174,7 @@ public class DownloadServiceTest {
|
||||
final int totalNumEventsExpected = itemAlreadyInQueue ? 1 : 3;
|
||||
Awaitility.await("item dequeue event + download termination event")
|
||||
.atMost(1000, TimeUnit.MILLISECONDS)
|
||||
.until(() ->feedItemEventListener.getEvents().size() >= totalNumEventsExpected);
|
||||
.until(() -> feedItemEventListener.getEvents().size() >= totalNumEventsExpected);
|
||||
assertFalse("The download should have been canceled",
|
||||
DBReader.getFeedMedia(testMedia11.getId()).isDownloaded());
|
||||
if (itemAlreadyInQueue) {
|
||||
|
@ -7,6 +7,7 @@ import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import de.test.antennapod.EspressoTestUtils;
|
||||
import org.awaitility.Awaitility;
|
||||
import org.awaitility.core.ConditionTimeoutException;
|
||||
import org.junit.After;
|
||||
@ -49,12 +50,8 @@ public class AutoDownloadTest {
|
||||
|
||||
dbTasksCallbacksOrig = ClientConfig.dbTasksCallbacks;
|
||||
|
||||
// create new database
|
||||
PodDBAdapter.init(context);
|
||||
PodDBAdapter.deleteDatabase();
|
||||
PodDBAdapter adapter = PodDBAdapter.getInstance();
|
||||
adapter.open();
|
||||
adapter.close();
|
||||
EspressoTestUtils.clearPreferences();
|
||||
EspressoTestUtils.clearDatabase();
|
||||
}
|
||||
|
||||
@After
|
||||
@ -126,7 +123,7 @@ public class AutoDownloadTest {
|
||||
if (playable == null) {
|
||||
return null;
|
||||
}
|
||||
return ((FeedMedia)playable).getItem();
|
||||
return ((FeedMedia) playable).getItem();
|
||||
}
|
||||
|
||||
private void useDownloadAlgorithm(final AutomaticDownloadAlgorithm downloadAlgorithm) {
|
||||
|
@ -75,8 +75,8 @@ public class MainActivityTest {
|
||||
final Feed feed = uiTestUtils.hostedFeeds.get(0);
|
||||
openNavDrawer();
|
||||
onView(withText(R.string.add_feed_label)).perform(click());
|
||||
onView(withId(R.id.etxtFeedurl)).perform(typeText(feed.getDownload_url()));
|
||||
onView(withText(R.string.confirm_label)).perform(scrollTo()).perform(click());
|
||||
onView(withId(R.id.etxtFeedurl)).perform(scrollTo(), typeText(feed.getDownload_url()));
|
||||
onView(withText(R.string.confirm_label)).perform(scrollTo(), click());
|
||||
Espresso.closeSoftKeyboard();
|
||||
onView(withText(R.string.subscribe_label)).perform(click());
|
||||
intended(hasComponent(MainActivity.class.getName()), times(2));
|
||||
|
@ -32,6 +32,7 @@ import static androidx.test.espresso.Espresso.onView;
|
||||
import static androidx.test.espresso.action.ViewActions.click;
|
||||
import static androidx.test.espresso.action.ViewActions.replaceText;
|
||||
import static androidx.test.espresso.action.ViewActions.scrollTo;
|
||||
import static androidx.test.espresso.action.ViewActions.swipeDown;
|
||||
import static androidx.test.espresso.action.ViewActions.swipeUp;
|
||||
import static androidx.test.espresso.assertion.ViewAssertions.doesNotExist;
|
||||
import static androidx.test.espresso.assertion.ViewAssertions.matches;
|
||||
@ -246,10 +247,10 @@ public class PreferencesTest {
|
||||
public void testPauseForInterruptions() {
|
||||
onView(withText(R.string.playback_pref)).perform(click());
|
||||
final boolean pauseForFocusLoss = UserPreferences.shouldPauseForFocusLoss();
|
||||
onView(withText(R.string.pref_pausePlaybackForFocusLoss_title)).perform(click());
|
||||
clickPreference(R.string.pref_pausePlaybackForFocusLoss_title);
|
||||
Awaitility.await().atMost(1000, MILLISECONDS)
|
||||
.until(() -> pauseForFocusLoss != UserPreferences.shouldPauseForFocusLoss());
|
||||
onView(withText(R.string.pref_pausePlaybackForFocusLoss_title)).perform(click());
|
||||
clickPreference(R.string.pref_pausePlaybackForFocusLoss_title);
|
||||
Awaitility.await().atMost(1000, MILLISECONDS)
|
||||
.until(() -> pauseForFocusLoss == UserPreferences.shouldPauseForFocusLoss());
|
||||
}
|
||||
@ -332,7 +333,8 @@ public class PreferencesTest {
|
||||
clickPreference(R.string.network_pref);
|
||||
clickPreference(R.string.pref_automatic_download_title);
|
||||
clickPreference(R.string.pref_episode_cache_title);
|
||||
onView(withText(minEntry)).perform(scrollTo()).perform(click());
|
||||
onView(withId(R.id.select_dialog_listview)).perform(swipeDown());
|
||||
onView(withText(minEntry)).perform(click());
|
||||
Awaitility.await().atMost(1000, MILLISECONDS)
|
||||
.until(() -> UserPreferences.getEpisodeCacheSize() == minValue);
|
||||
}
|
||||
@ -346,6 +348,7 @@ public class PreferencesTest {
|
||||
onView(withText(R.string.network_pref)).perform(click());
|
||||
onView(withText(R.string.pref_automatic_download_title)).perform(click());
|
||||
onView(withText(R.string.pref_episode_cache_title)).perform(click());
|
||||
onView(withId(R.id.select_dialog_listview)).perform(swipeUp());
|
||||
onView(withText(maxEntry)).perform(click());
|
||||
Awaitility.await().atMost(1000, MILLISECONDS)
|
||||
.until(() -> UserPreferences.getEpisodeCacheSize() == maxValue);
|
||||
@ -365,17 +368,17 @@ public class PreferencesTest {
|
||||
Awaitility.await().atMost(1000, MILLISECONDS)
|
||||
.until(UserPreferences::isEnableAutodownload);
|
||||
final boolean enableAutodownloadOnBattery = UserPreferences.isEnableAutodownloadOnBattery();
|
||||
onView(withText(R.string.pref_automatic_download_on_battery_title)).perform(click());
|
||||
clickPreference(R.string.pref_automatic_download_on_battery_title);
|
||||
Awaitility.await().atMost(1000, MILLISECONDS)
|
||||
.until(() -> enableAutodownloadOnBattery != UserPreferences.isEnableAutodownloadOnBattery());
|
||||
onView(withText(R.string.pref_automatic_download_on_battery_title)).perform(click());
|
||||
clickPreference(R.string.pref_automatic_download_on_battery_title);
|
||||
Awaitility.await().atMost(1000, MILLISECONDS)
|
||||
.until(() -> enableAutodownloadOnBattery == UserPreferences.isEnableAutodownloadOnBattery());
|
||||
final boolean enableWifiFilter = UserPreferences.isEnableAutodownloadWifiFilter();
|
||||
onView(withText(R.string.pref_autodl_wifi_filter_title)).perform(click());
|
||||
clickPreference(R.string.pref_autodl_wifi_filter_title);
|
||||
Awaitility.await().atMost(1000, MILLISECONDS)
|
||||
.until(() -> enableWifiFilter != UserPreferences.isEnableAutodownloadWifiFilter());
|
||||
onView(withText(R.string.pref_autodl_wifi_filter_title)).perform(click());
|
||||
clickPreference(R.string.pref_autodl_wifi_filter_title);
|
||||
Awaitility.await().atMost(1000, MILLISECONDS)
|
||||
.until(() -> enableWifiFilter == UserPreferences.isEnableAutodownloadWifiFilter());
|
||||
}
|
||||
@ -425,7 +428,7 @@ public class PreferencesTest {
|
||||
clickPreference(R.string.network_pref);
|
||||
clickPreference(R.string.pref_automatic_download_title);
|
||||
clickPreference(R.string.pref_episode_cleanup_title);
|
||||
String search = res.getQuantityString(R.plurals.episode_cleanup_days_after_listening, 5, 5);
|
||||
String search = res.getQuantityString(R.plurals.episode_cleanup_days_after_listening, 3, 3);
|
||||
onView(isRoot()).perform(waitForView(withText(search), 1000));
|
||||
onView(withText(search)).perform(click());
|
||||
Awaitility.await().atMost(1000, MILLISECONDS)
|
||||
@ -433,7 +436,7 @@ public class PreferencesTest {
|
||||
EpisodeCleanupAlgorithm alg = UserPreferences.getEpisodeCleanupAlgorithm();
|
||||
if (alg instanceof APCleanupAlgorithm) {
|
||||
APCleanupAlgorithm cleanupAlg = (APCleanupAlgorithm) alg;
|
||||
return cleanupAlg.getNumberOfHoursAfterPlayback() == 120; // 5 days
|
||||
return cleanupAlg.getNumberOfHoursAfterPlayback() == 72; // 5 days
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user