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

Commit

Permalink
fix: UndefinedWidget was not working for InputWidget and PageIndicato… (
Browse files Browse the repository at this point in the history
#515)

* fix: UndefinedWidget was not working for InputWidget and PageIndicatorComponent

* Create test cases for this error
  • Loading branch information
tuliopereirazup authored Jul 13, 2020
1 parent 91b51e9 commit 5ca1016
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@ package br.com.zup.beagle.android.widget
import android.annotation.SuppressLint
import android.graphics.Color
import android.view.View
import br.com.zup.beagle.android.components.form.InputWidget
import br.com.zup.beagle.android.components.page.PageIndicatorComponent
import br.com.zup.beagle.android.components.page.PageIndicatorOutput
import br.com.zup.beagle.android.setup.BeagleEnvironment
import br.com.zup.beagle.android.setup.Environment
import br.com.zup.beagle.android.view.ViewFactory

internal class UndefinedWidget : WidgetView() {
internal class UndefinedWidget : InputWidget(), PageIndicatorComponent {

private val viewFactory: ViewFactory = ViewFactory()

Expand All @@ -39,4 +42,14 @@ internal class UndefinedWidget : WidgetView() {
viewFactory.makeView(rootView.getContext())
}
}

override fun getValue(): Any { return "" }

override fun onErrorMessage(message: String) {}

override fun setCount(pages: Int) {}

override fun onItemUpdated(newIndex: Int) {}

override fun initPageView(pageIndicatorOutput: PageIndicatorOutput) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,38 @@ class BeagleMoshiTest : BaseTest() {
assertNotNull(JSONObject(jsonComponent))
}

@Test
fun make_should_return_moshi_to_serialize_a_UndefinedComponent_of_type_InputWidget() {
// Given
val component = FormInput(
name = RandomData.string(),
child = UndefinedWidget()
)

// When
val jsonComponent =
moshi.adapter(ServerDrivenComponent::class.java).toJson(component)

// Then
assertNotNull(JSONObject(jsonComponent))
}

@Test
fun make_should_return_moshi_to_serialize_a_UndefinedComponent_of_type_PageIndicatorComponent() {
// Given
val component = PageView(
children = listOf(),
pageIndicator = UndefinedWidget()
)

// When
val jsonComponent =
moshi.adapter(ServerDrivenComponent::class.java).toJson(component)

// Then
assertNotNull(JSONObject(jsonComponent))
}

@Test
fun moshi_should_deserialize_bindComponent() {
// Given
Expand Down

0 comments on commit 5ca1016

Please sign in to comment.