|
17 | 17 | package com.google.android.flexbox |
18 | 18 |
|
19 | 19 | import android.view.View |
| 20 | +import android.widget.CheckBox |
20 | 21 | import android.widget.TextView |
21 | 22 | import androidx.test.rule.ActivityTestRule |
22 | 23 | import androidx.test.runner.AndroidJUnit4 |
@@ -399,6 +400,74 @@ class FlexboxHelperTest { |
399 | 400 | assertThat(view3.measuredWidth, `is`(100)) |
400 | 401 | } |
401 | 402 |
|
| 403 | + @Test |
| 404 | + @Throws(Throwable::class) |
| 405 | + fun testDetermineMainSize_directionRow_considerCompoundButtonImplicitMinSizeWhenNotSpecified() { |
| 406 | + val containerWidth = 500 |
| 407 | + val activity = activityRule.activity |
| 408 | + val lp1 = FlexboxLayout.LayoutParams( |
| 409 | + FlexboxLayout.LayoutParams.WRAP_CONTENT, |
| 410 | + FlexboxLayout.LayoutParams.WRAP_CONTENT) |
| 411 | + val view1 = CheckBox(activity) |
| 412 | + view1.layoutParams = lp1 |
| 413 | + val lp2 = FlexboxLayout.LayoutParams( |
| 414 | + FlexboxLayout.LayoutParams.WRAP_CONTENT, |
| 415 | + FlexboxLayout.LayoutParams.WRAP_CONTENT) |
| 416 | + val view2 = TextView(activity) |
| 417 | + view2.layoutParams = lp2 |
| 418 | + view2.text = LONG_TEXT |
| 419 | + flexContainer.addView(view1) |
| 420 | + flexContainer.addView(view2) |
| 421 | + flexContainer.flexWrap = FlexWrap.NOWRAP |
| 422 | + val widthMeasureSpec = View.MeasureSpec.makeMeasureSpec(containerWidth, View.MeasureSpec.AT_MOST) |
| 423 | + val heightMeasureSpec = View.MeasureSpec.makeMeasureSpec(1000, View.MeasureSpec.UNSPECIFIED) |
| 424 | + val result = FlexboxHelper.FlexLinesResult() |
| 425 | + flexboxHelper.calculateHorizontalFlexLines(result, widthMeasureSpec, heightMeasureSpec) |
| 426 | + flexContainer.flexLines = result.mFlexLines |
| 427 | + flexboxHelper.determineMainSize(widthMeasureSpec, heightMeasureSpec) |
| 428 | + |
| 429 | + // CompoundButton will use its ButtonDrawable minWidth to determine its size when |
| 430 | + // no minimum width is set on it. |
| 431 | + val drawableMinWidth = view1.buttonDrawable!!.minimumWidth |
| 432 | + val expectedTextWidth = containerWidth - drawableMinWidth |
| 433 | + assertThat(view1.measuredWidth, `is`(drawableMinWidth)) |
| 434 | + assertThat(view2.measuredWidth, `is`(expectedTextWidth)) |
| 435 | + } |
| 436 | + |
| 437 | + @Test |
| 438 | + @Throws(Throwable::class) |
| 439 | + fun testDetermineMainSize_directionRow_considerCompoundButtonExplicitMinSizeWhenSpecified() { |
| 440 | + val containerWidth = 500 |
| 441 | + val compoundButtonMinWidth = 150 |
| 442 | + val activity = activityRule.activity |
| 443 | + val lp1 = FlexboxLayout.LayoutParams( |
| 444 | + FlexboxLayout.LayoutParams.WRAP_CONTENT, |
| 445 | + FlexboxLayout.LayoutParams.WRAP_CONTENT) |
| 446 | + lp1.minWidth = compoundButtonMinWidth |
| 447 | + val view1 = CheckBox(activity) |
| 448 | + view1.layoutParams = lp1 |
| 449 | + val lp2 = FlexboxLayout.LayoutParams( |
| 450 | + FlexboxLayout.LayoutParams.WRAP_CONTENT, |
| 451 | + FlexboxLayout.LayoutParams.WRAP_CONTENT) |
| 452 | + val view2 = TextView(activity) |
| 453 | + view2.layoutParams = lp2 |
| 454 | + view2.text = LONG_TEXT |
| 455 | + flexContainer.addView(view1) |
| 456 | + flexContainer.addView(view2) |
| 457 | + flexContainer.flexWrap = FlexWrap.NOWRAP |
| 458 | + val widthMeasureSpec = View.MeasureSpec.makeMeasureSpec(containerWidth, View.MeasureSpec.AT_MOST) |
| 459 | + val heightMeasureSpec = View.MeasureSpec.makeMeasureSpec(1000, View.MeasureSpec.UNSPECIFIED) |
| 460 | + val result = FlexboxHelper.FlexLinesResult() |
| 461 | + flexboxHelper.calculateHorizontalFlexLines(result, widthMeasureSpec, heightMeasureSpec) |
| 462 | + flexContainer.flexLines = result.mFlexLines |
| 463 | + flexboxHelper.determineMainSize(widthMeasureSpec, heightMeasureSpec) |
| 464 | + |
| 465 | + // CompoundButton will be measured based on its explicitly specified minWidth. |
| 466 | + val expectedTextWidth = containerWidth - compoundButtonMinWidth |
| 467 | + assertThat(view1.measuredWidth, `is`(compoundButtonMinWidth)) |
| 468 | + assertThat(view2.measuredWidth, `is`(expectedTextWidth)) |
| 469 | + } |
| 470 | + |
402 | 471 | @Test |
403 | 472 | @Throws(Throwable::class) |
404 | 473 | fun testDetermineCrossSize_direction_row_alignContent_stretch() { |
|
0 commit comments