use of io.github.hidroh.materialistic.test.TestItem in project materialistic by hidroh.
the class ItemActivityTest method testDefaultReadabilityView.
@Test
public void testDefaultReadabilityView() {
PreferenceManager.getDefaultSharedPreferences(activity).edit().putString(activity.getString(R.string.pref_story_display), activity.getString(R.string.pref_story_display_value_readability)).apply();
Intent intent = new Intent();
intent.putExtra(ItemActivity.EXTRA_ITEM, new TestItem() {
@NonNull
@Override
public String getType() {
return STORY_TYPE;
}
@Override
public String getId() {
return "1";
}
@Override
public boolean isStoryType() {
return true;
}
@Override
public int getKidCount() {
return 10;
}
@Override
public String getUrl() {
return "http://example.com";
}
});
controller.withIntent(intent).create().start().resume();
TabLayout tabLayout = (TabLayout) activity.findViewById(R.id.tab_layout);
assertEquals(2, tabLayout.getTabCount());
assertEquals(1, tabLayout.getSelectedTabPosition());
}
use of io.github.hidroh.materialistic.test.TestItem in project materialistic by hidroh.
the class ItemActivityTest method testShare.
@SuppressLint("NewApi")
@Test
public void testShare() {
TestApplication.addResolver(new Intent(Intent.ACTION_SEND));
Intent intent = new Intent();
intent.putExtra(ItemActivity.EXTRA_ITEM, new TestItem() {
@NonNull
@Override
public String getType() {
return STORY_TYPE;
}
@Override
public String getUrl() {
return "http://example.com";
}
@Override
public boolean isStoryType() {
return true;
}
@Override
public String getId() {
return "1";
}
});
controller.withIntent(intent).create().start().resume();
// inflate menu, see https://github.com/robolectric/robolectric/issues/1326
ShadowLooper.pauseMainLooper();
controller.visible();
ShadowApplication.getInstance().getForegroundThreadScheduler().advanceToLastPostedRunnable();
// share article
shadowOf(activity).clickMenuItem(R.id.menu_share);
shadowOf(ShadowPopupMenu.getLatestPopupMenu()).getOnMenuItemClickListener().onMenuItemClick(new RoboMenuItem(R.id.menu_article));
ShadowApplication.getInstance().getForegroundThreadScheduler().advanceToLastPostedRunnable();
Intent actual = shadowOf(activity).getNextStartedActivity();
assertThat(actual).hasAction(Intent.ACTION_SEND);
// share item
shadowOf(activity).clickMenuItem(R.id.menu_share);
shadowOf(ShadowPopupMenu.getLatestPopupMenu()).getOnMenuItemClickListener().onMenuItemClick(new RoboMenuItem(R.id.menu_comments));
ShadowApplication.getInstance().getForegroundThreadScheduler().advanceToLastPostedRunnable();
actual = shadowOf(activity).getNextStartedActivity();
assertThat(actual).hasAction(Intent.ACTION_SEND);
}
use of io.github.hidroh.materialistic.test.TestItem in project materialistic by hidroh.
the class ItemActivityTest method startWithIntent.
private void startWithIntent() {
Intent intent = new Intent();
intent.putExtra(ItemActivity.EXTRA_ITEM, new TestItem() {
@NonNull
@Override
public String getType() {
return STORY_TYPE;
}
@Override
public String getUrl() {
return "http://example.com";
}
@Override
public boolean isStoryType() {
return true;
}
@Override
public String getId() {
return "1";
}
});
controller.withIntent(intent).create().start().resume().visible();
}
use of io.github.hidroh.materialistic.test.TestItem in project materialistic by hidroh.
the class ItemActivityTest method testHeaderOpenExternal.
@Test
public void testHeaderOpenExternal() {
PreferenceManager.getDefaultSharedPreferences(activity).edit().putBoolean(activity.getString(R.string.pref_custom_tab), false).apply();
TestApplication.addResolver(new Intent(Intent.ACTION_VIEW, Uri.parse("http://example.com")));
Intent intent = new Intent();
intent.putExtra(ItemActivity.EXTRA_ITEM, new TestItem() {
@NonNull
@Override
public String getType() {
return STORY_TYPE;
}
@Override
public String getUrl() {
return "http://example.com";
}
@Override
public boolean isStoryType() {
return true;
}
@Override
public String getId() {
return "1";
}
});
PreferenceManager.getDefaultSharedPreferences(activity).edit().putBoolean(activity.getString(R.string.pref_external), true).apply();
controller.withIntent(intent).create().start().resume();
activity.findViewById(R.id.button_article).performClick();
assertThat(shadowOf(activity).getNextStartedActivity()).hasAction(Intent.ACTION_VIEW);
}
use of io.github.hidroh.materialistic.test.TestItem in project materialistic by hidroh.
the class ItemFragmentMultiPageTest method testWebItem.
@Test
public void testWebItem() {
WebItem webItem = mock(WebItem.class);
when(webItem.getId()).thenReturn("1");
Bundle args = new Bundle();
args.putParcelable(ItemFragment.EXTRA_ITEM, webItem);
Fragment fragment = Fragment.instantiate(RuntimeEnvironment.application, ItemFragment.class.getName(), args);
makeVisible(fragment);
verify(hackerNewsClient).getItem(eq("1"), eq(ItemManager.MODE_DEFAULT), listener.capture());
listener.getValue().onResponse(new TestItem() {
@Override
public Item[] getKidItems() {
return new Item[] { new TestItem() {
} };
}
@Override
public int getKidCount() {
return 1;
}
});
assertThat(fragment.getView().findViewById(R.id.empty)).isNotVisible();
}
Aggregations