From 3250594a82aae8304782c95236df15aebbc1b9a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?T=C3=BAlio=20Magalh=C3=A3es?= <55166462+tuliopereirazup@users.noreply.github.com> Date: Mon, 14 Sep 2020 10:39:27 -0300 Subject: [PATCH] fix: call removeAllViews before addView (#905) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Túlio Magalhães --- .../beagle/android/utils/ViewGroupExtensions.kt | 2 +- .../components/utils/ViewExtensionsKtTest.kt | 15 ++++++--------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/android/beagle/src/main/java/br/com/zup/beagle/android/utils/ViewGroupExtensions.kt b/android/beagle/src/main/java/br/com/zup/beagle/android/utils/ViewGroupExtensions.kt index 75d7ba5694..e8f57bbcc1 100644 --- a/android/beagle/src/main/java/br/com/zup/beagle/android/utils/ViewGroupExtensions.kt +++ b/android/beagle/src/main/java/br/com/zup/beagle/android/utils/ViewGroupExtensions.kt @@ -152,8 +152,8 @@ private fun loadView( loadView(screenRequest) } view.loadCompletedListener = { + viewGroup.removeAllViews() viewGroup.addView(view) - } view.listenerOnViewDetachedFromWindow = { viewModel.setViewCreated(rootView.getParentId()) diff --git a/android/beagle/src/test/java/br/com/zup/beagle/android/components/utils/ViewExtensionsKtTest.kt b/android/beagle/src/test/java/br/com/zup/beagle/android/components/utils/ViewExtensionsKtTest.kt index 77866e7cd5..2bf49c5c0a 100644 --- a/android/beagle/src/test/java/br/com/zup/beagle/android/components/utils/ViewExtensionsKtTest.kt +++ b/android/beagle/src/test/java/br/com/zup/beagle/android/components/utils/ViewExtensionsKtTest.kt @@ -39,15 +39,9 @@ import br.com.zup.beagle.android.view.custom.OnLoadCompleted import br.com.zup.beagle.android.view.custom.OnStateChanged import br.com.zup.beagle.android.view.viewmodel.GenerateIdViewModel import br.com.zup.beagle.android.view.viewmodel.ScreenContextViewModel -import io.mockk.Runs -import io.mockk.every +import io.mockk.* import io.mockk.impl.annotations.MockK import io.mockk.impl.annotations.RelaxedMockK -import io.mockk.just -import io.mockk.mockkStatic -import io.mockk.slot -import io.mockk.verify -import io.mockk.verifySequence import org.junit.Assert.assertEquals import org.junit.Test @@ -140,7 +134,7 @@ class ViewExtensionsKtTest : BaseTest() { } @Test - fun `loadView should addView when load complete`() { + fun `loadView should removeAllViews and addView when load complete`() { // Given val slot = slot() every { beagleView.loadCompletedListener = capture(slot) } just Runs @@ -151,7 +145,10 @@ class ViewExtensionsKtTest : BaseTest() { // Then assertEquals(beagleView, viewSlot.captured) - verify(exactly = once()) { viewGroup.addView(beagleView) } + verifyOrder { + viewGroup.removeAllViews() + viewGroup.addView(beagleView) + } }