Added queue test

This commit is contained in:
ByteHamster 2019-09-09 17:56:30 +02:00
parent a6e131a542
commit 6dfff544e4
3 changed files with 68 additions and 1 deletions

View File

@ -1,6 +1,7 @@
package de.test.antennapod;
import android.content.Context;
import android.content.SharedPreferences;
import android.support.annotation.StringRes;
import android.support.test.InstrumentationRegistry;
import android.support.test.espresso.PerformException;
@ -15,6 +16,7 @@ import de.danoeh.antennapod.R;
import de.danoeh.antennapod.activity.MainActivity;
import de.danoeh.antennapod.core.storage.PodDBAdapter;
import de.danoeh.antennapod.dialog.RatingDialog;
import de.danoeh.antennapod.fragment.QueueFragment;
import org.hamcrest.Matcher;
import java.io.File;
@ -97,6 +99,13 @@ public class EspressoTestUtils {
RatingDialog.saveRated();
}
public static void setLastNavFragment(String tag) {
InstrumentationRegistry.getTargetContext().getSharedPreferences(MainActivity.PREF_NAME, Context.MODE_PRIVATE)
.edit()
.putString(MainActivity.PREF_LAST_FRAGMENT_TAG, tag)
.commit();
}
public static void clearDatabase() {
PodDBAdapter.init(InstrumentationRegistry.getTargetContext());
PodDBAdapter.deleteDatabase();

View File

@ -0,0 +1,58 @@
package de.test.antennapod.ui;
import android.content.Intent;
import android.support.test.espresso.Espresso;
import android.support.test.espresso.intent.rule.IntentsTestRule;
import android.support.test.runner.AndroidJUnit4;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.activity.MainActivity;
import de.danoeh.antennapod.fragment.QueueFragment;
import de.test.antennapod.EspressoTestUtils;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.matcher.ViewMatchers.withContentDescription;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
/**
* User interface tests for queue fragment
*/
@RunWith(AndroidJUnit4.class)
public class QueueFragmentTest {
@Rule
public IntentsTestRule<MainActivity> mActivityRule = new IntentsTestRule<>(MainActivity.class, false, false);
@Before
public void setUp() {
EspressoTestUtils.clearPreferences();
EspressoTestUtils.makeNotFirstRun();
EspressoTestUtils.clearDatabase();
EspressoTestUtils.setLastNavFragment(QueueFragment.TAG);
mActivityRule.launchActivity(new Intent());
}
@Test
public void testLockEmptyQueue() {
onView(withContentDescription(R.string.lock_queue)).perform(click());
onView(withContentDescription(R.string.unlock_queue)).perform(click());
}
@Test
public void testSortEmptyQueue() {
Espresso.openContextualActionModeOverflowMenu();
onView(withText(R.string.sort)).perform(click());
onView(withText(R.string.random)).perform(click());
}
@Test
public void testKeepEmptyQueueSorted() {
Espresso.openContextualActionModeOverflowMenu();
onView(withText(R.string.sort)).perform(click());
onView(withText(R.string.keep_sorted)).perform(click());
}
}

View File

@ -87,7 +87,7 @@ public class MainActivity extends CastEnabledActivity implements NavDrawerActivi
public static final String PREF_NAME = "MainActivityPrefs";
public static final String PREF_IS_FIRST_LAUNCH = "prefMainActivityIsFirstLaunch";
private static final String PREF_LAST_FRAGMENT_TAG = "prefMainActivityLastFragmentTag";
public static final String PREF_LAST_FRAGMENT_TAG = "prefMainActivityLastFragmentTag";
public static final String EXTRA_NAV_TYPE = "nav_type";
public static final String EXTRA_NAV_INDEX = "nav_index";