Skip to content

Commit

Permalink
Fix KState extraction
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Luke De Feo authored and facebook-github-bot committed Jul 3, 2023
1 parent 62cb33b commit 20d7b57
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -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"))))))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 20d7b57

Please sign in to comment.