use of io.github.hidroh.materialistic.data.WebItem in project materialistic by hidroh.
the class ReadabilityFragmentTest method setUp.
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
TestApplication.applicationGraph.inject(this);
reset(readabilityClient);
controller = Robolectric.buildActivity(TestReadabilityActivity.class);
activity = controller.create().start().resume().visible().get();
PreferenceManager.getDefaultSharedPreferences(activity).edit().putBoolean(activity.getString(R.string.pref_lazy_load), false).putString(activity.getString(R.string.pref_story_display), activity.getString(R.string.pref_story_display_value_readability)).apply();
shadowOf((ConnectivityManager) activity.getSystemService(Context.CONNECTIVITY_SERVICE)).setActiveNetworkInfo(ShadowNetworkInfo.newInstance(null, ConnectivityManager.TYPE_WIFI, 0, true, true));
Bundle args = new Bundle();
WebItem item = new TestWebItem() {
@Override
public String getId() {
return "1";
}
@Override
public String getUrl() {
return "http://example.com/article.html";
}
};
args.putParcelable(WebFragment.EXTRA_ITEM, item);
fragment = (WebFragment) Fragment.instantiate(activity, WebFragment.class.getName(), args);
activity.getSupportFragmentManager().beginTransaction().replace(R.id.content_frame, fragment, "tag").commit();
}
use of io.github.hidroh.materialistic.data.WebItem in project materialistic by hidroh.
the class ItemActivityTest method testVolumeNavigation.
@Test
public void testVolumeNavigation() {
Intent intent = new Intent();
WebItem webItem = new TestWebItem() {
@Override
public String getUrl() {
return "http://example.com";
}
@Override
public String getId() {
return "1";
}
};
intent.putExtra(ItemActivity.EXTRA_ITEM, webItem);
controller.withIntent(intent).create().start().resume().visible();
activity.onKeyDown(KeyEvent.KEYCODE_VOLUME_UP, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_VOLUME_UP));
verify(keyDelegate).setScrollable(any(Scrollable.class), any(AppBarLayout.class));
verify(keyDelegate).onKeyDown(anyInt(), any(KeyEvent.class));
activity.onKeyUp(KeyEvent.KEYCODE_VOLUME_UP, new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_VOLUME_UP));
verify(keyDelegate).onKeyUp(anyInt(), any(KeyEvent.class));
activity.onKeyLongPress(KeyEvent.KEYCODE_VOLUME_UP, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_VOLUME_UP));
verify(keyDelegate).onKeyLongPress(anyInt(), any(KeyEvent.class));
}
use of io.github.hidroh.materialistic.data.WebItem in project materialistic by hidroh.
the class ItemFragmentMultiPageTest method testRefresh.
@Test
public void testRefresh() {
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);
ShadowSwipeRefreshLayout shadowSwipeRefreshLayout = (ShadowSwipeRefreshLayout) ShadowExtractor.extract(fragment.getView().findViewById(R.id.swipe_layout));
shadowSwipeRefreshLayout.getOnRefreshListener().onRefresh();
verify(hackerNewsClient).getItem(eq("1"), eq(ItemManager.MODE_DEFAULT), listener.capture());
verify(hackerNewsClient).getItem(eq("1"), eq(ItemManager.MODE_NETWORK), listener.capture());
listener.getAllValues().get(1).onResponse(new TestHnItem(1L));
assertThat((SwipeRefreshLayout) fragment.getView().findViewById(R.id.swipe_layout)).isNotRefreshing();
verify(((TestItemActivity) fragment.getActivity()).itemChangedListener).onItemChanged(any(Item.class));
}
use of io.github.hidroh.materialistic.data.WebItem 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();
}
use of io.github.hidroh.materialistic.data.WebItem in project materialistic by hidroh.
the class ItemFragmentMultiPageTest method testDisplayMenu.
@Test
public void testDisplayMenu() {
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);
fragment.onOptionsItemSelected(new RoboMenuItem(R.id.menu_comments));
assertThat(fragment.getFragmentManager()).hasFragmentWithTag(PopupSettingsFragment.class.getName());
}
Aggregations