Merge pull request #3698 from ByteHamster/fix-mark-played-button

Fixed mark played button not working
This commit is contained in:
H. Lehmann 2019-12-20 00:13:19 +01:00 committed by GitHub
commit 51c717c41b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 85 additions and 6 deletions

View File

@ -0,0 +1,71 @@
package de.test.antennapod.ui;
import android.content.Intent;
import androidx.test.espresso.intent.rule.IntentsTestRule;
import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.runner.AndroidJUnit4;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.activity.MainActivity;
import de.danoeh.antennapod.core.feed.Feed;
import de.test.antennapod.EspressoTestUtils;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
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.scrollTo;
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
import static androidx.test.espresso.matcher.ViewMatchers.isRoot;
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;
import static org.hamcrest.CoreMatchers.not;
/**
* Test UI for feeds that do not have media files
*/
@RunWith(AndroidJUnit4.class)
public class TextOnlyFeedsTest {
private UITestUtils uiTestUtils;
@Rule
public IntentsTestRule<MainActivity> activityRule = new IntentsTestRule<>(MainActivity.class, false, false);
@Before
public void setUp() throws IOException {
EspressoTestUtils.clearPreferences();
EspressoTestUtils.makeNotFirstRun();
EspressoTestUtils.clearDatabase();
uiTestUtils = new UITestUtils(InstrumentationRegistry.getInstrumentation().getTargetContext());
uiTestUtils.setHostTextOnlyFeeds(true);
uiTestUtils.setup();
activityRule.launchActivity(new Intent());
}
@After
public void tearDown() throws Exception {
uiTestUtils.tearDown();
}
@Test
public void testMarkAsPlayedList() throws Exception {
uiTestUtils.addLocalFeedData(false);
final Feed feed = uiTestUtils.hostedFeeds.get(0);
openNavDrawer();
onDrawerItem(withText(feed.getTitle())).perform(scrollTo(), click());
onView(withText(feed.getItemAtIndex(0).getTitle())).perform(click());
onView(withText(R.string.mark_read_label)).perform(click());
onView(isRoot()).perform(waitForView(allOf(withText(R.string.mark_read_label), not(isDisplayed())), 3000));
}
}

View File

@ -43,6 +43,7 @@ public class UITestUtils {
private static final int NUM_ITEMS_PER_FEED = 10;
private String testFileName = "3sec.mp3";
private boolean hostTextOnlyFeeds = false;
private final Context context;
private final HTTPBin server = new HTTPBin();
private File destDir;
@ -142,9 +143,10 @@ public class UITestUtils {
"http://example.com/feed" + i + "/item/" + j, new Date(), FeedItem.UNPLAYED, feed);
items.add(item);
File mediaFile = newMediaFile("feed-" + i + "-episode-" + j + ".mp3");
item.setMedia(new FeedMedia(j, item, 0, 0, mediaFile.length(), "audio/mp3", null, hostFile(mediaFile), false, null, 0, 0));
if (!hostTextOnlyFeeds) {
File mediaFile = newMediaFile("feed-" + i + "-episode-" + j + ".mp3");
item.setMedia(new FeedMedia(j, item, 0, 0, mediaFile.length(), "audio/mp3", null, hostFile(mediaFile), false, null, 0, 0));
}
}
feed.setItems(items);
feed.setDownload_url(hostFeed(feed));
@ -191,7 +193,9 @@ public class UITestUtils {
}
queue.add(feed.getItems().get(0));
feed.getItems().get(1).getMedia().setPlaybackCompletionDate(new Date());
if (feed.getItems().get(1).hasMedia()) {
feed.getItems().get(1).getMedia().setPlaybackCompletionDate(new Date());
}
}
localFeedDataAdded = true;
@ -218,4 +222,8 @@ public class UITestUtils {
public void setMediaFileName(String filename) {
testFileName = filename;
}
public void setHostTextOnlyFeeds(boolean hostTextOnlyFeeds) {
this.hostTextOnlyFeeds = hostTextOnlyFeeds;
}
}

View File

@ -235,7 +235,7 @@ public class ItemFragment extends Fragment {
@Override
public void onResume() {
super.onResume();
if(itemsLoaded) {
if (itemsLoaded) {
progbarLoading.setVisibility(View.GONE);
updateAppearance();
}
@ -459,7 +459,7 @@ public class ItemFragment extends Fragment {
}
}
@Subscribe
@Subscribe(threadMode = ThreadMode.MAIN)
public void onUnreadItemsChanged(UnreadItemsUpdateEvent event) {
load();
}