Refresh Feed after Credentials Change (#6236)
This commit is contained in:
parent
025944d6ab
commit
ebfda200e0
|
@ -6,7 +6,9 @@ import androidx.test.platform.app.InstrumentationRegistry;
|
|||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
import de.danoeh.antennapod.R;
|
||||
import de.danoeh.antennapod.activity.MainActivity;
|
||||
import de.danoeh.antennapod.core.storage.DBReader;
|
||||
import de.danoeh.antennapod.model.feed.Feed;
|
||||
import de.danoeh.antennapod.model.feed.FeedPreferences;
|
||||
import de.test.antennapod.EspressoTestUtils;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
|
@ -16,6 +18,8 @@ import org.junit.runner.RunWith;
|
|||
|
||||
import static androidx.test.espresso.Espresso.onView;
|
||||
import static androidx.test.espresso.action.ViewActions.click;
|
||||
import static androidx.test.espresso.action.ViewActions.pressBack;
|
||||
import static androidx.test.espresso.action.ViewActions.typeText;
|
||||
import static androidx.test.espresso.matcher.ViewMatchers.isDescendantOfA;
|
||||
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
|
||||
import static androidx.test.espresso.matcher.ViewMatchers.isRoot;
|
||||
|
@ -24,6 +28,10 @@ import static androidx.test.espresso.matcher.ViewMatchers.withText;
|
|||
import static de.test.antennapod.EspressoTestUtils.clickPreference;
|
||||
import static de.test.antennapod.EspressoTestUtils.waitForView;
|
||||
import static org.hamcrest.Matchers.allOf;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class FeedSettingsTest {
|
||||
|
@ -76,4 +84,52 @@ public class FeedSettingsTest {
|
|||
clickPreference(R.string.feed_volume_reduction);
|
||||
onView(withText(R.string.cancel_label)).perform(click());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that modifying a feed's authentication settings results in proper behavior.
|
||||
* Expect:
|
||||
* - Feed is refreshed automatically
|
||||
* - Database has updated username and password
|
||||
*/
|
||||
@Test
|
||||
public void testAuthenticationSettingsUpdate() throws IOException {
|
||||
onView(isRoot()).perform(waitForView(allOf(isDescendantOfA(withId(R.id.appBar)),
|
||||
withText(feed.getTitle()), isDisplayed()), 1000));
|
||||
|
||||
String updatedTitle = "modified episode title";
|
||||
String username = "username";
|
||||
String password = "password";
|
||||
|
||||
// update feed hosted on server
|
||||
feed.getItems().get(0).setTitle(updatedTitle);
|
||||
uiTestUtils.hostFeed(feed);
|
||||
|
||||
// interact with UI to update authentication settings
|
||||
updateAuthenticationSettings(username, password);
|
||||
|
||||
// expect feed to have refreshed and be showing new episode title
|
||||
onView(isRoot()).perform(waitForView(withText(updatedTitle), 5000));
|
||||
|
||||
// expect database to be updated with correct username and password
|
||||
Feed updatedFeed = DBReader.getFeed(feed.getId());
|
||||
assertNotNull(updatedFeed);
|
||||
|
||||
FeedPreferences updatedFeedPreferences = updatedFeed.getPreferences();
|
||||
assertNotNull(updatedFeedPreferences);
|
||||
|
||||
assertEquals("database updated with username", username, updatedFeedPreferences.getUsername());
|
||||
assertEquals("database updated with password", password, updatedFeedPreferences.getPassword());
|
||||
}
|
||||
|
||||
private void updateAuthenticationSettings(String username, String password) {
|
||||
onView(withId(R.id.butShowSettings)).perform(click());
|
||||
|
||||
clickPreference(R.string.authentication_label);
|
||||
onView(withId(R.id.usernameEditText)).perform(typeText(username));
|
||||
onView(withId(R.id.passwordEditText)).perform(typeText(password));
|
||||
onView(withText(R.string.confirm_label)).perform(click());
|
||||
|
||||
onView(isRoot()).perform(pressBack());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -78,7 +78,7 @@ public class UITestUtils {
|
|||
}
|
||||
}
|
||||
|
||||
private String hostFeed(Feed feed) throws IOException {
|
||||
public String hostFeed(Feed feed) throws IOException {
|
||||
File feedFile = new File(hostedFeedDir, feed.getTitle());
|
||||
FileOutputStream out = new FileOutputStream(feedFile);
|
||||
Rss2Generator generator = new Rss2Generator();
|
||||
|
|
|
@ -16,6 +16,7 @@ import androidx.preference.PreferenceFragmentCompat;
|
|||
import androidx.preference.SwitchPreferenceCompat;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import de.danoeh.antennapod.R;
|
||||
import de.danoeh.antennapod.core.storage.DBTasks;
|
||||
import de.danoeh.antennapod.event.settings.SkipIntroEndingChangedEvent;
|
||||
import de.danoeh.antennapod.event.settings.SpeedPresetChangedEvent;
|
||||
import de.danoeh.antennapod.event.settings.VolumeAdaptionChangedEvent;
|
||||
|
@ -36,10 +37,13 @@ import io.reactivex.MaybeOnSubscribe;
|
|||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.disposables.Disposable;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Locale;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
public class FeedSettingsFragment extends Fragment {
|
||||
private static final String TAG = "FeedSettingsFragment";
|
||||
|
@ -255,7 +259,17 @@ public class FeedSettingsFragment extends Fragment {
|
|||
protected void onConfirmed(String username, String password) {
|
||||
feedPreferences.setUsername(username);
|
||||
feedPreferences.setPassword(password);
|
||||
DBWriter.setFeedPreferences(feedPreferences);
|
||||
Future<?> setPreferencesFuture = DBWriter.setFeedPreferences(feedPreferences);
|
||||
|
||||
new Thread(() -> {
|
||||
try {
|
||||
setPreferencesFuture.get();
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
DBTasks.forceRefreshFeed(requireContext(), feed, true);
|
||||
}, "RefreshAfterCredentialChange").start();
|
||||
}
|
||||
}.show();
|
||||
return false;
|
||||
|
|
Loading…
Reference in New Issue