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();
}
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));
}
});
}
Aggregations