From 97484015077019bd72db8f5213638142ebc1a6b4 Mon Sep 17 00:00:00 2001 From: Uzias Ferreira Date: Tue, 11 May 2021 14:58:38 -0300 Subject: [PATCH 1/2] fix: adjust image corner radius --- .../java/br/com/zup/beagle/android/components/Image.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/android/beagle/src/main/java/br/com/zup/beagle/android/components/Image.kt b/android/beagle/src/main/java/br/com/zup/beagle/android/components/Image.kt index 2f5868ccc5..74d9d1745e 100644 --- a/android/beagle/src/main/java/br/com/zup/beagle/android/components/Image.kt +++ b/android/beagle/src/main/java/br/com/zup/beagle/android/components/Image.kt @@ -26,6 +26,7 @@ import br.com.zup.beagle.android.engine.mapper.ViewMapper import br.com.zup.beagle.android.imagedownloader.DefaultImageDownloader import br.com.zup.beagle.android.logger.BeagleMessageLogs import br.com.zup.beagle.android.setup.BeagleEnvironment +import br.com.zup.beagle.android.utils.dp import br.com.zup.beagle.android.utils.observeBindChanges import br.com.zup.beagle.android.view.ViewFactory import br.com.zup.beagle.android.widget.RootView @@ -73,11 +74,15 @@ data class Image constructor( } private fun getImageView(rootView: RootView) = viewFactory.makeImageView(rootView.getContext(), - style?.cornerRadius?.radius ?: 0.0).apply { + getCornerRadius()).apply { adjustViewBounds = true scaleType = viewMapper.toScaleType(mode ?: ImageContentMode.FIT_CENTER) } + private fun getCornerRadius(): Double { + return style?.cornerRadius?.radius?.dp() ?: 0.0 + } + private fun loadLocalImage(rootView: RootView, imageView: ImageView, pathType: ImagePath.Local) { imageView.apply { observeBindChanges(rootView, imageView, pathType.mobileId) { mobileId -> From 90e53fb3537edd57ea07632269cc9837fe55af6f Mon Sep 17 00:00:00 2001 From: Uzias Ferreira Date: Tue, 11 May 2021 15:28:14 -0300 Subject: [PATCH 2/2] add unit test --- .../beagle/android/components/ImageTest.kt | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/android/beagle/src/test/java/br/com/zup/beagle/android/components/ImageTest.kt b/android/beagle/src/test/java/br/com/zup/beagle/android/components/ImageTest.kt index 091041a93d..ab4a829404 100644 --- a/android/beagle/src/test/java/br/com/zup/beagle/android/components/ImageTest.kt +++ b/android/beagle/src/test/java/br/com/zup/beagle/android/components/ImageTest.kt @@ -20,7 +20,9 @@ import android.widget.ImageView import br.com.zup.beagle.android.components.utils.RoundedImageView import br.com.zup.beagle.android.setup.BeagleEnvironment import br.com.zup.beagle.android.testutil.RandomData +import br.com.zup.beagle.android.utils.dp import br.com.zup.beagle.android.view.ViewFactory +import br.com.zup.beagle.core.CornerRadius import br.com.zup.beagle.core.Style import br.com.zup.beagle.ext.applyStyle import br.com.zup.beagle.ext.unitReal @@ -30,6 +32,7 @@ import io.mockk.Runs import io.mockk.every import io.mockk.just import io.mockk.mockk +import io.mockk.mockkStatic import io.mockk.slot import io.mockk.verify import org.junit.jupiter.api.Assertions.assertEquals @@ -47,7 +50,8 @@ internal class ImageTest : BaseComponentTest() { private val imageView: RoundedImageView = mockk(relaxed = true, relaxUnitFun = true) private val scaleTypeSlot = slot() - private val style = Style(size = Size(width = 100.unitReal(), height = 100.unitReal())) + private val style = Style(size = Size(width = 100.unitReal(), height = 100.unitReal()), + cornerRadius = CornerRadius(radius = 10.0)) private lateinit var imageLocal: Image private lateinit var imageRemote: Image @@ -57,9 +61,12 @@ internal class ImageTest : BaseComponentTest() { override fun setUp() { super.setUp() + mockkStatic("br.com.zup.beagle.android.utils.NumberExtensionsKt") + every { anyConstructed().makeImageView(rootView.getContext(), any()) } returns imageView every { beagleSdk.designSystem } returns mockk(relaxed = true) every { beagleSdk.designSystem!!.image(any()) } returns IMAGE_RES + every { 10.0.dp() } returns 20.0 imageLocal = Image(ImagePath.Local("imageName")) imageRemote = Image(ImagePath.Remote(DEFAULT_URL, ImagePath.Local("imageName"))).applyStyle(style) @@ -169,5 +176,17 @@ internal class ImageTest : BaseComponentTest() { // Then verify(exactly = 1) { imageView.setImageResource(IMAGE_RES) } } + + @Test + @DisplayName("Then set corner radius correctly") + fun testCornerRadius() { + // When + imageRemote.buildView(rootView) + + // Then + verify { + anyConstructed().makeImageView(rootView.getContext(), 20.0) + } + } } } \ No newline at end of file