Search in sources :

Example 6 with TestWebItem

use of io.github.hidroh.materialistic.test.TestWebItem 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 7 with TestWebItem

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

the class WebFragmentLocalTest method testStory.

@Test
public void testStory() {
    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";
        }
    });
    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");
}
Also used : ShadowWebView(org.robolectric.shadows.ShadowWebView) Intent(android.content.Intent) WebView(android.webkit.WebView) ShadowWebView(org.robolectric.shadows.ShadowWebView) TestWebItem(io.github.hidroh.materialistic.test.TestWebItem) TestItem(io.github.hidroh.materialistic.test.TestItem) Test(org.junit.Test)

Example 8 with TestWebItem

use of io.github.hidroh.materialistic.test.TestWebItem 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 9 with TestWebItem

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

the class ReadabilityFragmentLazyLoadTest method setUp.

@Before
public void setUp() {
    TestApplication.applicationGraph.inject(this);
    reset(readabilityClient);
    controller = Robolectric.buildActivity(TestReadabilityActivity.class);
    activity = controller.create().start().resume().visible().get();
    PreferenceManager.getDefaultSharedPreferences(activity).edit().putString(activity.getString(R.string.pref_story_display), activity.getString(R.string.pref_story_display_value_readability)).apply();
    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);
}
Also used : 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 10 with TestWebItem

use of io.github.hidroh.materialistic.test.TestWebItem 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)

Aggregations

TestWebItem (io.github.hidroh.materialistic.test.TestWebItem)15 Test (org.junit.Test)13 Intent (android.content.Intent)10 SlowTest (io.github.hidroh.materialistic.test.suite.SlowTest)10 WebItem (io.github.hidroh.materialistic.data.WebItem)6 RobolectricPackageManager (org.robolectric.res.builder.RobolectricPackageManager)3 ConnectivityManager (android.net.ConnectivityManager)2 Bundle (android.os.Bundle)2 KeyEvent (android.view.KeyEvent)2 WebView (android.webkit.WebView)2 TestItem (io.github.hidroh.materialistic.test.TestItem)2 TestReadabilityActivity (io.github.hidroh.materialistic.test.TestReadabilityActivity)2 Before (org.junit.Before)2 Config (org.robolectric.annotation.Config)2 ShadowWebView (org.robolectric.shadows.ShadowWebView)2 Account (android.accounts.Account)1 AppBarLayout (android.support.design.widget.AppBarLayout)1 Fragment (android.support.v4.app.Fragment)1 BuildConfig (io.github.hidroh.materialistic.BuildConfig)1 ShadowFloatingActionButton (io.github.hidroh.materialistic.test.shadow.ShadowFloatingActionButton)1