androidx.glance.testing.unit

Classes

GlanceMappedNode

An implementation of GlanceNode node that uses MappedNode to perform assertions during testing.

MappedNode

Hold a Glance composable node in a form that enables performing assertion on it.

Top-level functions summary

GlanceNodeMatcher<MappedNode>

Returns a matcher that matches if a given node has a descendant node somewhere in its sub-hierarchy that the matches the provided matcher.

GlanceNodeMatcher<MappedNode>

Returns a matcher that matches if the given node has clickable modifier set.

GlanceNodeMatcher<MappedNode>
hasContentDescription(value: String, ignoreCase: Boolean)

Returns whether the content description set directly on the node contains the provided value.

GlanceNodeMatcher<MappedNode>

Returns whether the content description set directly on the node is equal to the provided value.

GlanceNodeMatcher<MappedNode>

Returns a matcher that matches if the given node doesn't have a clickable modifier or onClick set.

GlanceNodeMatcher<MappedNode>
hasStartActivityClickAction(
    componentName: ComponentName,
    parameters: ActionParameters
)

Returns a matcher that matches if a given node has a clickable set with action that starts an activity.

inline GlanceNodeMatcher<MappedNode>
<T : Activity> hasStartActivityClickAction(
    parameters: ActionParameters,
    activityOptions: Bundle?
)

Returns a matcher that matches if a given node has a clickable set with action that starts an activity.

GlanceNodeMatcher<MappedNode>
hasTestTag(testTag: String)

Returns a matcher that matches if a node is annotated by the given test tag.

GlanceNodeMatcher<MappedNode>
hasText(text: String, ignoreCase: Boolean)

Returns a matcher that matches if text on node contains the provided text as its substring.

GlanceNodeMatcher<MappedNode>
hasTextEqualTo(text: String, ignoreCase: Boolean)

Returns a matcher that matches if node is a text node and its text is equal to the provided text.

Extension functions summary

GlanceNodeAssertion<MappedNodeGlanceMappedNode>

Asserts that a given node has a clickable modifier or onClick set.

GlanceNodeAssertion<MappedNodeGlanceMappedNode>

Asserts that the content description set on the node contains the provided value as substring.

GlanceNodeAssertion<MappedNodeGlanceMappedNode>

Asserts that the content description set on the node is equal to the provided value

GlanceNodeAssertion<MappedNodeGlanceMappedNode>

Asserts that a given node doesn't have a clickable modifier or onClick set.

GlanceNodeAssertion<MappedNodeGlanceMappedNode>

Asserts that a given node has a clickable set with action that starts an activity.

inline GlanceNodeAssertion<MappedNodeGlanceMappedNode>

Asserts that a given node has a clickable set with action that starts an activity.

GlanceNodeAssertion<MappedNodeGlanceMappedNode>

Asserts that a given node is annotated by the given test tag.

GlanceNodeAssertion<MappedNodeGlanceMappedNode>

Asserts that text on the given node is a text node and its text contains the provided text as substring.

GlanceNodeAssertion<MappedNodeGlanceMappedNode>

Asserts that text on the given node is text node and its text is equal to the provided text.

Top-level functions

hasAnyDescendant

fun hasAnyDescendant(matcher: GlanceNodeMatcher<MappedNode>): GlanceNodeMatcher<MappedNode>

Returns a matcher that matches if a given node has a descendant node somewhere in its sub-hierarchy that the matches the provided matcher.

This can be passed in GlanceNodeAssertionsProvider.onNode and GlanceNodeAssertionsProvider.onAllNodes functions on assertion providers to filter out matching node(s) or in assertions to validate that node(s) satisfy the condition.

Parameters
matcher: GlanceNodeMatcher<MappedNode>

a matcher that needs to be satisfied for the descendant node to be matched

hasClickAction

fun hasClickAction(): GlanceNodeMatcher<MappedNode>

Returns a matcher that matches if the given node has clickable modifier set.

This can be passed in GlanceNodeAssertionsProvider.onNode and GlanceNodeAssertionsProvider.onAllNodes functions on assertion providers to filter out matching node(s) or in assertions to validate that node(s) satisfy the condition.

hasContentDescription

fun hasContentDescription(value: String, ignoreCase: Boolean = false): GlanceNodeMatcher<MappedNode>

Returns whether the content description set directly on the node contains the provided value.

This can be passed in GlanceNodeAssertionsProvider.onNode and GlanceNodeAssertionsProvider.onAllNodes functions on assertion providers to filter out matching node(s) or in assertions to validate that node(s) satisfy the condition.

Parameters
value: String

