Skip to content

Commit

Permalink
Add tests to verify that getProps is not generated for MountSpecs
Browse files Browse the repository at this point in the history
Summary: We're disabling getProps generation in MountSpecs for now. This diff adds tests to verify this expectation

Reviewed By: zielinskimz

Differential Revision: D63395378

fbshipit-source-id: 51ba8701e8bbfdb9446fab3604ade1453915065a
  • Loading branch information
kingsleyadio authored and facebook-github-bot committed Sep 26, 2024
1 parent f78e18d commit d005f45
Showing 1 changed file with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,15 @@ import com.facebook.litho.Component
import com.facebook.litho.ComponentContext
import com.facebook.litho.annotations.ExcuseMySpec
import com.facebook.litho.annotations.LayoutSpec
import com.facebook.litho.annotations.MountSpec
import com.facebook.litho.annotations.OnCreateLayout
import com.facebook.litho.annotations.OnCreateMountContent
import com.facebook.litho.annotations.OnMount
import com.facebook.litho.annotations.Prop
import com.facebook.litho.annotations.Reason
import com.facebook.litho.specmodels.internal.RunMode
import com.facebook.litho.specmodels.processor.LayoutSpecModelFactory
import com.facebook.litho.specmodels.processor.MountSpecModelFactory
import com.google.testing.compile.CompilationRule
import org.assertj.core.api.Assertions
import org.junit.Rule
Expand All @@ -42,6 +46,7 @@ class ComponentBodyGeneratorTest {
@Rule @JvmField val compilationRule = CompilationRule()

private val layoutSpecModelFactory = LayoutSpecModelFactory()
private val mountSpecModelFactory = MountSpecModelFactory()
private val elements
get() = compilationRule.elements

Expand All @@ -58,6 +63,16 @@ class ComponentBodyGeneratorTest {
Assertions.assertThat(getPropsSpec).isNotNull()
}

@Test
fun generate_forMountSpec_doesNotGenerateGetPropsMethod() {
val typeElement = elements.getTypeElement(TestMountSpec::class.java.canonicalName)
val specModel =
mountSpecModelFactory.create(elements, types, typeElement, mock(), RunMode.normal(), null)
val typeSpecDataHolder = ComponentBodyGenerator.generate(specModel, null, RunMode.normal())
val getPropsSpec = typeSpecDataHolder.methodSpecs.find { it.name == "getProps" }
Assertions.assertThat(getPropsSpec).isNull()
}

@Test
fun generateGetPropsMethod_hasProps_generatesArrayOfProps() {
val typeElement = elements.getTypeElement(TestLayoutSpec::class.java.canonicalName)
Expand Down Expand Up @@ -119,3 +134,22 @@ private object EmptyTestLayoutSpec {
return Column.create(c).build()
}
}

@ExcuseMySpec(reason = Reason.LEGACY)
@MountSpec
private object TestMountSpec {

@OnCreateMountContent
fun onCreateMountContent(): Content {
return Content()
}

@OnMount
fun onMount(c: ComponentContext?, content: Content, @Prop prop: String) {
content.prop = prop
}
}

private class Content {
var prop: String? = null
}

0 comments on commit d005f45

Please sign in to comment.