diff --git a/android/beagle/src/main/java/br/com/zup/beagle/android/components/refresh/PullToRefresh.kt b/android/beagle/src/main/java/br/com/zup/beagle/android/components/refresh/PullToRefresh.kt index 6b472e5832..479a60b2db 100644 --- a/android/beagle/src/main/java/br/com/zup/beagle/android/components/refresh/PullToRefresh.kt +++ b/android/beagle/src/main/java/br/com/zup/beagle/android/components/refresh/PullToRefresh.kt @@ -31,6 +31,7 @@ import br.com.zup.beagle.android.widget.RootView import br.com.zup.beagle.android.widget.WidgetView import br.com.zup.beagle.annotation.RegisterWidget import br.com.zup.beagle.core.ServerDrivenComponent +import br.com.zup.beagle.core.SingleChildComponent @RegisterWidget("pullToRefresh") data class PullToRefresh constructor( @@ -38,15 +39,15 @@ data class PullToRefresh constructor( val onPull: List, val isRefreshing: Bind? = null, val color: Bind? = null, - val child: ServerDrivenComponent? = null, -) : WidgetView(), ContextComponent { + override val child: ServerDrivenComponent, +) : WidgetView(), ContextComponent, SingleChildComponent { constructor( context: ContextData?, onPull: List, isRefreshing: Bind? = null, color: String? = null, - child: ServerDrivenComponent? = null, + child: ServerDrivenComponent, ) : this( context = context, onPull = onPull, @@ -70,9 +71,7 @@ data class PullToRefresh constructor( } private fun buildChildView(rootView: RootView) = viewFactory.makeBeagleFlexView(rootView).apply { - child?.let { - addView(it, false) - } + addView(child, false) } private fun observeRefreshState(rootView: RootView, view: SwipeRefreshLayout) { diff --git a/android/beagle/src/test/java/br/com/zup/beagle/android/components/refresh/PullToRefreshTest.kt b/android/beagle/src/test/java/br/com/zup/beagle/android/components/refresh/PullToRefreshTest.kt index 1e3c760bcd..0095384455 100644 --- a/android/beagle/src/test/java/br/com/zup/beagle/android/components/refresh/PullToRefreshTest.kt +++ b/android/beagle/src/test/java/br/com/zup/beagle/android/components/refresh/PullToRefreshTest.kt @@ -141,15 +141,15 @@ class PullToRefreshTest : BaseComponentTest() { inner class PullToRefreshBuildWithNullParamsTest { @Test - @DisplayName("Then should not observe color changes") - fun testBuildNotObserveColor() { + @DisplayName("Then should not observe isRefreshing changes") + fun testBuildNotObserveIsRefreshing() { // Given pullToRefreshComponent = PullToRefresh( context, onPullActions, - isRefreshing, - null as String?, - null + null, + "#FF0000", + child ) // When @@ -157,20 +157,20 @@ class PullToRefreshTest : BaseComponentTest() { // Then verify(exactly = 0) { - pullToRefreshComponent.observeBindChanges(rootView, swipeRefreshLayout, color, captureLambda()) + pullToRefreshComponent.observeBindChanges(rootView, swipeRefreshLayout, isRefreshing, captureLambda()) } } @Test - @DisplayName("Then should not add child") - fun testBuildNotAddChild() { + @DisplayName("Then should not observe color changes") + fun testBuildNotObserveColor() { // Given pullToRefreshComponent = PullToRefresh( context, onPullActions, isRefreshing, - color, - null + null as String?, + child ) // When @@ -178,7 +178,7 @@ class PullToRefreshTest : BaseComponentTest() { // Then verify(exactly = 0) { - beagleFlexView.addView(child, false) + pullToRefreshComponent.observeBindChanges(rootView, swipeRefreshLayout, color, captureLambda()) } } }