Search in sources :

Example 11 with TestHnItem

use of io.github.hidroh.materialistic.data.TestHnItem in project materialistic by hidroh.

the class BaseListActivityLandTest method testScrollItemToTop.

@Config(shadows = ShadowRecyclerView.class)
@Test
public void testScrollItemToTop() {
    activity.onItemSelected(new TestHnItem(1L) {

        @NonNull
        @Override
        public String getType() {
            return STORY_TYPE;
        }
    });
    TabLayout tabLayout = (TabLayout) activity.findViewById(R.id.tab_layout);
    assertThat(tabLayout.getTabCount()).isEqualTo(2);
    tabLayout.getTabAt(0).select();
    ViewPager viewPager = (ViewPager) activity.findViewById(R.id.content);
    viewPager.getAdapter().instantiateItem(viewPager, 0);
    viewPager.getAdapter().finishUpdate(viewPager);
    RecyclerView itemRecyclerView = (RecyclerView) viewPager.findViewById(R.id.recycler_view);
    itemRecyclerView.smoothScrollToPosition(1);
    assertThat(customShadowOf(itemRecyclerView).getScrollPosition()).isEqualTo(1);
    tabLayout.getTabAt(1).select();
    tabLayout.getTabAt(0).select();
    tabLayout.getTabAt(0).select();
    assertThat(customShadowOf(itemRecyclerView).getScrollPosition()).isEqualTo(0);
}
Also used : TabLayout(android.support.design.widget.TabLayout) NonNull(android.support.annotation.NonNull) RecyclerView(android.support.v7.widget.RecyclerView) ShadowRecyclerView(io.github.hidroh.materialistic.test.shadow.ShadowRecyclerView) TestHnItem(io.github.hidroh.materialistic.data.TestHnItem) ViewPager(android.support.v4.view.ViewPager) Test(org.junit.Test) SlowTest(io.github.hidroh.materialistic.test.suite.SlowTest) Config(org.robolectric.annotation.Config)

Example 12 with TestHnItem

use of io.github.hidroh.materialistic.data.TestHnItem in project materialistic by hidroh.

the class BaseListActivityLandTest method testSelectItemOpenStory.

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Test
public void testSelectItemOpenStory() {
    assertThat(activity.findViewById(R.id.empty_selection)).isVisible();
    activity.onItemSelected(new TestHnItem(1L) {

        @NonNull
        @Override
        public String getType() {
            return STORY_TYPE;
        }

        @Override
        public String getUrl() {
            return "http://example.com";
        }
    });
    assertThat(activity.findViewById(R.id.empty_selection)).isNotVisible();
    assertStoryMode();
    shadowOf(activity).clickMenuItem(R.id.menu_share);
    PopupMenu popupMenu = ShadowPopupMenu.getLatestPopupMenu();
    assertNotNull(popupMenu);
    assertThat(popupMenu.getMenu()).hasItem(R.id.menu_article).hasItem(R.id.menu_comments);
    shadowOf(activity).clickMenuItem(R.id.menu_external);
    assertNotNull(ShadowPopupMenu.getLatestPopupMenu());
}
Also used : NonNull(android.support.annotation.NonNull) TestHnItem(io.github.hidroh.materialistic.data.TestHnItem) PopupMenu(android.widget.PopupMenu) ShadowPopupMenu(org.robolectric.shadows.ShadowPopupMenu) Test(org.junit.Test) SlowTest(io.github.hidroh.materialistic.test.suite.SlowTest) TargetApi(android.annotation.TargetApi)

Example 13 with TestHnItem

use of io.github.hidroh.materialistic.data.TestHnItem in project materialistic by hidroh.

the class BaseListActivityLandTest method testBackPressed.

@Test
public void testBackPressed() {
    activity.onItemSelected(new TestHnItem(1L) {

        @NonNull
        @Override
        public String getType() {
            return STORY_TYPE;
        }
    });
    activity.onKeyDown(KeyEvent.KEYCODE_BACK, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK));
    verify(keyDelegate).setBackInterceptor(any(KeyDelegate.BackInterceptor.class));
    verify(keyDelegate).onKeyDown(anyInt(), any(KeyEvent.class));
}
Also used : KeyEvent(android.view.KeyEvent) NonNull(android.support.annotation.NonNull) TestHnItem(io.github.hidroh.materialistic.data.TestHnItem) Test(org.junit.Test) SlowTest(io.github.hidroh.materialistic.test.suite.SlowTest)

