Search in sources :

Example 11 with TestItem

use of io.github.hidroh.materialistic.test.TestItem in project materialistic by hidroh.

the class WebFragmentLocalTest method testMenu.

@Test
public void testMenu() {
    TestWebItem item = new TestWebItem() {

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

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

        @Override
        public String getUrl() {
            return String.format(HackerNewsClient.WEB_ITEM_PATH, "1");
        }

        @Override
        public String getDisplayedTitle() {
            return "Ask HN";
        }
    };
    Intent intent = new Intent();
    intent.putExtra(WebActivity.EXTRA_ITEM, item);
    controller.withIntent(intent).create().start().resume().visible();
    verify(itemManager).getItem(eq("1"), eq(ItemManager.MODE_DEFAULT), listener.capture());
    listener.getValue().onResponse(new TestItem() {

        @Override
        public String getText() {
            return "text";
        }
    });
    Fragment fragment = activity.getSupportFragmentManager().findFragmentByTag(WebFragment.class.getName());
    assertTrue(fragment.hasOptionsMenu());
    fragment.onOptionsItemSelected(new RoboMenuItem(R.id.menu_font_options));
    assertNotNull(ShadowDialog.getLatestDialog());
    PreferenceManager.getDefaultSharedPreferences(activity).edit().putString(activity.getString(R.string.pref_readability_font), "DroidSans.ttf").apply();
    WebView webView = (WebView) activity.findViewById(R.id.web_view);
    ShadowWebView shadowWebView = shadowOf(webView);
    shadowWebView.getWebViewClient().onPageFinished(webView, "about:blank");
    assertThat(shadowWebView.getLastLoadDataWithBaseURL().data).contains("text").contains("DroidSans.ttf");
}
Also used : ShadowWebView(org.robolectric.shadows.ShadowWebView) Intent(android.content.Intent) WebView(android.webkit.WebView) ShadowWebView(org.robolectric.shadows.ShadowWebView) Fragment(android.support.v4.app.Fragment) RoboMenuItem(org.robolectric.fakes.RoboMenuItem) TestWebItem(io.github.hidroh.materialistic.test.TestWebItem) TestItem(io.github.hidroh.materialistic.test.TestItem) Test(org.junit.Test)

Example 12 with TestItem

use of io.github.hidroh.materialistic.test.TestItem in project materialistic by hidroh.

the class WebFragmentLocalTest method testComment.

@Test
public void testComment() {
    TestItem item = new TestItem() {

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

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

        @Override
        public String getUrl() {
            return String.format(HackerNewsClient.WEB_ITEM_PATH, "1");
        }

        @Override
        public String getText() {
            return "comment";
        }
    };
    Intent intent = new Intent();
    intent.putExtra(WebActivity.EXTRA_ITEM, item);
    controller.withIntent(intent).create().start().resume().visible();
    WebView webView = (WebView) activity.findViewById(R.id.web_view);
    ShadowWebView shadowWebView = shadowOf(webView);
    shadowWebView.getWebViewClient().onPageFinished(webView, "about:blank");
    assertThat(shadowWebView.getLastLoadDataWithBaseURL().data).contains("comment");
}
Also used : ShadowWebView(org.robolectric.shadows.ShadowWebView) Intent(android.content.Intent) WebView(android.webkit.WebView) ShadowWebView(org.robolectric.shadows.ShadowWebView) TestItem(io.github.hidroh.materialistic.test.TestItem) Test(org.junit.Test)

Example 13 with TestItem

use of io.github.hidroh.materialistic.test.TestItem in project materialistic by hidroh.

the class HackerNewsItemTest method testPopulate.

@Test
public void testPopulate() {
    item.populate(new TestItem() {

        @Override
        public String getTitle() {
            return "title";
        }

        @Override
        public String getRawType() {
            return "rawType";
        }

        @Override
        public String getRawUrl() {
            return "rawUrl";
        }

        @Override
        public long[] getKids() {
            return new long[] { 1l };
        }

        @Override
        public String getBy() {
            return "by";
        }

        @Override
        public long getTime() {
            return 1234l;
        }

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

        @Override
        public String getParent() {
            return "1";
        }

        @Override
        public boolean isDead() {
            return true;
        }

        @Override
        public boolean isDeleted() {
            return true;
        }

        @Override
        public int getDescendants() {
            return 1;
        }

        @Override
        public int getScore() {
            return 5;
        }
    });
    assertEquals("title", item.getTitle());
    assertEquals("text", item.getText());
    assertEquals("rawType", item.getRawType());
    assertEquals("rawUrl", item.getRawUrl());
    assertEquals("by", item.getBy());
    assertEquals(1234l, item.getTime());
    assertEquals(1, item.getDescendants());
    assertEquals(1, item.getLastKidCount());
    assertEquals(5, item.getScore());
    assertTrue(item.isDead());
    assertTrue(item.isDeleted());
    assertThat(item.getDisplayedAuthor(RuntimeEnvironment.application, true, 0)).contains(" - by");
    assertThat(item.getDisplayedTime(RuntimeEnvironment.application)).isNotEmpty();
    assertThat(item.getKids()).hasSize(1);
    assertEquals(1, item.getKidItems()[0].getLevel());
}
Also used : TestItem(io.github.hidroh.materialistic.test.TestItem) Test(org.junit.Test)

Example 14 with TestItem

use of io.github.hidroh.materialistic.test.TestItem in project materialistic by hidroh.

the class HackerNewsItemTest method testKidCountNoDescendants.

@Test
public void testKidCountNoDescendants() {
    item.populate(new TestItem() {

        @Override
        public long[] getKids() {
            return new long[] { 1l, 2l };
        }
    });
    assertEquals(2, item.getKidCount());
}
Also used : TestItem(io.github.hidroh.materialistic.test.TestItem) Test(org.junit.Test)

Example 15 with TestItem

use of io.github.hidroh.materialistic.test.TestItem in project materialistic by hidroh.

the class HackerNewsItemTest method testGetUrlStory.

@Test
public void testGetUrlStory() {
    item.populate(new TestItem() {

        @Override
        public String getRawType() {
            return "story";
        }

        @Override
        public String getRawUrl() {
            return "http://example.com";
        }
    });
    assertEquals("http://example.com", item.getUrl());
}
Also used : TestItem(io.github.hidroh.materialistic.test.TestItem) Test(org.junit.Test)

Aggregations

TestItem (io.github.hidroh.materialistic.test.TestItem)40 Test (org.junit.Test)38 SlowTest (io.github.hidroh.materialistic.test.suite.SlowTest)15 Intent (android.content.Intent)12 Bundle (android.os.Bundle)9 NonNull (android.support.annotation.NonNull)8 Fragment (android.support.v4.app.Fragment)7 RoboMenuItem (org.robolectric.fakes.RoboMenuItem)5 TextView (android.widget.TextView)4 TestHnItem (io.github.hidroh.materialistic.data.TestHnItem)4 RecyclerView (android.support.v7.widget.RecyclerView)3 WebView (android.webkit.WebView)3 HackerNewsClient (io.github.hidroh.materialistic.data.HackerNewsClient)3 ShadowWebView (org.robolectric.shadows.ShadowWebView)3 SuppressLint (android.annotation.SuppressLint)2 Parcel (android.os.Parcel)2 TabLayout (android.support.design.widget.TabLayout)2 Item (io.github.hidroh.materialistic.data.Item)2 ResponseListener (io.github.hidroh.materialistic.data.ResponseListener)2 WebItem (io.github.hidroh.materialistic.data.WebItem)2