diff options
-rw-r--r-- | src/de/danoeh/antennapod/activity/MainActivity.java | 4 | ||||
-rw-r--r-- | src/instrumentationTest/de/test/antennapod/ui/MainActivityTest.java | 86 |
2 files changed, 88 insertions, 2 deletions
diff --git a/src/de/danoeh/antennapod/activity/MainActivity.java b/src/de/danoeh/antennapod/activity/MainActivity.java index 92afea77c..898897bd8 100644 --- a/src/de/danoeh/antennapod/activity/MainActivity.java +++ b/src/de/danoeh/antennapod/activity/MainActivity.java @@ -41,8 +41,8 @@ public class MainActivity extends ActionBarActivity { | EventDistributor.FEED_LIST_UPDATE | EventDistributor.UNREAD_ITEMS_UPDATE; - private static final String PREF_NAME = "MainActivityPrefs"; - private static final String PREF_IS_FIRST_LAUNCH = "prefMainActivityIsFirstLaunch"; + public static final String PREF_NAME = "MainActivityPrefs"; + public static final String PREF_IS_FIRST_LAUNCH = "prefMainActivityIsFirstLaunch"; public static final String EXTRA_NAV_INDEX = "nav_index"; public static final String EXTRA_NAV_TYPE = "nav_type"; diff --git a/src/instrumentationTest/de/test/antennapod/ui/MainActivityTest.java b/src/instrumentationTest/de/test/antennapod/ui/MainActivityTest.java index 319664806..26f38da98 100644 --- a/src/instrumentationTest/de/test/antennapod/ui/MainActivityTest.java +++ b/src/instrumentationTest/de/test/antennapod/ui/MainActivityTest.java @@ -1,8 +1,18 @@ package instrumentationTest.de.test.antennapod.ui; +import android.content.Context; +import android.content.SharedPreferences; +import android.content.res.Resources; import android.test.ActivityInstrumentationTestCase2; +import android.view.View; import com.robotium.solo.Solo; +import de.danoeh.antennapod.R; +import de.danoeh.antennapod.activity.DefaultOnlineFeedViewActivity; import de.danoeh.antennapod.activity.MainActivity; +import de.danoeh.antennapod.activity.PreferenceActivity; +import de.danoeh.antennapod.feed.EventDistributor; +import de.danoeh.antennapod.feed.Feed; +import de.danoeh.antennapod.storage.PodDBAdapter; /** * User interface tests for MainActivity @@ -22,13 +32,89 @@ public class MainActivityTest extends ActivityInstrumentationTestCase2<MainActiv solo = new Solo(getInstrumentation(), getActivity()); uiTestUtils = new UITestUtils(getInstrumentation().getTargetContext()); uiTestUtils.setup(); + // create database + PodDBAdapter adapter = new PodDBAdapter(getInstrumentation().getTargetContext()); + adapter.open(); + adapter.close(); + + // override first launch preference + SharedPreferences prefs = getInstrumentation().getTargetContext().getSharedPreferences(MainActivity.PREF_NAME, Context.MODE_PRIVATE); + prefs.edit().putBoolean(MainActivity.PREF_IS_FIRST_LAUNCH, false).commit(); } @Override protected void tearDown() throws Exception { uiTestUtils.tearDown(); + solo.finishOpenedActivities(); + PodDBAdapter.deleteDatabase(getInstrumentation().getTargetContext()); super.tearDown(); } + public void testAddFeed() throws Exception { + uiTestUtils.addHostedFeedData(); + final Feed feed = uiTestUtils.hostedFeeds.get(0); + solo.setNavigationDrawer(Solo.OPENED); + solo.clickOnText(solo.getString(R.string.add_feed_label)); + solo.enterText(0, feed.getDownload_url()); + solo.clickOnButton(0); + solo.waitForActivity(DefaultOnlineFeedViewActivity.class); + solo.waitForView(R.id.butSubscribe); + assertEquals(solo.getString(R.string.subscribe_label), solo.getButton(0).getText().toString()); + solo.clickOnButton(0); + solo.waitForText(solo.getString(R.string.subscribed_label)); + } + + public void testClickNavDrawer() throws Exception { + uiTestUtils.addLocalFeedData(false); + EventDistributor.getInstance().sendFeedUpdateBroadcast(); + EventDistributor.getInstance().sendQueueUpdateBroadcast(); + + final View home = solo.getView(android.R.id.home); + + // all episodes + solo.waitForView(android.R.id.list); + assertEquals(solo.getString(R.string.all_episodes_label), getActionbarTitle()); + // queue + solo.clickOnView(home); + solo.clickOnText(solo.getString(R.string.queue_label)); + solo.waitForView(android.R.id.list); + assertEquals(solo.getString(R.string.queue_label), getActionbarTitle()); + + // downloads + solo.clickOnView(home); + solo.clickOnText(solo.getString(R.string.downloads_label)); + solo.waitForView(android.R.id.list); + assertEquals(solo.getString(R.string.downloads_label), getActionbarTitle()); + + // playback history + solo.clickOnView(home); + solo.clickOnText(solo.getString(R.string.playback_history_label)); + solo.waitForView(android.R.id.list); + assertEquals(solo.getString(R.string.playback_history_label), getActionbarTitle()); + // add podcast + solo.clickOnView(home); + solo.clickOnText(solo.getString(R.string.add_feed_label)); + solo.waitForView(R.id.txtvFeedurl); + assertEquals(solo.getString(R.string.add_feed_label), getActionbarTitle()); + + // podcasts + for (int i = 0; i < uiTestUtils.hostedFeeds.size(); i++) { + Feed f = uiTestUtils.hostedFeeds.get(i); + solo.clickOnView(home); + solo.clickOnText(f.getTitle()); + solo.waitForView(android.R.id.list); + assertEquals("", getActionbarTitle()); + } + } + + private String getActionbarTitle() { + return ((MainActivity)solo.getCurrentActivity()).getMainActivtyActionBar().getTitle().toString(); + } + + public void testGoToPreferences() { + solo.setNavigationDrawer(Solo.CLOSED); + solo.clickOnMenuItem(solo.getString(R.string.settings_label)); + solo.waitForActivity(PreferenceActivity.class); + } } |