LegacyLithoViewRule

class LegacyLithoViewRule @JvmOverloads constructor(val componentsConfiguration: ComponentsConfiguration? = null, val themeResId: Int? = null) : TestRule

Deprecated

Please use LithoViewRule and TestLithoView instead

This test utility allows clients to test assertion on the view hierarchy rendered by a Litho components. The utility has methods to override the default {@link LithoView}, {@link ComponentTree}, width, and height specs.

 @RunWith(AndroidJUnit4::class)
class LithoSampleTest {

@Rule @JvmField val lithoViewRule = LegacyLithoViewRule()
@Test
fun test() {
lithoViewRule.render { TestComponent() }

// or you can use setRoot/measure/layout for more fine-grained control
val lithoViewTest = lithoViewRule.attachToWindow().setRoot(TestComponent()).measure().layout()
// Test your assertions on the litho view.
}
}

Constructors

Link copied to clipboard
constructor(componentsConfiguration: ComponentsConfiguration? = null, themeResId: Int? = null)

Types

Link copied to clipboard
object Companion
Link copied to clipboard
inner class InteractionsScope

Class which exposes interactions that can take place on a view. Exposing interactions in this class ensures that they are only accessible within act, where the proper threading is taken into account to properly update the components and views.

Properties

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
val themeResId: Int? = null
Link copied to clipboard

Functions

Link copied to clipboard

Perform any interactions defined in the InteractionScope or on the LegacyLithoViewRule.

Link copied to clipboard
open override fun apply(base: Statement, description: Description): Statement
Link copied to clipboard

Explicitly attaches current root LithoView

Link copied to clipboard

Explicitly detaches current root LithoView

Link copied to clipboard
fun findAllComponents(vararg clazz: Class<out Component?>): List<Component>
fun findAllComponents(vararg clazz: KClass<out Component>): List<Component>

Returns a list of all components of the given classes from the ComponentTree or an empty list if not found

Link copied to clipboard

Returns a component of the given class from the ComponentTree or null if not found

Link copied to clipboard

Returns a component of the given class only if it is a direct child of the root component

Link copied to clipboard
fun findViewWithContentDescription(contentDescription: String): View

Finds the first View with the specified content description in the rendered hierarchy, throwing if it doesn't exist.

Link copied to clipboard

Finds the first View with the specified content description in the rendered hierarchy, returning null if is doesn't exist.

Link copied to clipboard

Finds the first View with the specified tag in the rendered hierarchy, throwing if it doesn't exist.

Link copied to clipboard

Finds the first View with the specified tag in the rendered hierarchy, returning null if is doesn't exist.

Link copied to clipboard
fun findViewWithText(@StringRes resourceId: Int): View

Finds the first View with the specified text in the rendered hierarchy, throwing if it doesn't exist.

Link copied to clipboard

Finds the first View with the specified text in the rendered hierarchy, returning null if is doesn't exist.

Link copied to clipboard
fun idle()

Runs through all tasks on the background thread and main lopper, blocking until it completes. Use if there are any async events triggered by layout ( ie visibility events) to manually drain the queue

Link copied to clipboard

Explicitly calls layout on the current root LithoView. If there are any async events triggered by layout use together with idle

Link copied to clipboard

Explicitly calls measure on the current root LithoView

Link copied to clipboard

Explicitly releases current root LithoView

Link copied to clipboard
fun render(componentFunction: ComponentScope.() -> Component?)

Sets the new root to render.

Link copied to clipboard

Runs through all tasks on the background thread only, not touching the main lopper, blocking until it completes.

Link copied to clipboard

Sets the new root Component.Builder to render.

Sets the new root Component to render.

Link copied to clipboard
fun setRootAndSizeSpecSync(component: Component?, widthSpec: Int, heightSpec: Int): LegacyLithoViewRule

Sets the new root Component with new size spec to render.

Link copied to clipboard

Sets the new root Component.Builder to render asynchronously.

Sets the new root Component to render asynchronously.

Link copied to clipboard
fun setSizePx(widthPx: Int, heightPx: Int): LegacyLithoViewRule

Sets a new width and height which should be used to render.

Link copied to clipboard
fun setSizeSpecs(widthSpec: Int, heightSpec: Int): LegacyLithoViewRule

Sets a new width spec and height spec which should be used to render.

Link copied to clipboard
fun setTreeProp(klass: Class<*>, instance: Any?): LegacyLithoViewRule

Sets a new TreeProp for the next layout pass.

Link copied to clipboard

Sets a new ComponentTree which should be used to render.

Link copied to clipboard
Link copied to clipboard

Sets a new LithoView which should be used to render.