Class

SubspaceSemanticsMatcher

Wrapper for semantics matcher lambdas that allows building a description string explaining to the developer what conditions were being tested.

subspacePanelRenderedAndInteractive

@Sampled
public fun subspacePanelRenderedAndInteractive() {
    var count = 0

    composeTestRule.setContent {
        Subspace {
            SpatialPanel(SubspaceModifier.testTag("spatialPanel")) {
                Button(onClick = { count++ }) { Text("Increment") }
            }
        }
    }

    // Assert subspace node existence, position, and dimensions in the Spatial hierarchy
    composeTestRule
        .onSubspaceNodeWithTag("spatialPanel")
        .assertExists()
        .assertPositionInRootIsEqualTo(0.dp, 0.dp, 0.dp)

    // Interact with the 2D Compose node nested within the Spatial container
    composeTestRule.onNodeWithText("Increment").performClick()

    composeTestRule.waitForIdle()

    // Verify outcomes
    assert(count == 1)
}

subspaceNodeMatcherProperties

@Sampled
public fun subspaceNodeMatcherProperties() {
    composeTestRule.setContent {
        Subspace {
            SpatialPanel(SubspaceModifier.width(100.dp).height(100.dp).testTag("myPanel")) {}
        }
    }

    // Check existence and exact spatial dimensions in DP using semantic matchers
    composeTestRule
        .onSubspaceNodeWithTag("myPanel")
        .assertExists()
        .assertPositionInRootIsEqualTo(0.dp, 0.dp, 0.dp)
        .assertWidthIsEqualTo(100.dp)
        .assertHeightIsEqualTo(100.dp)
}

advancedSubspaceSemanticsMatchers

@Sampled
public fun advancedSubspaceSemanticsMatchers() {
    // Construct custom semantics matchers using factory methods
    val hasTestTag =
        SubspaceSemanticsMatcher.expectValue(SemanticsProperties.TestTag, "customPanel")
    val hasContentDescription =
        SubspaceSemanticsMatcher.keyIsDefined(SemanticsProperties.ContentDescription)

    // Combine matchers using infix functions and logical operators
    val complexMatcher = hasTestTag and hasContentDescription

    // Use the combined matcher to locate and assert existence of the spatial node
    composeTestRule.onSubspaceNode(complexMatcher).assertExists()
}
Jetpack Compose beyond MaterialFree components, screens and templates for apps that don’t look like Google’s. Copy them into your app, or let your coding agent add them.Browse for free

Content updated: