test(image): [android] adding missing image resize mode test cases (#47527)

Summary:
Follow up from https://github.com/facebook/react-native/issues/47433, adding some missing scenarios in the unit tests for the image component in Android.

## Changelog:

[INTERNAL] [ADDED] - Improving Android `ImageResizeMode` unit tests

Pull Request resolved: https://github.com/facebook/react-native/pull/47527

Test Plan:
```bash
yarn test-android
```

Reviewed By: fabriziocucci

Differential Revision: D65735794

Pulled By: Abbondanzo

fbshipit-source-id: a420274c78d9eadf0439870cfaae4d16247c6034
This commit is contained in:
Mateo Guzmán 2024-11-11 07:38:59 -08:00 committed by Facebook GitHub Bot
parent e70202e606
commit 6295b81e79

View File

@ -7,6 +7,7 @@
package com.facebook.react.views.image
import android.graphics.Shader.TileMode
import com.facebook.drawee.drawable.ScalingUtils
import org.assertj.core.api.Assertions
import org.junit.Test
@ -17,7 +18,7 @@ import org.robolectric.RobolectricTestRunner
class ImageResizeModeTest {
@Test
fun testImageResizeMode() {
fun testScaleType() {
Assertions.assertThat(ImageResizeMode.toScaleType(null))
.isEqualTo(ScalingUtils.ScaleType.CENTER_CROP)
Assertions.assertThat(ImageResizeMode.toScaleType("contain"))
@ -28,6 +29,8 @@ class ImageResizeModeTest {
.isEqualTo(ScalingUtils.ScaleType.FIT_XY)
Assertions.assertThat(ImageResizeMode.toScaleType("center"))
.isEqualTo(ScalingUtils.ScaleType.CENTER_INSIDE)
Assertions.assertThat(ImageResizeMode.toScaleType("repeat"))
.isEqualTo(ScaleTypeStartInside.INSTANCE)
Assertions.assertThat(ImageResizeMode.toScaleType("none"))
.isEqualTo(ScaleTypeStartInside.INSTANCE)
@ -35,4 +38,18 @@ class ImageResizeModeTest {
Assertions.assertThat(ImageResizeMode.defaultValue())
.isEqualTo(ScalingUtils.ScaleType.CENTER_CROP)
}
@Test
fun testTileMode() {
Assertions.assertThat(ImageResizeMode.toTileMode(null)).isEqualTo(TileMode.CLAMP)
Assertions.assertThat(ImageResizeMode.toTileMode("contain")).isEqualTo(TileMode.CLAMP)
Assertions.assertThat(ImageResizeMode.toTileMode("cover")).isEqualTo(TileMode.CLAMP)
Assertions.assertThat(ImageResizeMode.toTileMode("stretch")).isEqualTo(TileMode.CLAMP)
Assertions.assertThat(ImageResizeMode.toTileMode("center")).isEqualTo(TileMode.CLAMP)
Assertions.assertThat(ImageResizeMode.toTileMode("none")).isEqualTo(TileMode.CLAMP)
Assertions.assertThat(ImageResizeMode.toTileMode("repeat")).isEqualTo(TileMode.REPEAT)
// No resizeMode set
Assertions.assertThat(ImageResizeMode.defaultTileMode()).isEqualTo(TileMode.CLAMP)
}
}