Search in sources :

Example 11 with WebItem

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();
}
Also used : ConnectivityManager(android.net.ConnectivityManager) Bundle(android.os.Bundle) TestWebItem(io.github.hidroh.materialistic.test.TestWebItem) WebItem(io.github.hidroh.materialistic.data.WebItem) TestReadabilityActivity(io.github.hidroh.materialistic.test.TestReadabilityActivity) TestWebItem(io.github.hidroh.materialistic.test.TestWebItem) Before(org.junit.Before)

Example 12 with WebItem

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));
}
Also used : KeyEvent(android.view.KeyEvent) TestWebItem(io.github.hidroh.materialistic.test.TestWebItem) WebItem(io.github.hidroh.materialistic.data.WebItem) Intent(android.content.Intent) AppBarLayout(android.support.design.widget.AppBarLayout) TestWebItem(io.github.hidroh.materialistic.test.TestWebItem) SlowTest(io.github.hidroh.materialistic.test.suite.SlowTest) Test(org.junit.Test)

Example 13 with WebItem

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));
}
Also used : TestItem(io.github.hidroh.materialistic.test.TestItem) WebItem(io.github.hidroh.materialistic.data.WebItem) Item(io.github.hidroh.materialistic.data.Item) TestHnItem(io.github.hidroh.materialistic.data.TestHnItem) RoboMenuItem(org.robolectric.fakes.RoboMenuItem) ShadowSwipeRefreshLayout(io.github.hidroh.materialistic.test.shadow.ShadowSwipeRefreshLayout) Bundle(android.os.Bundle) WebItem(io.github.hidroh.materialistic.data.WebItem) TestHnItem(io.github.hidroh.materialistic.data.TestHnItem) Fragment(android.support.v4.app.Fragment) ShadowSwipeRefreshLayout(io.github.hidroh.materialistic.test.shadow.ShadowSwipeRefreshLayout) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) SlowTest(io.github.hidroh.materialistic.test.suite.SlowTest) Test(org.junit.Test)

Example 14 with WebItem

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();
}
Also used : Bundle(android.os.Bundle) WebItem(io.github.hidroh.materialistic.data.WebItem) Fragment(android.support.v4.app.Fragment) TestItem(io.github.hidroh.materialistic.test.TestItem) SlowTest(io.github.hidroh.materialistic.test.suite.SlowTest) Test(org.junit.Test)

Example 15 with WebItem

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());
}
Also used : Bundle(android.os.Bundle) WebItem(io.github.hidroh.materialistic.data.WebItem) Fragment(android.support.v4.app.Fragment) RoboMenuItem(org.robolectric.fakes.RoboMenuItem) SlowTest(io.github.hidroh.materialistic.test.suite.SlowTest) Test(org.junit.Test)

Aggregations

WebItem (io.github.hidroh.materialistic.data.WebItem)15 SlowTest (io.github.hidroh.materialistic.test.suite.SlowTest)8 Test (org.junit.Test)8 Bundle (android.os.Bundle)7 TestWebItem (io.github.hidroh.materialistic.test.TestWebItem)6 Intent (android.content.Intent)5 Fragment (android.support.v4.app.Fragment)4 Item (io.github.hidroh.materialistic.data.Item)4 SwipeRefreshLayout (android.support.v4.widget.SwipeRefreshLayout)2 KeyEvent (android.view.KeyEvent)2 TestItem (io.github.hidroh.materialistic.test.TestItem)2 TestReadabilityActivity (io.github.hidroh.materialistic.test.TestReadabilityActivity)2 ShadowSwipeRefreshLayout (io.github.hidroh.materialistic.test.shadow.ShadowSwipeRefreshLayout)2 Before (org.junit.Before)2 RoboMenuItem (org.robolectric.fakes.RoboMenuItem)2 PendingIntent (android.app.PendingIntent)1 Context (android.content.Context)1 ConnectivityManager (android.net.ConnectivityManager)1 CustomTabsIntent (android.support.customtabs.CustomTabsIntent)1 AppBarLayout (android.support.design.widget.AppBarLayout)1