Search in sources :

Example 6 with BaseFragmentActivity

use of org.edx.mobile.base.BaseFragmentActivity in project edx-app-android by edx.

the class BaseFragmentActivityTest method lifecycleTest.

/**
 * Testing overall lifecycle and setup
 */
@Test
public void lifecycleTest() {
    ActivityController<? extends BaseFragmentActivity> controller = Robolectric.buildActivity(getActivityClass()).withIntent(getIntent());
    BaseFragmentActivity activity = controller.get();
    ShadowActivity shadowActivity = Shadows.shadowOf(activity);
    controller.create().start();
    // Action bar state initialization
    ActionBar bar = activity.getSupportActionBar();
    if (bar != null) {
        int displayOptions = bar.getDisplayOptions();
        assertTrue((displayOptions & ActionBar.DISPLAY_HOME_AS_UP) > 0);
        assertTrue((displayOptions & ActionBar.DISPLAY_SHOW_HOME) > 0);
        assertTrue(null == activity.findViewById(android.R.id.home));
    }
    controller.postCreate(null).resume().postResume().visible();
    DrawerLayout mDrawerLayout = (DrawerLayout) activity.findViewById(R.id.drawer_layout);
    boolean hasDrawer = hasDrawer();
    if (mDrawerLayout != null) {
        // NavigationFragment initialization
        FragmentManager fragmentManager = activity.getSupportFragmentManager();
        fragmentManager.executePendingTransactions();
        assert fragmentManager.findFragmentByTag("NavigationFragment") != null;
        if (hasDrawer) {
            CharSequence contentDescription = activity.findViewById(android.R.id.home).getContentDescription();
            assertFalse(mDrawerLayout.isDrawerOpen(GravityCompat.START));
            assertEquals(activity.getText(R.string.label_close), contentDescription);
            mDrawerLayout.openDrawer(GravityCompat.START);
            assertTrue(mDrawerLayout.isDrawerOpen(GravityCompat.START));
            assertEquals(activity.getText(R.string.label_close), contentDescription);
            activity.closeDrawer();
            assertFalse(mDrawerLayout.isDrawerOpen(GravityCompat.START));
            assertEquals(activity.getText(R.string.label_close), contentDescription);
            mDrawerLayout.openDrawer(GravityCompat.START);
            assertTrue(mDrawerLayout.isDrawerOpen(GravityCompat.START));
            assertEquals(activity.getText(R.string.label_close), contentDescription);
            Configuration config = activity.getResources().getConfiguration();
            assertNotEquals(Configuration.ORIENTATION_LANDSCAPE, config.orientation);
            config.orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
            activity.onConfigurationChanged(config);
            assertTrue(mDrawerLayout.isDrawerOpen(GravityCompat.START));
            assertEquals(activity.getText(R.string.label_close), contentDescription);
        }
    }
    // Action bar home button
    assertTrue(shadowActivity.clickMenuItem(android.R.id.home));
    if (hasDrawer) {
        assertNotNull(mDrawerLayout);
        assertTrue(mDrawerLayout.isDrawerOpen(GravityCompat.START));
        assertTrue(shadowActivity.clickMenuItem(android.R.id.home));
        assertFalse(mDrawerLayout.isDrawerOpen(GravityCompat.START));
        activity.finish();
    }
    assertThat(activity).isFinishing();
}
Also used : FragmentManager(android.support.v4.app.FragmentManager) BaseFragmentActivity(org.edx.mobile.base.BaseFragmentActivity) Configuration(android.content.res.Configuration) ShadowActivity(org.robolectric.shadows.ShadowActivity) DrawerLayout(android.support.v4.widget.DrawerLayout) ActionBar(android.support.v7.app.ActionBar) Test(org.junit.Test)

Example 7 with BaseFragmentActivity

use of org.edx.mobile.base.BaseFragmentActivity in project edx-app-android by edx.

the class BaseFragmentActivityTest method showInfoMessageTest.

/**
 * Testing show info method
 */
@Test
public void showInfoMessageTest() {
    final BaseFragmentActivity activity = Robolectric.buildActivity(getActivityClass()).withIntent(getIntent()).setup().get();
    TextView messageView = new TextView(activity);
    messageView.setId(R.id.flying_message);
    messageView.setVisibility(View.GONE);
    activity.addContentView(messageView, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
    assertThat(messageView).hasText("");
    final String message = "test";
    assertShowInfoMessage(activity, message, new Runnable() {

        @Override
        public void run() {
            assumeTrue(activity.showInfoMessage(message));
        }
    });
}
Also used : BaseFragmentActivity(org.edx.mobile.base.BaseFragmentActivity) ViewGroup(android.view.ViewGroup) TextView(android.widget.TextView) Test(org.junit.Test)

Aggregations

BaseFragmentActivity (org.edx.mobile.base.BaseFragmentActivity)7 Test (org.junit.Test)5 View (android.view.View)2 ViewGroup (android.view.ViewGroup)2 TextView (android.widget.TextView)2 Activity (android.app.Activity)1 Configuration (android.content.res.Configuration)1 FragmentActivity (android.support.v4.app.FragmentActivity)1 FragmentManager (android.support.v4.app.FragmentManager)1 DrawerLayout (android.support.v4.widget.DrawerLayout)1 ActionBar (android.support.v7.app.ActionBar)1 OnClickListener (android.view.View.OnClickListener)1 ImageView (android.widget.ImageView)1 ArrayList (java.util.ArrayList)1 HasDownloadEntry (org.edx.mobile.model.course.HasDownloadEntry)1 DownloadEntry (org.edx.mobile.model.db.DownloadEntry)1 AnalyticsRegistry (org.edx.mobile.module.analytics.AnalyticsRegistry)1 BulkVideosDownloadCancelledEvent (org.edx.mobile.module.storage.BulkVideosDownloadCancelledEvent)1 UserProfileActivity (org.edx.mobile.profiles.UserProfileActivity)1 ShadowActivity (org.robolectric.shadows.ShadowActivity)1