Skip to content
This repository has been archived by the owner on Jun 1, 2024. It is now read-only.

Commit

Permalink
refactor: changed PullToRefresh contract
Browse files Browse the repository at this point in the history
Signed-off-by: Paulo Cesar Meurer <[email protected]>
  • Loading branch information
paulomeurerzup committed Jun 17, 2021
1 parent f5d968c commit 4a52b03
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,23 @@ 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(
override val context: ContextData? = null,
val onPull: List<Action>,
val isRefreshing: Bind<Boolean>? = null,
val color: Bind<String>? = null,
val child: ServerDrivenComponent? = null,
) : WidgetView(), ContextComponent {
override val child: ServerDrivenComponent,
) : WidgetView(), ContextComponent, SingleChildComponent {

constructor(
context: ContextData?,
onPull: List<Action>,
isRefreshing: Bind<Boolean>? = null,
color: String? = null,
child: ServerDrivenComponent? = null,
child: ServerDrivenComponent,
) : this(
context = context,
onPull = onPull,
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,44 +141,44 @@ 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
pullToRefreshComponent.buildView(rootView)

// 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
pullToRefreshComponent.buildView(rootView)

// Then
verify(exactly = 0) {
beagleFlexView.addView(child, false)
pullToRefreshComponent.observeBindChanges(rootView, swipeRefreshLayout, color, captureLambda())
}
}
}
Expand Down

0 comments on commit 4a52b03

Please sign in to comment.