JetBrains / compose-multiplatform

Compose Multiplatform, a modern UI framework for Kotlin that makes building performant and beautiful user interfaces easy and enjoyable.
https://jetbrains.com/lp/compose-multiplatform
Apache License 2.0
15.24k stars 1.11k forks source link

Fix SemanticsNodeInteraction class properties visibility #4964

Closed aleks-ex closed 1 week ago

aleks-ex commented 1 week ago

The SemanticsNodeInteraction class is defined as follows:

class SemanticsNodeInteraction constructor(
    internal val testContext: TestContext,
    internal val useUnmergedTree: Boolean,
    internal val selector: SemanticsSelector
)

The properties testContext, useUnmergedTree, and selector have internal visibility. This restricts access to these properties from external code that utilizes the library. Consequently, it hinders the creation of custom extension functions necessary for certain testing scenarios.

Current testing API doesn't allow to search descendant deeper than 1st generation as SemanticsNodeInteraction has just onChildren() and onChildAt(index: Int) to find it. (commonMain/androidx/compose/ui/test/Selectors.kt)

For instance, the library provides extension functions for working with lists, such as:

/**
 * Returns children of this node.
 */
fun SemanticsNodeInteraction.onChildren(): SemanticsNodeInteractionCollection {
    return SemanticsNodeInteractionCollection(
        testContext,
        useUnmergedTree,
        selector.addSelectionFromSingleNode("children") { it.children }
    )
}

In my framework, I need to create similar extension functions with custom logic of target elements search. However, I am unable to do so because I do not have access to the testContext, useUnmergedTree, and selector properties.

I kindly request to change the visibility of these properties in the SemanticsNodeInteraction class from internal to public.

Jetpack Compose version: 1.6.7 Jetpack Compose component used: androidx.compose.ui:ui-test

aleks-ex commented 1 week ago

Similar issue in google tracker https://issuetracker.google.com/issues/342778294

Schahen commented 1 week ago

Hi! The thing is that SemanticsNodeInteraction belongs to a common code shared with Android Jetpack so whatever proposals you have on this API it's better to start here - https://github.com/androidx/androidx