Fix KState extraction
Summary: The field changed from mStates to states breaking our reflection based code. Ideally I would like to just check if type == KStateContainer and access the field normally but the rest of the infrastructure expect to work on a java field. Added tests to catch this sort of thing in the future. had to shift buck files around a bit to get it to work Reviewed By: antonk52 Differential Revision: D46974357 fbshipit-source-id: 87a6f5883b33e4d1a7359df5987fc7ead7c19033
This commit is contained in:
committed by
Facebook GitHub Bot
parent
62cb33b763
commit
20d7b57dbe
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import com.facebook.flipper.plugins.uidebugger.litho.descriptors.props.ComponentDataExtractor
|
||||
import com.facebook.flipper.plugins.uidebugger.model.InspectableArray
|
||||
import com.facebook.flipper.plugins.uidebugger.model.InspectableObject
|
||||
import com.facebook.flipper.plugins.uidebugger.model.InspectableValue
|
||||
import com.facebook.litho.KStateContainer
|
||||
import junit.framework.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
|
||||
class KStateContainerExtractionTest {
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testCanExtractKState() {
|
||||
|
||||
// this test ensures that our reflection based extraction doesn't break if the KState class
|
||||
// structure changes
|
||||
val stateContainer = KStateContainer.withNewState(null, "foo")
|
||||
|
||||
val result = ComponentDataExtractor.getState(stateContainer, "Comp1")
|
||||
|
||||
assertEquals(
|
||||
result,
|
||||
InspectableObject(mapOf(1 to InspectableArray(listOf(InspectableValue.Text("foo"))))))
|
||||
}
|
||||
}
|
||||
@@ -35,11 +35,11 @@ sealed class InspectableValue : Inspectable() {
|
||||
|
||||
@kotlinx.serialization.Serializable
|
||||
@SerialName("text")
|
||||
class Text(val value: String) : InspectableValue()
|
||||
data class Text(val value: String) : InspectableValue()
|
||||
|
||||
@kotlinx.serialization.Serializable
|
||||
@SerialName("boolean")
|
||||
class Boolean(val value: kotlin.Boolean) : InspectableValue()
|
||||
data class Boolean(val value: kotlin.Boolean) : InspectableValue()
|
||||
|
||||
@SerialName("number")
|
||||
@kotlinx.serialization.Serializable
|
||||
|
||||
Reference in New Issue
Block a user