Enable bottom navigation for users who never touched the setting (#8158)

* Enable bottom navigation for users who never opened the settings

* Make tests more independent of navigation setting
This commit is contained in:
Hans-Peter Lehmann
2025-12-14 16:26:21 +01:00
committed by GitHub
parent fb6979a8a3
commit 8dfb0c2a8e
9 changed files with 30 additions and 55 deletions

View File

@ -11,8 +11,6 @@ import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.espresso.PerformException;
import androidx.test.espresso.UiController;
import androidx.test.espresso.ViewAction;
import androidx.test.espresso.ViewInteraction;
import androidx.test.espresso.contrib.DrawerActions;
import androidx.test.espresso.contrib.RecyclerViewActions;
import androidx.test.espresso.util.HumanReadables;
import androidx.test.espresso.util.TreeIterables;
@ -39,6 +37,7 @@ import static androidx.test.espresso.action.ViewActions.click;
import static androidx.test.espresso.assertion.ViewAssertions.doesNotExist;
import static androidx.test.espresso.assertion.ViewAssertions.matches;
import static androidx.test.espresso.matcher.ViewMatchers.hasDescendant;
import static androidx.test.espresso.matcher.ViewMatchers.isDescendantOfA;
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
import static androidx.test.espresso.matcher.ViewMatchers.isRoot;
import static androidx.test.espresso.matcher.ViewMatchers.withContentDescription;
@ -218,13 +217,15 @@ public class EspressoTestUtils {
click()));
}
public static void openNavDrawer() {
onView(isRoot()).perform(waitForView(withId(R.id.drawer_layout), 1000));
onView(withId(R.id.drawer_layout)).perform(DrawerActions.open());
public static void clickBottomNavItem(@StringRes int text) {
onView(allOf(withText(text),
isDescendantOfA(withId(R.id.bottomNavigationView)), isDisplayed())).perform(click());
}
public static ViewInteraction onDrawerItem(Matcher<View> viewMatcher) {
return onView(allOf(viewMatcher, withId(R.id.txtvTitle)));
public static void clickBottomNavOverflow(@StringRes int text) {
onView(allOf(withText(R.string.overflow_more),
isDescendantOfA(withId(R.id.bottomNavigationView)), isDisplayed())).perform(click());
onView(allOf(withText(text), isDisplayed())).perform(click());
}
public static void tryKillPlaybackService() {

View File

@ -26,8 +26,6 @@ import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
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.onDrawerItem;
import static de.test.antennapod.EspressoTestUtils.openNavDrawer;
import static de.test.antennapod.EspressoTestUtils.waitForView;
import static de.test.antennapod.NthMatcher.first;
import static org.hamcrest.CoreMatchers.allOf;
@ -55,9 +53,6 @@ public class ShareDialogTest {
activityRule.launchActivity(new Intent());
openNavDrawer();
onDrawerItem(withText(R.string.episodes_label)).perform(click());
Matcher<View> allEpisodesMatcher;
allEpisodesMatcher = Matchers.allOf(withId(R.id.recyclerView), isDisplayed(), hasMinimumChildCount(2));
onView(isRoot()).perform(waitForView(allEpisodesMatcher, 1000));

View File

@ -37,16 +37,13 @@ import java.util.List;
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.hasMinimumChildCount;
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
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.clickBottomNavOverflow;
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 java.util.concurrent.TimeUnit.MILLISECONDS;
import static org.hamcrest.Matchers.allOf;
@ -232,8 +229,7 @@ public class PlaybackTest {
}
protected void startLocalPlayback() {
openNavDrawer();
onDrawerItem(withText(R.string.episodes_label)).perform(click());
clickBottomNavOverflow(R.string.episodes_label);
final List<FeedItem> episodes = DBReader.getEpisodes(0, 10,
FeedItemFilter.unfiltered(), SortOrder.DATE_NEW_OLD);

View File

@ -9,6 +9,7 @@ import de.danoeh.antennapod.R;
import de.danoeh.antennapod.activity.MainActivity;
import de.danoeh.antennapod.model.feed.Feed;
import de.danoeh.antennapod.storage.database.PodDBAdapter;
import de.danoeh.antennapod.ui.screen.AddFeedFragment;
import de.test.antennapod.EspressoTestUtils;
import org.junit.After;
import org.junit.Before;
@ -24,14 +25,10 @@ import static androidx.test.espresso.action.ViewActions.replaceText;
import static androidx.test.espresso.action.ViewActions.scrollTo;
import static androidx.test.espresso.matcher.ViewMatchers.withId;
import static androidx.test.espresso.matcher.ViewMatchers.withText;
import static de.test.antennapod.EspressoTestUtils.openNavDrawer;
import static de.test.antennapod.EspressoTestUtils.waitForViewGlobally;
/**
* User interface tests for MainActivity.
*/
@RunWith(AndroidJUnit4.class)
public class MainActivityTest {
public class AddFeedFragmentTest {
private UITestUtils uiTestUtils;
@ -42,6 +39,7 @@ public class MainActivityTest {
public void setUp() throws IOException {
EspressoTestUtils.clearPreferences();
EspressoTestUtils.clearDatabase();
EspressoTestUtils.setLaunchScreen(AddFeedFragment.TAG);
activityRule.launchActivity(new Intent());
@ -56,12 +54,10 @@ public class MainActivityTest {
}
@Test
public void testAddFeed() throws Exception {
public void testAddFeedByUrl() throws Exception {
// connect to podcast feed
uiTestUtils.addHostedFeedData();
final Feed feed = uiTestUtils.hostedFeeds.get(0);
openNavDrawer();
onView(withText(R.string.add_feed_label)).perform(click());
onView(withId(R.id.addViaUrlButton)).perform(scrollTo(), click());
onView(withId(R.id.textInput)).perform(replaceText(feed.getDownloadUrl()));
onView(withText(R.string.confirm_label)).perform(scrollTo(), click());

View File

@ -2,7 +2,6 @@ package de.test.antennapod.ui;
import android.content.Intent;
import android.os.Build;
import androidx.annotation.StringRes;
import androidx.test.espresso.intent.rule.IntentsTestRule;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.platform.app.InstrumentationRegistry;
@ -20,12 +19,12 @@ import java.io.IOException;
import java.util.Collections;
import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.action.ViewActions.click;
import static androidx.test.espresso.matcher.ViewMatchers.isDescendantOfA;
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
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.clickBottomNavItem;
import static de.test.antennapod.EspressoTestUtils.clickBottomNavOverflow;
import static de.test.antennapod.EspressoTestUtils.waitForView;
import static org.hamcrest.Matchers.allOf;
import static org.junit.Assume.assumeTrue;
@ -56,17 +55,6 @@ public class BottomNavigationTest {
uiTestUtils.tearDown();
}
void clickBottomNavItem(@StringRes int text) {
onView(allOf(withText(text),
isDescendantOfA(withId(R.id.bottomNavigationView)), isDisplayed())).perform(click());
}
void clickBottomNavOverview(@StringRes int text) {
onView(allOf(withText(R.string.overflow_more),
isDescendantOfA(withId(R.id.bottomNavigationView)), isDisplayed())).perform(click());
onView(allOf(withText(text), isDisplayed())).perform(click());
}
@Test
public void testClickBottomNavigation() throws Exception {
assumeTrue(Build.VERSION.SDK_INT >= 30); // Unclear why this crashes on old Android versions
@ -90,19 +78,19 @@ public class BottomNavigationTest {
onView(isRoot()).perform(waitForView(allOf(isDescendantOfA(withId(R.id.toolbar)),
withText(R.string.subscriptions_label)), 1000));
clickBottomNavOverview(R.string.episodes_label);
clickBottomNavOverflow(R.string.episodes_label);
onView(isRoot()).perform(waitForView(allOf(isDescendantOfA(withId(R.id.toolbar)),
withText(R.string.episodes_label)), 1000));
clickBottomNavOverview(R.string.downloads_label);
clickBottomNavOverflow(R.string.downloads_label);
onView(isRoot()).perform(waitForView(allOf(isDescendantOfA(withId(R.id.toolbar)),
withText(R.string.downloads_label)), 1000));
clickBottomNavOverview(R.string.playback_history_label);
clickBottomNavOverflow(R.string.playback_history_label);
onView(isRoot()).perform(waitForView(allOf(isDescendantOfA(withId(R.id.toolbar)),
withText(R.string.playback_history_label)), 1000));
clickBottomNavOverview(R.string.add_feed_label);
clickBottomNavOverflow(R.string.add_feed_label);
onView(isRoot()).perform(waitForView(allOf(isDescendantOfA(withId(R.id.toolbar)),
withText(R.string.add_feed_label)), 1000));
}

View File

@ -2,6 +2,8 @@ package de.test.antennapod.ui;
import android.content.Intent;
import android.os.Build;
import android.view.View;
import androidx.test.espresso.ViewInteraction;
import androidx.test.espresso.contrib.DrawerActions;
import androidx.test.espresso.intent.rule.IntentsTestRule;
import androidx.test.ext.junit.runners.AndroidJUnit4;
@ -12,6 +14,7 @@ import de.danoeh.antennapod.model.feed.Feed;
import de.danoeh.antennapod.storage.preferences.UserPreferences;
import de.danoeh.antennapod.ui.screen.preferences.PreferenceActivity;
import de.test.antennapod.EspressoTestUtils;
import org.hamcrest.Matcher;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
@ -31,7 +34,6 @@ import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
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.onDrawerItem;
import static de.test.antennapod.EspressoTestUtils.waitForView;
import static org.hamcrest.Matchers.allOf;
import static org.junit.Assume.assumeTrue;
@ -67,6 +69,10 @@ public class NavigationDrawerTest {
onView(withId(R.id.drawer_layout)).perform(DrawerActions.open());
}
private ViewInteraction onDrawerItem(Matcher<View> viewMatcher) {
return onView(allOf(viewMatcher, withId(R.id.txtvTitle)));
}
@Test
public void testClickNavDrawer() throws Exception {
uiTestUtils.addLocalFeedData(false);

View File

@ -18,13 +18,9 @@ import java.io.IOException;
import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.action.ViewActions.click;
import static androidx.test.espresso.action.ViewActions.swipeUp;
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
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.onDrawerItem;
import static de.test.antennapod.EspressoTestUtils.openNavDrawer;
import static de.test.antennapod.EspressoTestUtils.waitForView;
import static org.hamcrest.CoreMatchers.allOf;
@ -48,7 +44,6 @@ public class TextOnlyFeedsTest {
uiTestUtils.setHostTextOnlyFeeds(true);
uiTestUtils.setup();
activityRule.launchActivity(new Intent());
}
@After
@ -60,9 +55,8 @@ public class TextOnlyFeedsTest {
public void testMarkAsPlayedList() throws Exception {
uiTestUtils.addLocalFeedData(false);
final Feed feed = uiTestUtils.hostedFeeds.get(0);
openNavDrawer();
onView(withId(R.id.nav_list)).perform(swipeUp());
onDrawerItem(withText(feed.getTitle())).perform(click());
EspressoTestUtils.setLaunchScreen("" + feed.getId());
activityRule.launchActivity(new Intent());
onView(withText(feed.getItemAtIndex(0).getTitle())).perform(click());
onView(isRoot()).perform(waitForView(withText(R.string.mark_read_no_media_label), 3000));
onView(allOf(withText(R.string.mark_read_no_media_label), isDisplayed())).perform(click());

View File

@ -348,7 +348,6 @@ public class MainActivity extends CastEnabledActivity {
SharedPreferences prefs = getSharedPreferences(PREF_NAME, MODE_PRIVATE);
if (prefs.getBoolean(PREF_IS_FIRST_LAUNCH, true)) {
FeedUpdateManager.getInstance().restartUpdateAlarm(this, true);
UserPreferences.setBottomNavigationEnabled(true);
SharedPreferences.Editor edit = prefs.edit();
edit.putBoolean(PREF_IS_FIRST_LAUNCH, false);

View File

@ -757,7 +757,7 @@ public abstract class UserPreferences {
}
public static boolean isBottomNavigationEnabled() {
return prefs.getBoolean(PREF_BOTTOM_NAVIGATION, false);
return prefs.getBoolean(PREF_BOTTOM_NAVIGATION, true);
}
public static void setBottomNavigationEnabled(boolean enabled) {