Search in sources :

Example 1 with CustomSnackbar

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);
}
Also used : CustomSnackbar(android.support.design.testapp.custom.CustomSnackbar) CustomSnackbar(android.support.design.testapp.custom.CustomSnackbar) SmallTest(android.support.test.filters.SmallTest) MediumTest(android.support.test.filters.MediumTest) Test(org.junit.Test) MediumTest(android.support.test.filters.MediumTest)

Example 2 with CustomSnackbar

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);
}
Also used : LayoutInflater(android.view.LayoutInflater) CustomSnackbar(android.support.design.testapp.custom.CustomSnackbar) CustomSnackbarMainContent(android.support.design.testapp.custom.CustomSnackbarMainContent)

Example 3 with CustomSnackbar

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());
}
Also used : CustomSnackbar(android.support.design.testapp.custom.CustomSnackbar) SnackbarUtils(android.support.design.testutils.SnackbarUtils)

Example 4 with CustomSnackbar

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);
}
Also used : CustomSnackbar(android.support.design.testapp.custom.CustomSnackbar) SmallTest(android.support.test.filters.SmallTest) MediumTest(android.support.test.filters.MediumTest) Test(org.junit.Test) MediumTest(android.support.test.filters.MediumTest)

Aggregations

CustomSnackbar (android.support.design.testapp.custom.CustomSnackbar)4 MediumTest (android.support.test.filters.MediumTest)2 SmallTest (android.support.test.filters.SmallTest)2 Test (org.junit.Test)2 CustomSnackbarMainContent (android.support.design.testapp.custom.CustomSnackbarMainContent)1 SnackbarUtils (android.support.design.testutils.SnackbarUtils)1 LayoutInflater (android.view.LayoutInflater)1