value that should be substring of the content description set directly on the node.

ignoreCase: Boolean = false

whether case should be ignored. Default is case sensitive.

hasContentDescriptionEqualTo

fun hasContentDescriptionEqualTo(value: String, ignoreCase: Boolean = false): GlanceNodeMatcher<MappedNode>

Returns whether the content description set directly on the node is equal to the provided value.

This can be passed in GlanceNodeAssertionsProvider.onNode and GlanceNodeAssertionsProvider.onAllNodes functions on assertion providers to filter out matching node(s) or in assertions to validate that node(s) satisfy the condition.

Parameters
value: String

value that should match exactly with content description set directly on the node.

ignoreCase: Boolean = false

whether case should be ignored. Default is case sensitive.

hasNoClickAction

fun hasNoClickAction(): GlanceNodeMatcher<MappedNode>

Returns a matcher that matches if the given node doesn't have a clickable modifier or onClick set.

This can be passed in GlanceNodeAssertionsProvider.onNode and GlanceNodeAssertionsProvider.onAllNodes functions on assertion providers to filter out matching node(s) or in assertions to validate that node(s) satisfy the condition.

hasStartActivityClickAction

fun hasStartActivityClickAction(
    componentName: ComponentName,
    parameters: ActionParameters = actionParametersOf()
): GlanceNodeMatcher<MappedNode>

Returns a matcher that matches if a given node has a clickable set with action that starts an activity.

This can be passed in GlanceNodeAssertionsProvider.onNode and GlanceNodeAssertionsProvider.onAllNodes functions on assertion providers to filter out matching node(s) or in assertions to validate that node(s) satisfy the condition.

Parameters
componentName: ComponentName

component of the activity that is expected to have been passed in the actionStartActivity method call

parameters: ActionParameters = actionParametersOf()

the parameters associated with the action that are expected to have been passed in the actionStartActivity method call

hasStartActivityClickAction

inline fun <T : Activity> hasStartActivityClickAction(
    parameters: ActionParameters = actionParametersOf(),
    activityOptions: Bundle? = null
): GlanceNodeMatcher<MappedNode>

Returns a matcher that matches if a given node has a clickable set with action that starts an activity.

This can be passed in GlanceNodeAssertionsProvider.onNode and GlanceNodeAssertionsProvider.onAllNodes functions on assertion providers to filter out matching node(s) or in assertions to validate that node(s) satisfy the condition.

Parameters
<T : Activity>

class of the activity that is expected to have been passed in the actionStartActivity method call

parameters: ActionParameters = actionParametersOf()

the parameters associated with the action that are expected to have been passed in the actionStartActivity method call

activityOptions: Bundle? = null

Additional options built from an android.app.ActivityOptions that are expected to have been passed in the actionStartActivity method call

hasTestTag

fun hasTestTag(testTag: String): GlanceNodeMatcher<MappedNode>

Returns a matcher that matches if a node is annotated by the given test tag.

This can be passed in GlanceNodeAssertionsProvider.onNode and GlanceNodeAssertionsProvider.onAllNodes functions on assertion providers to filter out matching node(s) or in assertions to validate that node(s) satisfy the condition.

Parameters
testTag: String

value to match against the free form string specified in the testTag semantics modifier on the Glance composable nodes.

hasText

fun hasText(text: String, ignoreCase: Boolean = false): GlanceNodeMatcher<MappedNode>

Returns a matcher that matches if text on node contains the provided text as its substring.

This can be passed in GlanceNodeAssertionsProvider.onNode and GlanceNodeAssertionsProvider.onAllNodes functions on assertion providers to filter out matching node(s) or in assertions to validate that node(s) satisfy the condition.

Parameters
text: String

value that should be matched as a substring of the node's text.

ignoreCase: Boolean = false

whether to perform case insensitive matching. Defaults to case sensitive matching.

hasTextEqualTo

fun hasTextEqualTo(text: String, ignoreCase: Boolean = false): GlanceNodeMatcher<MappedNode>

Returns a matcher that matches if node is a text node and its text is equal to the provided text.

This can be passed in GlanceNodeAssertionsProvider.onNode and GlanceNodeAssertionsProvider.onAllNodes functions on assertion providers to filter out matching node(s) or in assertions to validate that node(s) satisfy the condition.

Parameters
text: String

value that should exactly match the node's text.

ignoreCase: Boolean = false

whether to perform case insensitive matching. Defaults to case sensitive matching.

Extension functions

assertHasClickAction

fun GlanceNodeAssertion<MappedNodeGlanceMappedNode>.assertHasClickAction(

): GlanceNodeAssertion<MappedNodeGlanceMappedNode>

