Skip to content

Commit

Permalink
[Carousel] Added tests for hero and multibrowse strategies when the c…
Browse files Browse the repository at this point in the history
…arousel container is very small.

PiperOrigin-RevId: 568855070
  • Loading branch information
hunterstich authored and dsn5ft committed Oct 2, 2023
1 parent 4a6ae4d commit 8312162
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
Expand Up @@ -78,6 +78,23 @@ public void testItemSmallerThanContainer_showsOneLargeOneSmall() {
assertThat(keylineState.getKeylines().get(2).maskedItemSize).isEqualTo(minSmallItemSize);
}

@Test
public void testSmallContainer_shouldShowOneLargeItem() {
View view = createViewWithSize(ApplicationProvider.getApplicationContext(), 100, 400);
float minSmallItemSize =
view.getResources().getDimension(R.dimen.m3_carousel_small_item_size_min);
// Create a carousel that will not fit a large and small item where the large item is at least
// as big as the min small item.
int carouselWidth = (int) (minSmallItemSize * 1.5f);
Carousel carousel = createCarouselWithWidth(carouselWidth);

HeroCarouselStrategy config = new HeroCarouselStrategy();
KeylineState keylineState = config.onFirstChildMeasuredWithMargins(carousel, view);

assertThat(keylineState.getKeylines()).hasSize(3);
assertThat(keylineState.getKeylines().get(1).maskedItemSize).isEqualTo((float) carouselWidth);
}

@Test
public void testKnownArrangement_correctlyCalculatesKeylineLocations() {
View view = createViewWithSize(ApplicationProvider.getApplicationContext(), 400, 200);
Expand Down
Expand Up @@ -76,6 +76,24 @@ public void testItemLargerThanContainerSize_defaultsToOneLargeOneSmall() {
assertThat(keylineState.getKeylines().get(2).maskedItemSize).isEqualTo(minSmallItemSize);
}


@Test
public void testSmallContainer_shouldShowOneLargeItem() {
View view = createViewWithSize(ApplicationProvider.getApplicationContext(), 100, 400);
float minSmallItemSize =
view.getResources().getDimension(R.dimen.m3_carousel_small_item_size_min);
// Create a carousel that will not fit a large and small item where the large item is at least
// as big as the min small item.
int carouselWidth = (int) (minSmallItemSize * 1.5f);
Carousel carousel = createCarouselWithWidth(carouselWidth);

MultiBrowseCarouselStrategy config = new MultiBrowseCarouselStrategy();
KeylineState keylineState = config.onFirstChildMeasuredWithMargins(carousel, view);

assertThat(keylineState.getKeylines()).hasSize(3);
assertThat(keylineState.getKeylines().get(1).maskedItemSize).isEqualTo((float) carouselWidth);
}

@Test
public void testKnownArrangementWithMediumItem_correctlyCalculatesKeylineLocations() {
float[] locOffsets = new float[] {-.5F, 100F, 300F, 464F, 556F, 584.5F};
Expand Down

0 comments on commit 8312162

Please sign in to comment.