use of android.support.design.testapp.custom.CustomSnackbar in project material-components-android by material-components.
the class CustomSnackbarTest method testDismissViaAnotherSnackbar.
@Test
@MediumTest
public void testDismissViaAnotherSnackbar() throws Throwable {
final CustomSnackbar anotherSnackbar = makeCustomSnackbar().setTitle("Different title").setSubtitle("Different subtitle").setDuration(Snackbar.LENGTH_SHORT);
// Our dismiss action is to show another snackbar (and verify that the original snackbar
// is now dismissed with CONSECUTIVE event)
verifyDismissCallback(onView(isAssignableFrom(Snackbar.SnackbarLayout.class)), null, new DismissAction() {
@Override
public void dismiss(CustomSnackbar snackbar) {
anotherSnackbar.show();
}
}, Snackbar.LENGTH_LONG, Snackbar.Callback.DISMISS_EVENT_CONSECUTIVE);
// And dismiss the second snackbar to get back to clean state
SnackbarUtils.dismissTransientBottomBarAndWaitUntilFullyDismissed(anotherSnackbar);
}
use of android.support.design.testapp.custom.CustomSnackbar in project material-components-android by material-components.
the class CustomSnackbarTest method makeCustomSnackbar.
private CustomSnackbar makeCustomSnackbar() {
final LayoutInflater inflater = LayoutInflater.from(mCoordinatorLayout.getContext());
final CustomSnackbarMainContent content = (CustomSnackbarMainContent) inflater.inflate(R.layout.custom_snackbar_include, mCoordinatorLayout, false);
final BaseTransientBottomBar.ContentViewCallback contentViewCallback = new BaseTransientBottomBar.ContentViewCallback() {
@Override
public void animateContentIn(int delay, int duration) {
ViewCompat.setAlpha(content, 0f);
ViewCompat.animate(content).alpha(1f).setDuration(duration).setStartDelay(delay).start();
}
@Override
public void animateContentOut(int delay, int duration) {
ViewCompat.setAlpha(content, 1f);
ViewCompat.animate(content).alpha(0f).setDuration(duration).setStartDelay(delay).start();
}
};
return new CustomSnackbar(mCoordinatorLayout, content, contentViewCallback);
}
use of android.support.design.testapp.custom.CustomSnackbar in project material-components-android by material-components.
the class CustomSnackbarTest method verifyDismissCallback.
private void verifyDismissCallback(final ViewInteraction interaction, @Nullable final ViewAction action, @Nullable final DismissAction dismissAction, final int length, @Snackbar.Callback.DismissEvent final int expectedEvent) throws Throwable {
final BaseTransientBottomBar.BaseCallback mockCallback = mock(BaseTransientBottomBar.BaseCallback.class);
final CustomSnackbar snackbar = makeCustomSnackbar().setTitle(TITLE_TEXT).setSubtitle(SUBTITLE_TEXT).setDuration(length).addCallback(mockCallback);
// Show the snackbar
SnackbarUtils.showTransientBottomBarAndWaitUntilFullyShown(snackbar);
// Verify that our onShown has been called
verify(mockCallback, times(1)).onShown(snackbar);
// and that the snackbar is either shown or queued to be shown
assertTrue(snackbar.isShownOrQueued());
// and also check that we have the intended title / subtitle displayed somewhere in
// our hierarchy
onView(withText(TITLE_TEXT)).check(matches(isCompletelyDisplayed()));
onView(withText(SUBTITLE_TEXT)).check(matches(isCompletelyDisplayed()));
// Now perform the UI interaction
SnackbarUtils.performActionAndWaitUntilFullyDismissed(snackbar, new SnackbarUtils.TransientBottomBarAction() {
@Override
public void perform() throws Throwable {
if (action != null) {
interaction.perform(action);
} else if (dismissAction != null) {
activityTestRule.runOnUiThread(new Runnable() {
@Override
public void run() {
dismissAction.dismiss(snackbar);
}
});
}
}
});
// Verify that our onDismissed has been called
verify(mockCallback, times(1)).onDismissed(snackbar, expectedEvent);
verifyNoMoreInteractions(mockCallback);
// and that the snackbar is neither shown nor queued to be shown
assertFalse(snackbar.isShownOrQueued());
}
use of android.support.design.testapp.custom.CustomSnackbar in project material-components-android by material-components.
the class CustomSnackbarTest method testMultipleCallbacks.
@Test
@MediumTest
public void testMultipleCallbacks() throws Throwable {
final CustomSnackbar snackbar = makeCustomSnackbar().setTitle(TITLE_TEXT).setSubtitle(SUBTITLE_TEXT).setDuration(Snackbar.LENGTH_INDEFINITE);
final BaseTransientBottomBar.BaseCallback mockCallback1 = mock(BaseTransientBottomBar.BaseCallback.class);
final BaseTransientBottomBar.BaseCallback mockCallback2 = mock(BaseTransientBottomBar.BaseCallback.class);
snackbar.addCallback(mockCallback1);
snackbar.addCallback(mockCallback2);
SnackbarUtils.showTransientBottomBarAndWaitUntilFullyShown(snackbar);
verify(mockCallback1, times(1)).onShown(snackbar);
verify(mockCallback2, times(1)).onShown(snackbar);
SnackbarUtils.dismissTransientBottomBarAndWaitUntilFullyDismissed(snackbar);
verify(mockCallback1, times(1)).onDismissed(snackbar, BaseTransientBottomBar.BaseCallback.DISMISS_EVENT_MANUAL);
verify(mockCallback2, times(1)).onDismissed(snackbar, BaseTransientBottomBar.BaseCallback.DISMISS_EVENT_MANUAL);
}
Aggregations