@Test public void testJob() { item.populate(new PopulatedStory(1) { @Override public String getRawType() { return JOB_TYPE; } }); verify(itemManager).getItem(any(), eq(ItemManager.MODE_DEFAULT), itemListener.capture()); itemListener.getValue().onResponse(item); RecyclerView.ViewHolder holder = adapter.getViewHolder(0); assertThat((TextView) holder.itemView.findViewById(R.id.source)).isEmpty(); }
@Test public void testPoll() { item.populate(new PopulatedStory(1) { @Override public String getRawType() { return POLL_TYPE; } }); verify(itemManager).getItem(any(), eq(ItemManager.MODE_DEFAULT), itemListener.capture()); itemListener.getValue().onResponse(item); RecyclerView.ViewHolder holder = adapter.getViewHolder(0); assertThat((TextView) holder.itemView.findViewById(R.id.source)).isEmpty(); }
@Test public void testStory() { item.setIsViewed(true); verify(itemManager).getItem(any(), eq(ItemManager.MODE_DEFAULT), itemListener.capture()); itemListener.getValue().onResponse(item); RecyclerView.ViewHolder holder = adapter.getViewHolder(0); assertThat((View) holder.itemView.findViewById(R.id.bookmarked)).isNotVisible(); assertThat((TextView) holder.itemView.findViewById(R.id.rank)).hasTextString("46"); assertThat((TextView) holder.itemView.findViewById(R.id.title)).hasTextString("title"); assertThat((TextView) holder.itemView.findViewById(R.id.comment)) .isVisible() .isEmpty(); assertViewed(); }
@Test public void testDeriveNoMatches() { controller.pause().stop().destroy(); controller = Robolectric.buildActivity(SubmitActivity.class, new Intent().putExtra(Intent.EXTRA_TEXT, "title - http://example.com blah blah")); activity = controller .create().start().resume().visible().get(); assertThat((EditText) activity.findViewById(R.id.edittext_title)).isEmpty(); assertThat((EditText) activity.findViewById(R.id.edittext_content)) .hasTextString("title - http://example.com blah blah"); }
@Test public void testDeriveEmptyTitle() { controller.pause().stop().destroy(); controller = Robolectric.buildActivity(SubmitActivity.class, new Intent().putExtra(Intent.EXTRA_TEXT, " : http://example.com")); activity = controller .create().start().resume().visible().get(); assertThat((EditText) activity.findViewById(R.id.edittext_title)).isEmpty(); assertThat((EditText) activity.findViewById(R.id.edittext_content)).hasTextString("http://example.com"); }
@Test public void testSearch() { ShadowLocalBroadcastManager.getInstance(activity) .sendBroadcast(new Intent(WebFragment.ACTION_FULLSCREEN) .putExtra(WebFragment.EXTRA_FULLSCREEN, true)); activity.findViewById(R.id.button_find).performClick(); ViewSwitcher controlSwitcher = activity.findViewById(R.id.control_switcher); assertThat(controlSwitcher.getDisplayedChild()).isEqualTo(1); ShadowWebView shadowWebView = Shadow.extract(activity.findViewById(R.id.web_view)); // no query EditText editText = activity.findViewById(R.id.edittext); shadowOf(editText).getOnEditorActionListener().onEditorAction(null, 0, null); assertThat((View) activity.findViewById(R.id.button_next)).isDisabled(); // with results shadowWebView.setFindCount(1); editText.setText("abc"); shadowOf(editText).getOnEditorActionListener().onEditorAction(null, 0, null); assertThat((View) activity.findViewById(R.id.button_next)).isEnabled(); activity.findViewById(R.id.button_next).performClick(); assertThat(shadowWebView.getFindIndex()).isEqualTo(1); activity.findViewById(R.id.button_clear).performClick(); assertThat(editText).isEmpty(); assertThat(controlSwitcher.getDisplayedChild()).isEqualTo(0); // with no results shadowWebView.setFindCount(0); editText.setText("abc"); shadowOf(editText).getOnEditorActionListener().onEditorAction(null, 0, null); assertThat((View) activity.findViewById(R.id.button_next)).isDisabled(); assertThat(ShadowToast.getTextOfLatestToast()).contains(activity.getString(R.string.no_matches)); }