Fixed tests

This commit is contained in:
ByteHamster 2020-03-23 16:08:18 +01:00
parent 5ad7228b4e
commit 11536361c5
4 changed files with 17 additions and 27 deletions

View File

@ -32,7 +32,9 @@ import java.util.concurrent.TimeoutException;
import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.action.ViewActions.click;
import static androidx.test.espresso.matcher.ViewMatchers.hasDescendant;
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
import static androidx.test.espresso.matcher.ViewMatchers.isRoot;
import static androidx.test.espresso.matcher.ViewMatchers.withContentDescription;
import static androidx.test.espresso.matcher.ViewMatchers.withId;
import static androidx.test.espresso.matcher.ViewMatchers.withText;
import static org.hamcrest.Matchers.allOf;
@ -193,4 +195,8 @@ public class EspressoTestUtils {
}
androidx.test.platform.app.InstrumentationRegistry.getInstrumentation().waitForIdleSync();
}
public static Matcher<View> actionBarOverflow() {
return allOf(isDisplayed(), withContentDescription("More options"));
}
}

View File

@ -1,6 +1,7 @@
package de.test.antennapod.ui;
import android.content.Intent;
import android.view.View;
import androidx.test.espresso.Espresso;
import androidx.test.espresso.intent.rule.IntentsTestRule;
import androidx.test.runner.AndroidJUnit4;
@ -8,6 +9,7 @@ import de.danoeh.antennapod.R;
import de.danoeh.antennapod.activity.MainActivity;
import de.danoeh.antennapod.fragment.QueueFragment;
import de.test.antennapod.EspressoTestUtils;
import org.hamcrest.Matcher;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
@ -18,6 +20,7 @@ import static androidx.test.espresso.action.ViewActions.click;
import static androidx.test.espresso.matcher.ViewMatchers.withClassName;
import static androidx.test.espresso.matcher.ViewMatchers.withContentDescription;
import static androidx.test.espresso.matcher.ViewMatchers.withText;
import static de.test.antennapod.NthMatcher.first;
import static org.hamcrest.CoreMatchers.allOf;
import static org.hamcrest.CoreMatchers.endsWith;
@ -48,14 +51,14 @@ public class QueueFragmentTest {
@Test
public void testSortEmptyQueue() {
Espresso.openContextualActionModeOverflowMenu();
onView(first(EspressoTestUtils.actionBarOverflow())).perform(click());
onView(withText(R.string.sort)).perform(click());
onView(withText(R.string.random)).perform(click());
}
@Test
public void testKeepEmptyQueueSorted() {
Espresso.openContextualActionModeOverflowMenu();
onView(first(EspressoTestUtils.actionBarOverflow())).perform(click());
onView(withText(R.string.sort)).perform(click());
onView(withText(R.string.keep_sorted)).perform(click());
}

View File

@ -4,7 +4,6 @@ import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.core.view.ViewCompat;
import androidx.viewpager.widget.ViewPager;
@ -12,7 +11,7 @@ import java.lang.ref.WeakReference;
/**
* Override {@link #findScrollingChild(View)} to support {@link ViewPager}'s nested scrolling.
* By the way, In order to override package level method and field.
* In order to override package level method and field.
* This class put in the same package path where {@link BottomSheetBehavior} located.
* Source: https://medium.com/@hanru.yeh/funny-solution-that-makes-bottomsheetdialog-support-viewpager-with-nestedscrollingchilds-bfdca72235c3
*/
@ -52,24 +51,4 @@ public class ViewPagerBottomSheetBehavior<V extends View> extends BottomSheetBeh
final View scrollingChild = findScrollingChild(viewRef.get());
nestedScrollingChildRef = new WeakReference<>(scrollingChild);
}
/**
* A utility function to get the {@link ViewPagerBottomSheetBehavior} associated with the {@code view}.
*
* @param view The {@link View} with {@link ViewPagerBottomSheetBehavior}.
* @return The {@link ViewPagerBottomSheetBehavior} associated with the {@code view}.
*/
@SuppressWarnings("unchecked")
public static <V extends View> ViewPagerBottomSheetBehavior<V> from(V view) {
ViewGroup.LayoutParams params = view.getLayoutParams();
if (!(params instanceof CoordinatorLayout.LayoutParams)) {
throw new IllegalArgumentException("The view is not a child of CoordinatorLayout");
}
CoordinatorLayout.Behavior behavior = ((CoordinatorLayout.LayoutParams) params).getBehavior();
if (!(behavior instanceof ViewPagerBottomSheetBehavior)) {
throw new IllegalArgumentException(
"The view is not associated with ViewPagerBottomSheetBehavior");
}
return (ViewPagerBottomSheetBehavior<V>) behavior;
}
}

View File

@ -333,9 +333,11 @@ public class AudioPlayerFragment extends Fragment implements
updatePlaybackSpeedButton();
setupOptionsMenu();
List<Chapter> chapters = controller.getMedia().getChapters();
boolean hasChapters = chapters != null && !chapters.isEmpty();
pageIndicator.setDisabledPage(hasChapters ? -1 : 2);
if (controller.getMedia() != null) {
List<Chapter> chapters = controller.getMedia().getChapters();
boolean hasChapters = chapters != null && !chapters.isEmpty();
pageIndicator.setDisabledPage(hasChapters ? -1 : 2);
}
}
@Override