Search in sources :

Example 26 with PopupMenu

use of android.widget.PopupMenu in project materialistic by hidroh.

the class ItemFragmentSinglePageTest method testVoteItemPromptToLogin.

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Test
public void testVoteItemPromptToLogin() {
    viewHolder.itemView.findViewById(R.id.button_more).performClick();
    PopupMenu popupMenu = ShadowPopupMenu.getLatestPopupMenu();
    assertNotNull(popupMenu);
    shadowOf(popupMenu).getOnMenuItemClickListener().onMenuItemClick(new RoboMenuItem(R.id.menu_contextual_vote));
    verify(userServices).voteUp(any(Context.class), any(), voteCallback.capture());
    voteCallback.getValue().onDone(false);
    assertThat(shadowOf(activity).getNextStartedActivity()).hasComponent(activity, LoginActivity.class);
}
Also used : Context(android.content.Context) RoboMenuItem(org.robolectric.fakes.RoboMenuItem) PopupMenu(android.widget.PopupMenu) ShadowPopupMenu(org.robolectric.shadows.ShadowPopupMenu) SlowTest(io.github.hidroh.materialistic.test.suite.SlowTest) Test(org.junit.Test) TargetApi(android.annotation.TargetApi)

Example 27 with PopupMenu

use of android.widget.PopupMenu in project materialistic by hidroh.

the class ListFragmentViewHolderTest method testReply.

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Test
public void testReply() {
    verify(itemManager).getItem(any(), eq(ItemManager.MODE_DEFAULT), itemListener.capture());
    itemListener.getValue().onResponse(item);
    adapter.getViewHolder(0).itemView.performLongClick();
    PopupMenu popupMenu = ShadowPopupMenu.getLatestPopupMenu();
    assertNotNull(popupMenu);
    shadowOf(popupMenu).getOnMenuItemClickListener().onMenuItemClick(new RoboMenuItem(R.id.menu_contextual_comment));
    assertThat(shadowOf(activity).getNextStartedActivity()).hasComponent(activity, ComposeActivity.class).hasExtra(ComposeActivity.EXTRA_PARENT_ID, "1");
}
Also used : RoboMenuItem(org.robolectric.fakes.RoboMenuItem) PopupMenu(android.widget.PopupMenu) ShadowPopupMenu(org.robolectric.shadows.ShadowPopupMenu) SlowTest(io.github.hidroh.materialistic.test.suite.SlowTest) Test(org.junit.Test) TargetApi(android.annotation.TargetApi)

Example 28 with PopupMenu

use of android.widget.PopupMenu in project materialistic by hidroh.

the class ListFragmentViewHolderTest method testVoteItem.

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Test
public void testVoteItem() {
    verify(itemManager).getItem(any(), eq(ItemManager.MODE_DEFAULT), itemListener.capture());
    itemListener.getValue().onResponse(item);
    adapter.getViewHolder(0).itemView.performLongClick();
    PopupMenu popupMenu = ShadowPopupMenu.getLatestPopupMenu();
    assertNotNull(popupMenu);
    assertThat(popupMenu.getMenu().findItem(R.id.menu_contextual_vote).isVisible()).isFalse();
    shadowOf(popupMenu).getOnMenuItemClickListener().onMenuItemClick(new RoboMenuItem(R.id.menu_contextual_vote));
    verify(userServices).voteUp(any(Context.class), eq(item.getId()), voteCallback.capture());
}
Also used : Context(android.content.Context) RoboMenuItem(org.robolectric.fakes.RoboMenuItem) PopupMenu(android.widget.PopupMenu) ShadowPopupMenu(org.robolectric.shadows.ShadowPopupMenu) SlowTest(io.github.hidroh.materialistic.test.suite.SlowTest) Test(org.junit.Test) TargetApi(android.annotation.TargetApi)

Example 29 with PopupMenu

use of android.widget.PopupMenu in project materialistic by hidroh.

