18
18
import com .google .android .material .test .R ;
19
19
20
20
import static com .google .android .material .carousel .CarouselHelper .createCarousel ;
21
+ import static com .google .android .material .carousel .CarouselHelper .createCarouselWithItemCount ;
21
22
import static com .google .android .material .carousel .CarouselHelper .createCarouselWithWidth ;
22
23
import static com .google .android .material .carousel .CarouselHelper .createViewWithSize ;
23
24
import static com .google .common .truth .Truth .assertThat ;
@@ -166,7 +167,7 @@ public void testKnownCenterAlignmentArrangement_correctlyCalculatesKeylineLocati
166
167
ApplicationProvider .getApplicationContext (), (int ) largeSize , (int ) largeSize );
167
168
int carouselSize = (int ) (largeSize + smallSize * 2 );
168
169
169
- MultiBrowseCarouselStrategy strategy = new MultiBrowseCarouselStrategy ();
170
+ HeroCarouselStrategy strategy = new HeroCarouselStrategy ();
170
171
List <Keyline > keylines =
171
172
strategy .onFirstChildMeasuredWithMargins (
172
173
createCarousel (
@@ -180,4 +181,35 @@ public void testKnownCenterAlignmentArrangement_correctlyCalculatesKeylineLocati
180
181
assertThat (keylines .get (i ).locOffset ).isEqualTo (locOffsets [i ]);
181
182
}
182
183
}
184
+
185
+ @ Test
186
+ public void testCenterAlignment_isLeftAlignedWithMinItems () {
187
+ float largeSize = 40F * 3 ; // 120F
188
+ float smallSize = 40F ;
189
+
190
+ View view =
191
+ createViewWithSize (
192
+ ApplicationProvider .getApplicationContext (), (int ) largeSize , (int ) largeSize );
193
+ int carouselSize = (int ) (largeSize + smallSize * 2 );
194
+
195
+ HeroCarouselStrategy strategy = new HeroCarouselStrategy ();
196
+ List <Keyline > keylines =
197
+ strategy
198
+ .onFirstChildMeasuredWithMargins (
199
+ createCarouselWithItemCount (
200
+ carouselSize , CarouselLayoutManager .ALIGNMENT_CENTER , 2 ),
201
+ view )
202
+ .getKeylines ();
203
+
204
+ float minSmallItemSize =
205
+ view .getResources ().getDimension (R .dimen .m3_carousel_small_item_size_min );
206
+
207
+ // keylines when there are only 2 items is {xsmall, large, small, xsmall}
208
+ float [] locOffsets =
209
+ new float [] {-.5F , (200 - minSmallItemSize ) / 2F , 200 - minSmallItemSize / 2F , 200.5F };
210
+
211
+ for (int i = 0 ; i < keylines .size (); i ++) {
212
+ assertThat (keylines .get (i ).locOffset ).isEqualTo (locOffsets [i ]);
213
+ }
214
+ }
183
215
}
0 commit comments