@@ -433,10 +433,7 @@ public void testSkipCollapsedFullyExpanded() throws Throwable {
433433 testSkipCollapsed ();
434434 }
435435
436- private void testSkipCollapsed_smallSwipe (int expectedState , float swipeViewHeightPercentage )
437- throws Throwable {
438- getBehavior ().setSkipCollapsed (true );
439- checkSetState (BottomSheetBehavior .STATE_EXPANDED , ViewMatchers .isDisplayed ());
436+ private void testSkipCollapsed_smallSwipe (int expectedState , float swipeViewHeightPercentage ) {
440437 Espresso .onView (ViewMatchers .withId (R .id .bottom_sheet ))
441438 .perform (
442439 DesignViewActions .withCustomConstraints (
@@ -476,16 +473,23 @@ private void testSkipCollapsed_smallSwipe(int expectedState, float swipeViewHeig
476473 }
477474 }
478475
476+ private void setSkipCollapsed () throws Throwable {
477+ getBehavior ().setSkipCollapsed (true );
478+ checkSetState (BottomSheetBehavior .STATE_EXPANDED , ViewMatchers .isDisplayed ());
479+ }
480+
479481 @ Test
480482 @ MediumTest
481483 public void testSkipCollapsed_smallSwipe_remainsExpanded () throws Throwable {
484+ setSkipCollapsed ();
482485 testSkipCollapsed_smallSwipe (
483486 BottomSheetBehavior .STATE_EXPANDED , /* swipeViewHeightPercentage = */ 0.5f );
484487 }
485488
486489 @ Test
487490 @ MediumTest
488491 public void testSkipCollapsedFullyExpanded_smallSwipe_remainsExpanded () throws Throwable {
492+ setSkipCollapsed ();
489493 getBehavior ().setFitToContents (false );
490494 testSkipCollapsed_smallSwipe (
491495 BottomSheetBehavior .STATE_HALF_EXPANDED , /* swipeViewHeightPercentage = */ 0.5f );
@@ -494,18 +498,41 @@ public void testSkipCollapsedFullyExpanded_smallSwipe_remainsExpanded() throws T
494498 @ Test
495499 @ MediumTest
496500 public void testSkipCollapsed_smallSwipePastThreshold_getsHidden () throws Throwable {
501+ setSkipCollapsed ();
497502 testSkipCollapsed_smallSwipe (
498503 BottomSheetBehavior .STATE_HIDDEN , /* swipeViewHeightPercentage = */ 0.75f );
499504 }
500505
501506 @ Test
502507 @ MediumTest
503508 public void testSkipCollapsedFullyExpanded_smallSwipePastThreshold_getsHidden () throws Throwable {
509+ setSkipCollapsed ();
504510 getBehavior ().setFitToContents (false );
505511 testSkipCollapsed_smallSwipe (
506512 BottomSheetBehavior .STATE_HIDDEN , /* swipeViewHeightPercentage = */ 0.75f );
507513 }
508514
515+ private void makeBottomSheetNotCollapsible () {
516+ // Set a peek height that equals to expanded height so it always stays EXPANDED.
517+ getBehavior ().setPeekHeight (5000 );
518+ }
519+
520+ @ Test
521+ @ MediumTest
522+ public void testNotCollapsible_smallSwipe_remainsExpanded () {
523+ makeBottomSheetNotCollapsible ();
524+ testSkipCollapsed_smallSwipe (
525+ BottomSheetBehavior .STATE_EXPANDED , /* swipeViewHeightPercentage = */ 0.5f );
526+ }
527+
528+ @ Test
529+ @ MediumTest
530+ public void testNotCollapsible_smallSwipePastThreshold_getsHidden () {
531+ makeBottomSheetNotCollapsible ();
532+ testSkipCollapsed_smallSwipe (
533+ BottomSheetBehavior .STATE_HIDDEN , /* swipeViewHeightPercentage = */ 0.75f );
534+ }
535+
509536 @ Test
510537 @ MediumTest
511538 public void testSwipeUpToExpand () {
@@ -935,16 +962,22 @@ public void testDynamicContent() throws Throwable {
935962 @ Test
936963 @ MediumTest
937964 public void testExpandedPeekHeight () throws Throwable {
965+ registerIdlingResourceCallback ();
938966 activityTestRule .runOnUiThread (
939967 () -> {
940968 // Make the peek height as tall as the bottom sheet.
941- BottomSheetBehavior <?> behavior = getBehavior ();
942- behavior .setPeekHeight (getBottomSheet ().getHeight ());
943- assertThat (behavior .getState (), is (BottomSheetBehavior .STATE_COLLAPSED ));
969+ getBehavior ().setPeekHeight (getBottomSheet ().getHeight ());
944970 });
945- // Both of these will not animate the sheet , but the state should be changed.
971+ Espresso .onView (ViewMatchers .withId (R .id .bottom_sheet ))
972+ .check (ViewAssertions .matches (ViewMatchers .isDisplayed ()));
973+ assertThat (getBehavior ().getState (), is (BottomSheetBehavior .STATE_EXPANDED ));
974+ unregisterIdlingResourceCallback ();
975+ // Both of these will not animate the sheet, and the state should be fixed as EXPANDED.
946976 checkSetState (BottomSheetBehavior .STATE_EXPANDED , ViewMatchers .isDisplayed ());
947- checkSetState (BottomSheetBehavior .STATE_COLLAPSED , ViewMatchers .isDisplayed ());
977+ checkSetState (
978+ BottomSheetBehavior .STATE_COLLAPSED ,
979+ BottomSheetBehavior .STATE_EXPANDED ,
980+ ViewMatchers .isDisplayed ());
948981 }
949982
950983 @ Test
@@ -962,12 +995,17 @@ public void testFindScrollingChildEnabled() {
962995 }
963996
964997 private void checkSetState (final int state , Matcher <View > matcher ) throws Throwable {
998+ checkSetState (state , state , matcher );
999+ }
1000+
1001+ private void checkSetState (
1002+ final int stateToSet , final int stateToExpect , Matcher <View > matcher ) throws Throwable {
9651003 registerIdlingResourceCallback ();
9661004 try {
967- activityTestRule .runOnUiThread (() -> getBehavior ().setState (state ));
1005+ activityTestRule .runOnUiThread (() -> getBehavior ().setState (stateToSet ));
9681006 Espresso .onView (ViewMatchers .withId (R .id .bottom_sheet ))
9691007 .check (ViewAssertions .matches (matcher ));
970- assertThat (getBehavior ().getState (), is (state ));
1008+ assertThat (getBehavior ().getState (), is (stateToExpect ));
9711009 assertAccessibilityActions (getBehavior (), getBottomSheet ());
9721010 } finally {
9731011 unregisterIdlingResourceCallback ();
0 commit comments