Asserts that a given node has a clickable modifier or onClick set.

Throws
kotlin.AssertionError

if the matcher does not match or the node can no longer be found.

assertHasContentDescription

fun GlanceNodeAssertion<MappedNodeGlanceMappedNode>.assertHasContentDescription(
    value: String,
    ignoreCase: Boolean = false
): GlanceNodeAssertion<MappedNodeGlanceMappedNode>

Asserts that the content description set on the node contains the provided value as substring.

Parameters
value: String

value that should be matched as a substring of the node's content description.

ignoreCase: Boolean = false

whether case should be ignored. Defaults to case sensitive.

Throws
kotlin.AssertionError

if the matcher does not match or the node can no longer be found.

assertHasContentDescriptionEqualTo

fun GlanceNodeAssertion<MappedNodeGlanceMappedNode>.assertHasContentDescriptionEqualTo(
    value: String,
    ignoreCase: Boolean = false
): GlanceNodeAssertion<MappedNodeGlanceMappedNode>

Asserts that the content description set on the node is equal to the provided value

Parameters
value: String

value that should be matched to be equal to the node's content description.

ignoreCase: Boolean = false

whether case should be ignored. Defaults to case sensitive.

Throws
kotlin.AssertionError

if the matcher does not match or the node can no longer be found.

assertHasNoClickAction

fun GlanceNodeAssertion<MappedNodeGlanceMappedNode>.assertHasNoClickAction(

): GlanceNodeAssertion<MappedNodeGlanceMappedNode>

Asserts that a given node doesn't have a clickable modifier or onClick set.

Throws
kotlin.AssertionError

if the matcher does not match or the node can no longer be found.

assertHasStartActivityClickAction

fun GlanceNodeAssertion<MappedNodeGlanceMappedNode>.assertHasStartActivityClickAction(
    componentName: ComponentName,
    parameters: ActionParameters = actionParametersOf()
): GlanceNodeAssertion<MappedNodeGlanceMappedNode>

Asserts that a given node has a clickable set with action that starts an activity.

Parameters
componentName: ComponentName

component of the activity that is expected to have been passed in the actionStartActivity method call

parameters: ActionParameters = actionParametersOf()

the parameters associated with the action that are expected to have been passed in the actionStartActivity method call

Throws
kotlin.AssertionError

if the matcher does not match or the node can no longer be found.

assertHasStartActivityClickAction

inline fun <T : Activity> GlanceNodeAssertion<MappedNodeGlanceMappedNode>.assertHasStartActivityClickAction(
    parameters: ActionParameters = actionParametersOf(),
    activityOptions: Bundle? = null
): GlanceNodeAssertion<MappedNodeGlanceMappedNode>

Asserts that a given node has a clickable set with action that starts an activity.

Parameters
<T : Activity>

class of the activity that is expected to have been passed in the actionStartActivity method call

parameters: ActionParameters = actionParametersOf()

the parameters associated with the action that are expected to have been passed in the actionStartActivity method call

activityOptions: Bundle? = null

Additional options built from an android.app.ActivityOptions that are expected to have been passed in the actionStartActivity method call

Throws
kotlin.AssertionError

if the matcher does not match or the node can no longer be found.

assertHasTestTag

fun GlanceNodeAssertion<MappedNodeGlanceMappedNode>.assertHasTestTag(
    testTag: String
): GlanceNodeAssertion<MappedNodeGlanceMappedNode>

Asserts that a given node is annotated by the given test tag.

Parameters
testTag: String

value to match against the free form string specified in the testTag semantics modifier on the Glance composable nodes.

Throws
kotlin.AssertionError

if the matcher does not match or the node can no longer be found.

assertHasText

fun GlanceNodeAssertion<MappedNodeGlanceMappedNode>.assertHasText(
    text: String,
    ignoreCase: Boolean = false
): GlanceNodeAssertion<MappedNodeGlanceMappedNode>

Asserts that text on the given node is a text node and its text contains the provided text as substring.

Parameters
text: String

value to match.

ignoreCase: Boolean = false

whether to perform case insensitive matching

assertHasTextEqualTo

fun GlanceNodeAssertion<MappedNodeGlanceMappedNode>.assertHasTextEqualTo(
    text: String,
    ignoreCase: Boolean = false
): GlanceNodeAssertion<MappedNodeGlanceMappedNode>

Asserts that text on the given node is text node and its text is equal to the provided text.

Parameters
text: String

value to match.

ignoreCase: Boolean = false

whether to perform case insensitive matching