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");
}
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");
}
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));
}
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);
}
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();
}
Aggregations