the class ListFragmentViewHolderTest method testRefresh.

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Test
public void testRefresh() {
    verify(itemManager).getItem(any(), eq(ItemManager.MODE_DEFAULT), itemListener.capture());
    itemListener.getValue().onResponse(item);
    reset(itemManager);
    adapter.getViewHolder(0).itemView.performLongClick();
    PopupMenu popupMenu = ShadowPopupMenu.getLatestPopupMenu();
    assertNotNull(popupMenu);
    shadowOf(popupMenu).getOnMenuItemClickListener().onMenuItemClick(new RoboMenuItem(R.id.menu_contextual_refresh));
    verify(itemManager).getItem(any(), eq(ItemManager.MODE_DEFAULT), any());
}
Also used : RoboMenuItem(org.robolectric.fakes.RoboMenuItem) PopupMenu(android.widget.PopupMenu) ShadowPopupMenu(org.robolectric.shadows.ShadowPopupMenu) SlowTest(io.github.hidroh.materialistic.test.suite.SlowTest) Test(org.junit.Test) TargetApi(android.annotation.TargetApi)

Example 30 with PopupMenu

use of android.widget.PopupMenu in project materialistic by hidroh.

the class ListFragmentViewHolderTest method testSaveItem.

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Test
public void testSaveItem() {
    ShadowContentObserver observer = shadowOf(shadowOf(activity.getContentResolver()).getContentObservers(MaterialisticProvider.URI_FAVORITE).iterator().next());
    verify(itemManager).getItem(any(), eq(ItemManager.MODE_DEFAULT), itemListener.capture());
    itemListener.getValue().onResponse(item);
    adapter.getViewHolder(0).itemView.performLongClick();
    PopupMenu popupMenu = ShadowPopupMenu.getLatestPopupMenu();
    assertNotNull(popupMenu);
    assertThat(popupMenu.getMenu().findItem(R.id.menu_contextual_save).isVisible()).isFalse();
    shadowOf(popupMenu).getOnMenuItemClickListener().onMenuItemClick(new RoboMenuItem(R.id.menu_contextual_save));
    verify(favoriteManager).add(any(Context.class), eq(item));
    observer.dispatchChange(false, MaterialisticProvider.URI_FAVORITE.buildUpon().appendPath("add").appendPath("1").build());
    assertTrue(item.isFavorite());
    View snackbarView = ShadowSnackbar.getLatestView();
    assertThat((TextView) snackbarView.findViewById(R.id.snackbar_text)).isNotNull().containsText(R.string.toast_saved);
    snackbarView.findViewById(R.id.snackbar_action).performClick();
    verify(favoriteManager).remove(any(Context.class), eq("1"));
    observer.dispatchChange(false, MaterialisticProvider.URI_FAVORITE.buildUpon().appendPath("remove").appendPath("1").build());
    assertFalse(item.isFavorite());
}
Also used : Context(android.content.Context) ShadowContentObserver(org.robolectric.shadows.ShadowContentObserver) View(android.view.View) TextView(android.widget.TextView) RecyclerView(android.support.v7.widget.RecyclerView) ShadowRecyclerView(io.github.hidroh.materialistic.test.shadow.ShadowRecyclerView) RoboMenuItem(org.robolectric.fakes.RoboMenuItem) PopupMenu(android.widget.PopupMenu) ShadowPopupMenu(org.robolectric.shadows.ShadowPopupMenu) SlowTest(io.github.hidroh.materialistic.test.suite.SlowTest) Test(org.junit.Test) TargetApi(android.annotation.TargetApi)

Aggregations

PopupMenu (android.widget.PopupMenu)97 MenuItem (android.view.MenuItem)60 View (android.view.View)44 TextView (android.widget.TextView)41 ImageView (android.widget.ImageView)30 RecyclerView (android.support.v7.widget.RecyclerView)22 TargetApi (android.annotation.TargetApi)20 SlowTest (io.github.hidroh.materialistic.test.suite.SlowTest)19 Test (org.junit.Test)19 ShadowPopupMenu (org.robolectric.shadows.ShadowPopupMenu)19 RoboMenuItem (org.robolectric.fakes.RoboMenuItem)18 Intent (android.content.Intent)14 Context (android.content.Context)12 DialogAction (com.afollestad.materialdialogs.DialogAction)12 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)12 MenuInflater (android.view.MenuInflater)10 AdapterView (android.widget.AdapterView)10 ListView (android.widget.ListView)10 Menu (android.view.Menu)9 NonNull (android.support.annotation.NonNull)8