Search in sources :

Example 96 with Config

use of org.robolectric.annotation.Config in project materialistic by hidroh.

the class WebFragmentTest method testScroll.

@Config(shadows = ShadowNestedScrollView.class)
@Test
public void testScroll() {
    ShadowNestedScrollView shadowScrollView = customShadowOf((NestedScrollView) activity.findViewById(R.id.nested_scroll_view));
    WebFragment fragment = (WebFragment) activity.getSupportFragmentManager().findFragmentByTag(WebFragment.class.getName());
    fragment.scrollToNext();
    assertThat(shadowScrollView.getLastScrollDirection()).isEqualTo(View.FOCUS_DOWN);
    fragment.scrollToPrevious();
    assertThat(shadowScrollView.getLastScrollDirection()).isEqualTo(View.FOCUS_UP);
    fragment.scrollToTop();
    assertThat(shadowScrollView.getSmoothScrollY()).isEqualTo(0);
}
Also used : ShadowNestedScrollView(io.github.hidroh.materialistic.test.shadow.ShadowNestedScrollView) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 97 with Config

use of org.robolectric.annotation.Config in project materialistic by hidroh.

the class FavoriteManagerTest method testAdd.

@Config(sdk = 18)
@Test
public void testAdd() {
    PreferenceManager.getDefaultSharedPreferences(RuntimeEnvironment.application).edit().putBoolean(RuntimeEnvironment.application.getString(R.string.pref_saved_item_sync), true).putBoolean(RuntimeEnvironment.application.getString(R.string.pref_offline_article), true).apply();
    shadowOf((ConnectivityManager) RuntimeEnvironment.application.getSystemService(Context.CONNECTIVITY_SERVICE)).setActiveNetworkInfo(ShadowNetworkInfo.newInstance(null, ConnectivityManager.TYPE_WIFI, 0, true, true));
    manager.add(RuntimeEnvironment.application, new TestWebItem() {

        @Override
        public String getId() {
            return "3";
        }

        @Override
        public String getUrl() {
            return "http://newitem.com";
        }

        @Override
        public String getDisplayedTitle() {
            return "new title";
        }
    });
    assertThat(resolver.getNotifiedUris()).isNotEmpty();
    assertTrue(ShadowContentResolver.isSyncActive(new Account("Materialistic", BuildConfig.APPLICATION_ID), MaterialisticProvider.PROVIDER_AUTHORITY));
}
Also used : Account(android.accounts.Account) ConnectivityManager(android.net.ConnectivityManager) TestWebItem(io.github.hidroh.materialistic.test.TestWebItem) Test(org.junit.Test) Config(org.robolectric.annotation.Config) BuildConfig(io.github.hidroh.materialistic.BuildConfig)

Example 98 with Config

use of org.robolectric.annotation.Config in project materialistic by hidroh.

the class ItemFragmentSinglePageTest method testNavigate.

@Config(shadows = ShadowRecyclerView.class)
@Test
public void testNavigate() {
    ShadowRecyclerView shadowRecyclerView = customShadowOf(recyclerView);
    TestLayoutManager testLayout = new TestLayoutManager(activity);
    recyclerView.setLayoutManager(testLayout);
    fragment.onNavigate(Navigable.DIRECTION_DOWN);
    assertThat(shadowRecyclerView.getScrollPosition()).isEqualTo(3);
    shadowRecyclerView.getScrollListener().onScrollStateChanged(recyclerView, RecyclerView.SCROLL_STATE_IDLE);
    testLayout.firstVisiblePosition = 3;
    fragment.onNavigate(Navigable.DIRECTION_UP);
    assertThat(shadowRecyclerView.getScrollPosition()).isEqualTo(0);
    testLayout.firstVisiblePosition = 0;
    fragment.onNavigate(Navigable.DIRECTION_RIGHT);
    assertThat(shadowRecyclerView.getScrollPosition()).isEqualTo(1);
    shadowRecyclerView.getScrollListener().onScrollStateChanged(recyclerView, RecyclerView.SCROLL_STATE_IDLE);
    testLayout.firstVisiblePosition = 1;
    fragment.onNavigate(Navigable.DIRECTION_LEFT);
    assertThat(shadowRecyclerView.getScrollPosition()).isEqualTo(0);
    shadowRecyclerView.getScrollListener().onScrollStateChanged(recyclerView, RecyclerView.SCROLL_STATE_IDLE);
}
Also used : TestLayoutManager(io.github.hidroh.materialistic.test.TestLayoutManager) ShadowRecyclerView(io.github.hidroh.materialistic.test.shadow.ShadowRecyclerView) SlowTest(io.github.hidroh.materialistic.test.suite.SlowTest) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 99 with Config

use of org.robolectric.annotation.Config in project materialistic by hidroh.

the class ReadabilityFragmentTest method testScrollToTop.

@Config(shadows = ShadowNestedScrollView.class)
@Test
public void testScrollToTop() {
    NestedScrollView scrollView = (NestedScrollView) activity.findViewById(R.id.nested_scroll_view);
    scrollView.smoothScrollTo(0, 1);
    assertThat(customShadowOf(scrollView).getSmoothScrollY()).isEqualTo(1);
    fragment.scrollToTop();
    assertThat(customShadowOf(scrollView).getSmoothScrollY()).isEqualTo(0);
    controller.pause().stop().destroy();
}
Also used : NestedScrollView(android.support.v4.widget.NestedScrollView) ShadowNestedScrollView(io.github.hidroh.materialistic.test.shadow.ShadowNestedScrollView) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 100 with Config

use of org.robolectric.annotation.Config in project materialistic by hidroh.

the class BaseListActivityTest method testScrollToTop.

@Config(shadows = ShadowRecyclerView.class)
@Test
public void testScrollToTop() {
    RecyclerView recyclerView = (RecyclerView) activity.findViewById(R.id.recycler_view);
    recyclerView.smoothScrollToPosition(1);
    assertThat(customShadowOf(recyclerView).getScrollPosition()).isEqualTo(1);
    activity.findViewById(R.id.toolbar).performClick();
    assertThat(customShadowOf(recyclerView).getScrollPosition()).isEqualTo(0);
}
Also used : RecyclerView(android.support.v7.widget.RecyclerView) ShadowRecyclerView(io.github.hidroh.materialistic.test.shadow.ShadowRecyclerView) Test(org.junit.Test) SlowTest(io.github.hidroh.materialistic.test.suite.SlowTest) Config(org.robolectric.annotation.Config)

Aggregations

Config (org.robolectric.annotation.Config)158 Test (org.junit.Test)153 Intent (android.content.Intent)21 ComponentName (android.content.ComponentName)16 Bundle (android.os.Bundle)10 Activity (android.app.Activity)7 Bitmap (android.graphics.Bitmap)7 Notification (android.app.Notification)6 Button (android.widget.Button)6 TextView (android.widget.TextView)6 BuildConfig (com.firebase.ui.auth.BuildConfig)6 BuildConfig (com.onesignal.BuildConfig)6 ShadowRecyclerView (io.github.hidroh.materialistic.test.shadow.ShadowRecyclerView)6 SlowTest (io.github.hidroh.materialistic.test.suite.SlowTest)6 Properties (java.util.Properties)6 Account (android.accounts.Account)5 Network (android.net.Network)5 NetworkInfo (android.net.NetworkInfo)5 RecyclerView (android.support.v7.widget.RecyclerView)5 BitmapDrawable (android.graphics.drawable.BitmapDrawable)4