NodeInfoTestHelper

Helper class for extracting NodeInfo from Views and creating predicates/extractors for testing NodeInfo properties.

This class provides utilities for testing accessibility properties and other NodeInfo fields in Litho component hierarchies. It centralizes the logic for extracting NodeInfo from views via the COMPONENT_NODE_INFO_ID tag.

Usage example:

// Get NodeInfo from a view
val nodeInfo = NodeInfoTestHelper.getNodeInfo(view)

// Create a predicate to check for a specific accessibility role
val predicate = NodeInfoTestHelper.createPropertyPredicate(
"accessibilityRole",
"android.widget.Button"
) { it.accessibilityRole }

// Create an extractor for debug output
val extractor = NodeInfoTestHelper.createPropertyExtractor(
"accessibilityRole"
) { it.accessibilityRole }

Types

Link copied to clipboard
fun interface PropertyExtractor<T>

Functional interface for extracting a property from NodeInfo.

Link copied to clipboard
fun interface PropertyFormatter<T>

Functional interface for formatting property values to readable strings.

Functions

Link copied to clipboard
fun <T> assertHasProperty(viewTree: ViewTree, propertyName: String, expectedValue: T, extractor: NodeInfoTestHelper.PropertyExtractor<T>, extractorFunction: Function<View, String>)

Asserts that a ViewTree contains a view with a NodeInfo that has the specified property value.

Link copied to clipboard
fun <T> createPropertyExtractor(propertyName: String, extractor: NodeInfoTestHelper.PropertyExtractor<T>, formatter: NodeInfoTestHelper.PropertyFormatter<T> = PropertyFormatter { it.toString() }): Function<View, String>

Creates an extractor function that extracts a property from NodeInfo and formats it for debug output.

Link copied to clipboard
fun <T> createPropertyPredicate(propertyName: String, expectedValue: T, extractor: NodeInfoTestHelper.PropertyExtractor<T>): Predicate<View>

Creates a predicate that checks if a view has a NodeInfo with a property matching the given value.

Link copied to clipboard

Extracts NodeInfo from a View if it has one attached via the COMPONENT_NODE_INFO_ID tag.