fix tests
This commit is contained in:
parent
70c06e7590
commit
a6260ba48b
9 changed files with 215 additions and 81 deletions
Binary file not shown.
|
@ -82,7 +82,11 @@ public class TestApiProvider extends ApiProvider {
|
|||
InputStream inputStream;
|
||||
switch (request.getUrl()) {
|
||||
case "/index.php/apps/news/api/v1-2/feeds":
|
||||
inputStream = handleCreateFeed(request);
|
||||
if("POST".equals(request.getMethod())) {
|
||||
inputStream = handleCreateFeed(request);
|
||||
} else {
|
||||
inputStream = stringToInputStream("{\"feeds\": []}");
|
||||
}
|
||||
break;
|
||||
case "/index.php/apps/news/api/v1-2/user":
|
||||
inputStream = handleUser();
|
||||
|
@ -90,8 +94,15 @@ public class TestApiProvider extends ApiProvider {
|
|||
case "/index.php/apps/news/api/v1-2/folders":
|
||||
inputStream = handleFolders();
|
||||
break;
|
||||
case "/index.php/apps/news/api/v1-2/items":
|
||||
inputStream = stringToInputStream("{\"items\": []}");
|
||||
break;
|
||||
//case "index.php/apps/news/api/v1-2/feeds":
|
||||
case "/index.php/apps/news/api/v1-2/items/unread/multiple":
|
||||
inputStream = stringToInputStream("");
|
||||
break;
|
||||
default:
|
||||
Log.e(TAG, request.getUrl());
|
||||
throw new Error("Not implemented yet!");
|
||||
}
|
||||
return inputStream;
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
package de.luhmer.owncloudnewsreader.helper;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
|
||||
import com.nextcloud.android.sso.aidl.NextcloudRequest;
|
||||
|
||||
import org.mockito.ArgumentCaptor;
|
||||
|
||||
import de.luhmer.owncloudnewsreader.R;
|
||||
import de.luhmer.owncloudnewsreader.di.TestApiProvider;
|
||||
import de.luhmer.owncloudnewsreader.reader.nextcloud.API;
|
||||
|
||||
import static androidx.test.espresso.Espresso.onView;
|
||||
import static androidx.test.espresso.action.ViewActions.click;
|
||||
import static androidx.test.espresso.matcher.ViewMatchers.withId;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.timeout;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
public class Utils {
|
||||
|
||||
public static void initMaterialShowCaseView(Context context) {
|
||||
String PREFS_NAME = "material_showcaseview_prefs";
|
||||
SharedPreferences sp = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
|
||||
sp.edit()
|
||||
.putInt("status_SWIPE_LEFT_RIGHT_AND_PTR", -1)
|
||||
.putInt("status_LOGO_SYNC", -1)
|
||||
.commit();
|
||||
}
|
||||
|
||||
public static void clearFocus() {
|
||||
sleep(200);
|
||||
onView(withId(R.id.toolbar)).perform(click());
|
||||
sleep(200);
|
||||
}
|
||||
|
||||
public static void sleep(int millis) {
|
||||
try {
|
||||
Thread.sleep(millis);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void sleep(float seconds) {
|
||||
try {
|
||||
Thread.sleep((long) seconds * 1000);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -11,9 +11,14 @@ import org.junit.Before;
|
|||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
|
@ -28,7 +33,11 @@ import androidx.test.espresso.matcher.BoundedMatcher;
|
|||
import androidx.test.espresso.matcher.ViewMatchers;
|
||||
import androidx.test.filters.LargeTest;
|
||||
import androidx.test.rule.ActivityTestRule;
|
||||
import androidx.test.rule.GrantPermissionRule;
|
||||
import androidx.test.runner.AndroidJUnit4;
|
||||
|
||||
import com.nextcloud.android.sso.aidl.NextcloudRequest;
|
||||
|
||||
import de.luhmer.owncloudnewsreader.Constants;
|
||||
import de.luhmer.owncloudnewsreader.NewsReaderDetailFragment;
|
||||
import de.luhmer.owncloudnewsreader.NewsReaderListActivity;
|
||||
|
@ -36,6 +45,8 @@ import de.luhmer.owncloudnewsreader.R;
|
|||
import de.luhmer.owncloudnewsreader.TestApplication;
|
||||
import de.luhmer.owncloudnewsreader.adapter.NewsListRecyclerAdapter;
|
||||
import de.luhmer.owncloudnewsreader.adapter.ViewHolder;
|
||||
import de.luhmer.owncloudnewsreader.di.ApiProvider;
|
||||
import de.luhmer.owncloudnewsreader.di.TestApiProvider;
|
||||
import de.luhmer.owncloudnewsreader.di.TestComponent;
|
||||
import helper.OrientationChangeAction;
|
||||
import helper.RecyclerViewAssertions;
|
||||
|
@ -56,11 +67,19 @@ import static androidx.test.espresso.matcher.ViewMatchers.withContentDescription
|
|||
import static androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility;
|
||||
import static androidx.test.espresso.matcher.ViewMatchers.withId;
|
||||
import static androidx.test.espresso.matcher.ViewMatchers.withText;
|
||||
import static de.luhmer.owncloudnewsreader.helper.Utils.clearFocus;
|
||||
import static de.luhmer.owncloudnewsreader.helper.Utils.initMaterialShowCaseView;
|
||||
import static de.luhmer.owncloudnewsreader.helper.Utils.sleep;
|
||||
import static junit.framework.TestCase.assertNotNull;
|
||||
import static junit.framework.TestCase.assertTrue;
|
||||
import static junit.framework.TestCase.fail;
|
||||
import static org.hamcrest.Matchers.allOf;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.timeout;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
@LargeTest
|
||||
|
@ -71,7 +90,11 @@ public class NewsReaderListActivityUiTests {
|
|||
@Rule
|
||||
public ActivityTestRule<NewsReaderListActivity> mActivityRule = new ActivityTestRule<>(NewsReaderListActivity.class);
|
||||
|
||||
@Rule
|
||||
public GrantPermissionRule mRuntimePermissionRule = GrantPermissionRule.grant(android.Manifest.permission.ACCESS_FINE_LOCATION);
|
||||
|
||||
protected @Inject SharedPreferences mPrefs;
|
||||
protected @Inject ApiProvider mApi;
|
||||
|
||||
private NewsReaderListActivity getActivity() {
|
||||
return mActivityRule.getActivity();
|
||||
|
@ -84,6 +107,10 @@ public class NewsReaderListActivityUiTests {
|
|||
|
||||
TestComponent ac = (TestComponent) ((TestApplication)(getActivity().getApplication())).getAppComponent();
|
||||
ac.inject(this);
|
||||
|
||||
clearFocus();
|
||||
|
||||
initMaterialShowCaseView(getActivity());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -96,13 +123,21 @@ public class NewsReaderListActivityUiTests {
|
|||
onView(isRoot()).perform(OrientationChangeAction.orientationLandscape(getActivity()));
|
||||
//onView(isRoot()).perform(OrientationChangeAction.orientationPortrait(getActivity()));
|
||||
|
||||
sleep(1.0f);
|
||||
sleep(2000);
|
||||
|
||||
LinearLayoutManager llm = (LinearLayoutManager) ndf.getRecyclerView().getLayoutManager();
|
||||
onView(withId(R.id.list)).check(new RecyclerViewAssertions(scrollPosition-(scrollPosition-llm.findFirstVisibleItemPosition())));
|
||||
int expectedPosition = scrollPosition-(scrollPosition-llm.findFirstVisibleItemPosition());
|
||||
|
||||
// As there is a little offset when rotating.. we need to add one here..
|
||||
onView(withId(R.id.list)).check(new RecyclerViewAssertions(expectedPosition+1));
|
||||
onView(withId(R.id.tv_no_items_available)).check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE)));
|
||||
|
||||
//onView(isRoot()).perform(OrientationChangeAction.orientationLandscape(getActivity()));
|
||||
sleep(2000);
|
||||
|
||||
onView(isRoot()).perform(OrientationChangeAction.orientationPortrait(getActivity()));
|
||||
|
||||
onView(withId(R.id.list)).check(new RecyclerViewAssertions(expectedPosition));
|
||||
onView(withId(R.id.tv_no_items_available)).check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE)));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -111,7 +146,7 @@ public class NewsReaderListActivityUiTests {
|
|||
|
||||
onView(withId(R.id.list)).perform(RecyclerViewActions.actionOnItemAtPosition(scrollPosition, click()));
|
||||
|
||||
sleep(2);
|
||||
sleep(2000);
|
||||
|
||||
Espresso.pressBack();
|
||||
|
||||
|
@ -126,7 +161,8 @@ public class NewsReaderListActivityUiTests {
|
|||
getActivity().runOnUiThread(() -> na.changeReadStateOfItem(vh, false));
|
||||
sleep(1.0f);
|
||||
|
||||
onView(withId(R.id.list)).check(new RecyclerViewAssertions(scrollPosition-(scrollPosition-llm.findFirstVisibleItemPosition())));
|
||||
int expectedPosition = scrollPosition-(scrollPosition-llm.findFirstVisibleItemPosition());
|
||||
onView(withId(R.id.list)).check(new RecyclerViewAssertions(expectedPosition));
|
||||
onView(withId(R.id.tv_no_items_available)).check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE)));
|
||||
}
|
||||
|
||||
|
@ -144,9 +180,8 @@ public class NewsReaderListActivityUiTests {
|
|||
|
||||
@Test
|
||||
public void searchTest() {
|
||||
String firstItem = "These are the best screen protectors for the Huawei P30 Pro";
|
||||
|
||||
sleep(500);
|
||||
String firstItem = "Immer wieder sonntags KW 19";
|
||||
// String firstItem = "These are the best screen protectors for the Huawei P30 Pro";
|
||||
|
||||
// Check first item
|
||||
checkRecyclerViewFirstItemText(firstItem);
|
||||
|
@ -157,12 +192,13 @@ public class NewsReaderListActivityUiTests {
|
|||
// Type in "test" into searchbar
|
||||
onView(allOf(withClassName(is("android.widget.SearchView$SearchAutoComplete")), isDisplayed())).perform(typeText("test"));
|
||||
sleep(1000);
|
||||
checkRecyclerViewFirstItemText("Testfahrt im Mercedes E 300 de mit 90-kW-Elektromotor und Vierzylinder-Diesel");
|
||||
checkRecyclerViewFirstItemText("VR ohne Kabel: Die Oculus Quest im Test, definitiv der richtige Ansatz");
|
||||
// checkRecyclerViewFirstItemText("Testfahrt im Mercedes E 300 de mit 90-kW-Elektromotor und Vierzylinder-Diesel");
|
||||
|
||||
// Close search bar
|
||||
onView(withContentDescription("Collapse")).perform(click());
|
||||
|
||||
sleep(500);
|
||||
sleep(1000);
|
||||
|
||||
// Test if search reset was successful
|
||||
checkRecyclerViewFirstItemText(firstItem);
|
||||
|
@ -173,18 +209,39 @@ public class NewsReaderListActivityUiTests {
|
|||
// Open navigation drawer
|
||||
onView(allOf(withContentDescription(getString(R.string.news_list_drawer_text)), isDisplayed())).perform(click());
|
||||
|
||||
sleep(1000);
|
||||
sleep(1500);
|
||||
|
||||
/*
|
||||
// Click on Got it
|
||||
onView(allOf(withText("GOT IT"), isDisplayed())).perform(click());
|
||||
|
||||
sleep(1000);
|
||||
*/
|
||||
|
||||
// Trigger refresh
|
||||
onView(allOf(withContentDescription(getString(R.string.content_desc_tap_to_refresh)), isDisplayed())).perform(click());
|
||||
|
||||
sleep(1000);
|
||||
assertTrue(true);
|
||||
try {
|
||||
verifySyncRequested();
|
||||
} catch (Exception e) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// Verify that the API was actually called
|
||||
private void verifySyncRequested() throws Exception {
|
||||
TestApiProvider.NewsTestNetworkRequest nr = ((TestApiProvider)mApi).networkRequestSpy;
|
||||
ArgumentCaptor<NextcloudRequest> argument = ArgumentCaptor.forClass(NextcloudRequest.class);
|
||||
verify(nr, times(6)).performNetworkRequest(argument.capture(), any());
|
||||
|
||||
List<String> requestedUrls = argument.getAllValues().stream().map(nextcloudRequest -> nextcloudRequest.getUrl()).collect(Collectors.toList());
|
||||
|
||||
assertTrue(requestedUrls.contains("/index.php/apps/news/api/v1-2/folders"));
|
||||
assertTrue(requestedUrls.contains("/index.php/apps/news/api/v1-2/feeds"));
|
||||
assertTrue(requestedUrls.contains("/index.php/apps/news/api/v1-2/items/unread/multiple"));
|
||||
assertTrue(requestedUrls.contains("/index.php/apps/news/api/v1-2/items")); // TODO Double check why /items is called twice... ?
|
||||
assertTrue(requestedUrls.contains("/index.php/apps/news/api/v1-2/user"));
|
||||
}
|
||||
|
||||
|
||||
|
@ -197,14 +254,6 @@ public class NewsReaderListActivityUiTests {
|
|||
return mActivityRule.getActivity().getString(resId);
|
||||
}
|
||||
|
||||
private void sleep(int millis) {
|
||||
try {
|
||||
Thread.sleep(millis);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static Matcher<View> atPosition(final int position, @NonNull final Matcher<View> itemMatcher) {
|
||||
checkNotNull(itemMatcher);
|
||||
|
@ -268,15 +317,6 @@ public class NewsReaderListActivityUiTests {
|
|||
return true;
|
||||
}
|
||||
|
||||
private void sleep(float seconds) {
|
||||
try {
|
||||
Thread.sleep((long) seconds * 1000);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private Fragment waitForFragment(int id, int timeout) {
|
||||
long endTime = SystemClock.uptimeMillis() + timeout;
|
||||
while (SystemClock.uptimeMillis() <= endTime) {
|
||||
|
|
|
@ -20,6 +20,7 @@ import androidx.test.InstrumentationRegistry;
|
|||
import androidx.test.espresso.contrib.RecyclerViewActions;
|
||||
import androidx.test.filters.LargeTest;
|
||||
import androidx.test.rule.ActivityTestRule;
|
||||
import androidx.test.rule.GrantPermissionRule;
|
||||
import androidx.test.runner.AndroidJUnit4;
|
||||
import de.luhmer.owncloudnewsreader.NewsReaderListActivity;
|
||||
import de.luhmer.owncloudnewsreader.R;
|
||||
|
@ -55,6 +56,9 @@ public class NightModeTest {
|
|||
public ActivityTestRule<NewsReaderListActivity> mActivityRule = new ActivityTestRule<>(NewsReaderListActivity.class);
|
||||
//public ActivityTestRule<NewsReaderListActivity> mActivityRule = new ActivityTestRule<>(NewsReaderListActivity.class, true, false);
|
||||
|
||||
@Rule
|
||||
public GrantPermissionRule mRuntimePermissionRule = GrantPermissionRule.grant(android.Manifest.permission.ACCESS_FINE_LOCATION);
|
||||
|
||||
private Activity getActivity() {
|
||||
return mActivityRule.getActivity();
|
||||
}
|
||||
|
|
|
@ -5,10 +5,13 @@ import org.junit.ClassRule;
|
|||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import androidx.core.view.GravityCompat;
|
||||
import androidx.test.filters.LargeTest;
|
||||
import androidx.test.rule.ActivityTestRule;
|
||||
import androidx.test.runner.AndroidJUnit4;
|
||||
import androidx.test.rule.GrantPermissionRule;
|
||||
|
||||
import de.luhmer.owncloudnewsreader.NewsReaderDetailFragment;
|
||||
import de.luhmer.owncloudnewsreader.NewsReaderListActivity;
|
||||
import de.luhmer.owncloudnewsreader.NewsReaderListFragment;
|
||||
|
@ -17,12 +20,17 @@ import de.luhmer.owncloudnewsreader.adapter.ViewHolder;
|
|||
import de.luhmer.owncloudnewsreader.database.DatabaseConnectionOrm;
|
||||
import de.luhmer.owncloudnewsreader.model.PodcastItem;
|
||||
import tools.fastlane.screengrab.Screengrab;
|
||||
import tools.fastlane.screengrab.UiAutomatorScreenshotStrategy;
|
||||
import tools.fastlane.screengrab.locale.LocaleTestRule;
|
||||
|
||||
import static de.luhmer.owncloudnewsreader.helper.Utils.clearFocus;
|
||||
import static de.luhmer.owncloudnewsreader.helper.Utils.initMaterialShowCaseView;
|
||||
|
||||
/**
|
||||
* Created by David on 06.03.2016.
|
||||
*/
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
@RunWith(JUnit4.class)
|
||||
@LargeTest
|
||||
public class ScreenshotTest {
|
||||
|
||||
@ClassRule
|
||||
|
@ -31,19 +39,28 @@ public class ScreenshotTest {
|
|||
@Rule
|
||||
public ActivityTestRule<NewsReaderListActivity> mActivityRule = new ActivityTestRule<>(NewsReaderListActivity.class);
|
||||
|
||||
@Rule
|
||||
public GrantPermissionRule mRuntimePermissionRule = GrantPermissionRule.grant(android.Manifest.permission.ACCESS_FINE_LOCATION, android.Manifest.permission.WRITE_EXTERNAL_STORAGE);
|
||||
|
||||
private NewsReaderListActivity activity;
|
||||
|
||||
private NewsReaderListActivity mActivity;
|
||||
private NewsReaderListFragment nrlf;
|
||||
private NewsReaderDetailFragment nrdf;
|
||||
private int itemPos = 0;
|
||||
|
||||
private int podcastGroupPosition = 3;
|
||||
//private int podcastGroupPosition = 3;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
activity = mActivityRule.getActivity();
|
||||
nrlf = mActivityRule.getActivity().getSlidingListFragment();
|
||||
nrdf = mActivityRule.getActivity().getNewsReaderDetailFragment();
|
||||
Screengrab.setDefaultScreenshotStrategy(new UiAutomatorScreenshotStrategy());
|
||||
|
||||
mActivity = mActivityRule.getActivity();
|
||||
nrlf = mActivity.getSlidingListFragment();
|
||||
nrdf = mActivity.getNewsReaderDetailFragment();
|
||||
|
||||
clearFocus();
|
||||
|
||||
initMaterialShowCaseView(mActivity);
|
||||
}
|
||||
|
||||
|
||||
|
@ -52,9 +69,9 @@ public class ScreenshotTest {
|
|||
public void testTakeScreenshots() {
|
||||
Screengrab.screenshot("startup");
|
||||
|
||||
activity.runOnUiThread(() -> {
|
||||
mActivity.runOnUiThread(() -> {
|
||||
openDrawer();
|
||||
nrlf.getListView().expandGroup(podcastGroupPosition);
|
||||
//nrlf.getListView().expandGroup(podcastGroupPosition);
|
||||
});
|
||||
|
||||
try {
|
||||
|
@ -66,7 +83,7 @@ public class ScreenshotTest {
|
|||
Screengrab.screenshot("slider_open");
|
||||
|
||||
|
||||
activity.runOnUiThread(() -> {
|
||||
mActivity.runOnUiThread(() -> {
|
||||
closeDrawer();
|
||||
|
||||
try {
|
||||
|
@ -75,7 +92,7 @@ public class ScreenshotTest {
|
|||
e.printStackTrace();
|
||||
}
|
||||
|
||||
activity.onClick(null, itemPos); //Select item
|
||||
mActivity.onClick(null, itemPos); //Select item
|
||||
|
||||
});
|
||||
|
||||
|
@ -87,7 +104,7 @@ public class ScreenshotTest {
|
|||
|
||||
Screengrab.screenshot("detail_activity");
|
||||
|
||||
activity.runOnUiThread(() -> {
|
||||
mActivity.runOnUiThread(() -> {
|
||||
NewsListRecyclerAdapter na = (NewsListRecyclerAdapter) nrdf.getRecyclerView().getAdapter();
|
||||
ViewHolder vh = (ViewHolder) nrdf.getRecyclerView().getChildViewHolder(nrdf.getRecyclerView().getLayoutManager().findViewByPosition(itemPos));
|
||||
na.changeReadStateOfItem(vh, false);
|
||||
|
@ -98,11 +115,12 @@ public class ScreenshotTest {
|
|||
|
||||
|
||||
@Test
|
||||
public void testPodcast() {
|
||||
activity.runOnUiThread(() -> {
|
||||
public void testAudioPodcast() {
|
||||
mActivity.runOnUiThread(() -> {
|
||||
openDrawer();
|
||||
nrlf.getListView().expandGroup(podcastGroupPosition);
|
||||
openFeed(podcastGroupPosition, 0);
|
||||
//nrlf.getListView().expandGroup(podcastGroupPosition);
|
||||
//openFeed(podcastGroupPosition, 0);
|
||||
openFeed(2, 1); // Open Android Podcast
|
||||
});
|
||||
|
||||
try {
|
||||
|
@ -111,17 +129,17 @@ public class ScreenshotTest {
|
|||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Screengrab.screenshot("podcast_list");
|
||||
//Screengrab.screenshot("podcast_list");
|
||||
|
||||
activity.runOnUiThread(() -> {
|
||||
mActivity.runOnUiThread(() -> {
|
||||
ViewHolder vh = (ViewHolder) nrdf.getRecyclerView().getChildViewHolder(nrdf.getRecyclerView().getLayoutManager().findViewByPosition(0));
|
||||
PodcastItem podcastItem = DatabaseConnectionOrm.ParsePodcastItemFromRssItem(activity, vh.getRssItem());
|
||||
activity.openMediaItem(podcastItem);
|
||||
PodcastItem podcastItem = DatabaseConnectionOrm.ParsePodcastItemFromRssItem(mActivity, vh.getRssItem());
|
||||
mActivity.openMediaItem(podcastItem);
|
||||
});
|
||||
|
||||
|
||||
try {
|
||||
Thread.sleep(5000);
|
||||
Thread.sleep(10000);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -129,7 +147,7 @@ public class ScreenshotTest {
|
|||
Screengrab.screenshot("podcast_running");
|
||||
|
||||
|
||||
activity.runOnUiThread(() -> activity.pausePodcast());
|
||||
mActivity.runOnUiThread(() -> mActivity.pausePodcast());
|
||||
|
||||
|
||||
try {
|
||||
|
@ -143,12 +161,13 @@ public class ScreenshotTest {
|
|||
|
||||
@Test
|
||||
public void testVideoPodcast() {
|
||||
activity.runOnUiThread(() -> {
|
||||
mActivity.runOnUiThread(() -> {
|
||||
//Set url to mock
|
||||
nrlf.bindUserInfoToUI();
|
||||
|
||||
openDrawer();
|
||||
openFeed(0, 13); //Click on ARD Podcast
|
||||
//openFeed(0, 13); //Click on ARD Podcast
|
||||
openFeed(7, -1);
|
||||
});
|
||||
|
||||
try {
|
||||
|
@ -157,23 +176,23 @@ public class ScreenshotTest {
|
|||
e.printStackTrace();
|
||||
}
|
||||
|
||||
activity.runOnUiThread(() -> {
|
||||
mActivity.runOnUiThread(() -> {
|
||||
ViewHolder vh = (ViewHolder) nrdf.getRecyclerView().getChildViewHolder(nrdf.getRecyclerView().getLayoutManager().findViewByPosition(1));
|
||||
PodcastItem podcastItem = DatabaseConnectionOrm.ParsePodcastItemFromRssItem(activity, vh.getRssItem());
|
||||
activity.openMediaItem(podcastItem);
|
||||
PodcastItem podcastItem = DatabaseConnectionOrm.ParsePodcastItemFromRssItem(mActivity, vh.getRssItem());
|
||||
mActivity.openMediaItem(podcastItem);
|
||||
});
|
||||
|
||||
|
||||
try {
|
||||
Thread.sleep(5000);
|
||||
Thread.sleep(15000);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
Screengrab.screenshot("video_podcast_running");
|
||||
|
||||
|
||||
activity.runOnUiThread(() -> activity.pausePodcast());
|
||||
mActivity.runOnUiThread(() -> mActivity.pausePodcast());
|
||||
|
||||
|
||||
try {
|
||||
|
@ -188,14 +207,14 @@ public class ScreenshotTest {
|
|||
}
|
||||
|
||||
private void openDrawer() {
|
||||
if(activity.drawerLayout != null) {
|
||||
activity.drawerLayout.openDrawer(GravityCompat.START, true);
|
||||
if(mActivity.drawerLayout != null) {
|
||||
mActivity.drawerLayout.openDrawer(GravityCompat.START, true);
|
||||
}
|
||||
}
|
||||
|
||||
private void closeDrawer() {
|
||||
if(activity.drawerLayout != null) {
|
||||
activity.drawerLayout.closeDrawer(GravityCompat.START, true);
|
||||
if(mActivity.drawerLayout != null) {
|
||||
mActivity.drawerLayout.closeDrawer(GravityCompat.START, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,6 +49,7 @@ import java.io.Serializable;
|
|||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
@ -56,6 +57,8 @@ import de.luhmer.owncloudnewsreader.ListView.SubscriptionExpandableListAdapter;
|
|||
import de.luhmer.owncloudnewsreader.database.DatabaseConnectionOrm;
|
||||
import de.luhmer.owncloudnewsreader.di.ApiProvider;
|
||||
import de.luhmer.owncloudnewsreader.interfaces.ExpListTextClicked;
|
||||
import de.luhmer.owncloudnewsreader.model.AbstractItem;
|
||||
import de.luhmer.owncloudnewsreader.model.ConcreteFeedItem;
|
||||
import de.luhmer.owncloudnewsreader.model.FolderSubscribtionItem;
|
||||
import de.luhmer.owncloudnewsreader.model.UserInfo;
|
||||
import io.reactivex.Observer;
|
||||
|
@ -221,17 +224,27 @@ public class NewsReaderListFragment extends Fragment implements OnCreateContextM
|
|||
|
||||
};
|
||||
|
||||
// Code below is only used for unit tests
|
||||
@VisibleForTesting
|
||||
public OnChildClickListener onChildClickListener = new OnChildClickListener() {
|
||||
|
||||
@Override
|
||||
public boolean onChildClick(ExpandableListView parent, View v,
|
||||
int groupPosition, int childPosition, long id) {
|
||||
|
||||
long idItem = lvAdapter.getChildId(groupPosition, childPosition);
|
||||
long idItem;
|
||||
if(childPosition != -1) {
|
||||
idItem = lvAdapter.getChildId(groupPosition, childPosition);
|
||||
} else {
|
||||
idItem = groupPosition;
|
||||
}
|
||||
Long optional_id_folder = null;
|
||||
FolderSubscribtionItem groupItem = (FolderSubscribtionItem) lvAdapter.getGroup(groupPosition);
|
||||
AbstractItem groupItem = (AbstractItem) lvAdapter.getGroup(groupPosition);
|
||||
if(groupItem != null)
|
||||
optional_id_folder = groupItem.id_database;
|
||||
if(groupItem instanceof ConcreteFeedItem) {
|
||||
idItem = ((ConcreteFeedItem)groupItem).feedId;
|
||||
}
|
||||
|
||||
mCallbacks.onChildItemClicked(idItem, optional_id_folder);
|
||||
|
||||
|
|
|
@ -456,15 +456,6 @@ public class PodcastFragment extends Fragment {
|
|||
if (mediaType == PlaybackService.VideoType.Video) {
|
||||
Log.v(TAG, "init regular video");
|
||||
tryOpeningPictureinPictureMode();
|
||||
} else if (mediaType == PlaybackService.VideoType.YouTube) {
|
||||
//if ("extra".equals(BuildConfig.FLAVOR)) {
|
||||
Log.v(TAG, "show youtube videos not supported");
|
||||
new AlertDialog.Builder(getActivity())
|
||||
.setTitle(getString(R.string.warning))
|
||||
.setMessage(R.string.dialog_feature_not_available)
|
||||
.setCancelable(true)
|
||||
.setPositiveButton(getString(android.R.string.ok), null)
|
||||
.show();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -213,8 +213,9 @@ public class PodcastPlaybackService extends MediaBrowserServiceCompat {
|
|||
}
|
||||
|
||||
private void updateMetadata(MediaItem mediaItem) {
|
||||
if(mediaItem == null) {
|
||||
mediaItem = new PodcastItem(-1, "", "", "", "", false, null, false);
|
||||
MediaItem mi = mediaItem;
|
||||
if(mi == null) {
|
||||
mi = new PodcastItem(-1, "", "", "", "", false, null, false);
|
||||
}
|
||||
|
||||
int totalDuration = 0;
|
||||
|
@ -223,11 +224,11 @@ public class PodcastPlaybackService extends MediaBrowserServiceCompat {
|
|||
}
|
||||
|
||||
mSession.setMetadata(new MediaMetadataCompat.Builder()
|
||||
.putString(MediaMetadataCompat.METADATA_KEY_ARTIST, mediaItem.author)
|
||||
.putString(MediaMetadataCompat.METADATA_KEY_TITLE, mediaItem.title)
|
||||
.putString(MediaMetadataCompat.METADATA_KEY_ARTIST, mi.author)
|
||||
.putString(MediaMetadataCompat.METADATA_KEY_TITLE, mi.title)
|
||||
//.putString(MediaMetadataCompat.METADATA_KEY_DISPLAY_SUBTITLE, mediaItem.author) // Android Auto
|
||||
.putString(MediaMetadataCompat.METADATA_KEY_ALBUM_ART_URI, mediaItem.favIcon)
|
||||
.putString(MediaMetadataCompat.METADATA_KEY_MEDIA_ID, String.valueOf(mediaItem.itemId))
|
||||
.putString(MediaMetadataCompat.METADATA_KEY_ALBUM_ART_URI, mi.favIcon)
|
||||
.putString(MediaMetadataCompat.METADATA_KEY_MEDIA_ID, String.valueOf(mi.itemId))
|
||||
.putString(CURRENT_PODCAST_MEDIA_TYPE, getCurrentlyPlayedMediaType().toString())
|
||||
.putLong(MediaMetadataCompat.METADATA_KEY_DURATION, totalDuration)
|
||||
//.putLong(EXTRA_IS_EXPLICIT, EXTRA_METADATA_ENABLED_VALUE) // Android Auto
|
||||
|
|
Loading…
Reference in a new issue