Skip to content

Commit 8312162

Browse files
hunterstichdsn5ft
authored andcommitted
[Carousel] Added tests for hero and multibrowse strategies when the carousel container is very small.
PiperOrigin-RevId: 568855070
1 parent 4a6ae4d commit 8312162

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

lib/javatests/com/google/android/material/carousel/HeroCarouselStrategyTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,23 @@ public void testItemSmallerThanContainer_showsOneLargeOneSmall() {
7878
assertThat(keylineState.getKeylines().get(2).maskedItemSize).isEqualTo(minSmallItemSize);
7979
}
8080

81+
@Test
82+
public void testSmallContainer_shouldShowOneLargeItem() {
83+
View view = createViewWithSize(ApplicationProvider.getApplicationContext(), 100, 400);
84+
float minSmallItemSize =
85+
view.getResources().getDimension(R.dimen.m3_carousel_small_item_size_min);
86+
// Create a carousel that will not fit a large and small item where the large item is at least
87+
// as big as the min small item.
88+
int carouselWidth = (int) (minSmallItemSize * 1.5f);
89+
Carousel carousel = createCarouselWithWidth(carouselWidth);
90+
91+
HeroCarouselStrategy config = new HeroCarouselStrategy();
92+
KeylineState keylineState = config.onFirstChildMeasuredWithMargins(carousel, view);
93+
94+
assertThat(keylineState.getKeylines()).hasSize(3);
95+
assertThat(keylineState.getKeylines().get(1).maskedItemSize).isEqualTo((float) carouselWidth);
96+
}
97+
8198
@Test
8299
public void testKnownArrangement_correctlyCalculatesKeylineLocations() {
83100
View view = createViewWithSize(ApplicationProvider.getApplicationContext(), 400, 200);

lib/javatests/com/google/android/material/carousel/MultiBrowseCarouselStrategyTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,24 @@ public void testItemLargerThanContainerSize_defaultsToOneLargeOneSmall() {
7676
assertThat(keylineState.getKeylines().get(2).maskedItemSize).isEqualTo(minSmallItemSize);
7777
}
7878

79+
80+
@Test
81+
public void testSmallContainer_shouldShowOneLargeItem() {
82+
View view = createViewWithSize(ApplicationProvider.getApplicationContext(), 100, 400);
83+
float minSmallItemSize =
84+
view.getResources().getDimension(R.dimen.m3_carousel_small_item_size_min);
85+
// Create a carousel that will not fit a large and small item where the large item is at least
86+
// as big as the min small item.
87+
int carouselWidth = (int) (minSmallItemSize * 1.5f);
88+
Carousel carousel = createCarouselWithWidth(carouselWidth);
89+
90+
MultiBrowseCarouselStrategy config = new MultiBrowseCarouselStrategy();
91+
KeylineState keylineState = config.onFirstChildMeasuredWithMargins(carousel, view);
92+
93+
assertThat(keylineState.getKeylines()).hasSize(3);
94+
assertThat(keylineState.getKeylines().get(1).maskedItemSize).isEqualTo((float) carouselWidth);
95+
}
96+
7997
@Test
8098
public void testKnownArrangementWithMediumItem_correctlyCalculatesKeylineLocations() {
8199
float[] locOffsets = new float[] {-.5F, 100F, 300F, 464F, 556F, 584.5F};

0 commit comments

Comments
 (0)