Example 14 with TestHnItem

use of io.github.hidroh.materialistic.data.TestHnItem in project materialistic by hidroh.

the class BaseListActivityLandTest 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();
    controller.pause().resume();
    activity.onItemSelected(new TestHnItem(1L) {

        @NonNull
        @Override
        public String getType() {
            return STORY_TYPE;
        }
    });
    ViewPager viewPager = (ViewPager) activity.findViewById(R.id.content);
    viewPager.getAdapter().instantiateItem(viewPager, viewPager.getCurrentItem());
    assertStoryMode();
}
Also used : NonNull(android.support.annotation.NonNull) TestHnItem(io.github.hidroh.materialistic.data.TestHnItem) ViewPager(android.support.v4.view.ViewPager) Test(org.junit.Test) SlowTest(io.github.hidroh.materialistic.test.suite.SlowTest)

Example 15 with TestHnItem

use of io.github.hidroh.materialistic.data.TestHnItem in project materialistic by hidroh.

the class UserActivityTest method testCommentBinding.

@Test
public void testCommentBinding() {
    verify(userManager).getUser(eq("username"), userCaptor.capture());
    userCaptor.getValue().onResponse(user);
    RecyclerView recyclerView = (RecyclerView) activity.findViewById(R.id.recycler_view);
    verify(itemManager).getItem(eq("1"), eq(ItemManager.MODE_DEFAULT), itemCaptor.capture());
    itemCaptor.getValue().onResponse(new TestHnItem(1L) {

        @Override
        public String getText() {
            return "content";
        }

        @Override
        public String getParent() {
            return "2";
        }
    });
    RecyclerView.ViewHolder viewHolder = customShadowOf(recyclerView.getAdapter()).getViewHolder(0);
    assertThat(viewHolder.itemView.findViewById(R.id.title)).isNotVisible();
    assertThat((TextView) viewHolder.itemView.findViewById(R.id.text)).isVisible().hasTextString("content");
    viewHolder.itemView.findViewById(R.id.comment).performClick();
    assertThat(shadowOf(activity).getNextStartedActivity()).hasComponent(activity, ThreadPreviewActivity.class).hasExtra(ThreadPreviewActivity.EXTRA_ITEM);
}
Also used : RecyclerView(android.support.v7.widget.RecyclerView) ShadowRecyclerView(io.github.hidroh.materialistic.test.shadow.ShadowRecyclerView) TestHnItem(io.github.hidroh.materialistic.data.TestHnItem) Test(org.junit.Test)

Aggregations

TestHnItem (io.github.hidroh.materialistic.data.TestHnItem)35 Test (org.junit.Test)31 SlowTest (io.github.hidroh.materialistic.test.suite.SlowTest)23 RecyclerView (android.support.v7.widget.RecyclerView)12 TextView (android.widget.TextView)9 Intent (android.content.Intent)8 Bundle (android.os.Bundle)8 NonNull (android.support.annotation.NonNull)8 ShadowRecyclerView (io.github.hidroh.materialistic.test.shadow.ShadowRecyclerView)8 ShadowSwipeRefreshLayout (io.github.hidroh.materialistic.test.shadow.ShadowSwipeRefreshLayout)6 Context (android.content.Context)5 TestItem (io.github.hidroh.materialistic.test.TestItem)5 Before (org.junit.Before)4 Fragment (android.support.v4.app.Fragment)3 View (android.view.View)3 HackerNewsClient (io.github.hidroh.materialistic.data.HackerNewsClient)3 Item (io.github.hidroh.materialistic.data.Item)3 WebItem (io.github.hidroh.materialistic.data.WebItem)3 RoboMenuItem (org.robolectric.fakes.RoboMenuItem)3 ShadowContentObserver (org.robolectric.shadows.ShadowContentObserver)3