Conversation
8e45e8f to
2a0c8fa
Compare
There was a problem hiding this comment.
Once all modifications are done your tests should looks like
@Test
fun search_compose_in_view() {
Log.time("Compose in View") {
withId(R.id.compose_in_view)
.getView()
.getSemanticsNodeInteraction(matcher = hasText(composeInViewTag))
.assertIsDisplayed()
}
}
@Test
fun search_view_in_compose() {
Log.time("View in Compose") {
withId(R.id.view_in_compose)
.getView()
.getSemanticsNodeInteraction(matcher = hasTestTag(viewInComposeTag))
.onView()
.hasText(viewInComposeTag)
.isDisplayed()
}
}
```| @Test | ||
| fun search_compose_in_view() { | ||
| Log.time("Compose in View") { | ||
| onView(withId(R.id.compose_in_view)) |
There was a problem hiding this comment.
here , we can avoid onView and just call withId(R.id.compose_in_view).getView()
| @Test | ||
| fun search_view_in_compose() { | ||
| Log.time("View in Compose") { | ||
| onView(withId(R.id.view_in_compose)) |
There was a problem hiding this comment.
the same withId(R.id. view_in_compose).getView()
| /** | ||
| * Extract view from [androidx.compose.ui.viewinterop.AndroidView] in Compose | ||
| */ | ||
| fun UltronComposeSemanticsNodeInteraction.fetchView(): View? = semanticsNodeInteraction.fetchView() |
There was a problem hiding this comment.
Please, take a look at this part of documentation. (https://open-tool.github.io/ultron/docs/common/extension#customize-operation-info)
To make new Ultron library method we need to follow few rules:
- The action/assertion should pass throw the Ultron core logic. So, you need to call special method for this.
- we also need to put action logic to the extension function of
UltronComposeSemanticsNodeInteractionclass. - It should has proper description for external library users
Smth like this:
@OptIn(InternalComposeUiApi::class)
fun UltronComposeSemanticsNodeInteraction.fetchView(): View? = execute(
UltronComposeOperationParams(
operationName = "Fetch Android interop view of '${semanticsNodeInteraction.getSelectorDescription()}'",
operationDescription = "Compose fetch Android interop view of '${semanticsNodeInteraction.getSelectorDescription()}' during $timeoutMs ms",
operationType = ComposeOperationType.FETCH_INTEROP_VIEW
)
) {
((it.fetchSemanticsNode()
.layoutInfo as? InteroperableComposeUiNode)?.getInteropView())
}Extend com.atiurin.ultron.core.compose.operation.ComposeOperationType with new enum values FETCH_INTEROP_VIEW, ON_INTEROP_VIEW
| /** | ||
| * Extract view from [androidx.compose.ui.viewinterop.AndroidView] in Compose | ||
| */ | ||
| @OptIn(InternalComposeUiApi::class) |
There was a problem hiding this comment.
We don't interact with SemanticsNodeInteraction directly, so this method should be deleted
| /** | ||
| * Extract view from [androidx.compose.ui.viewinterop.AndroidView] in Compose and wrap with Matcher | ||
| */ | ||
| fun UltronComposeSemanticsNodeInteraction.onView(): Matcher<View> = semanticsNodeInteraction.onView() |
There was a problem hiding this comment.
we also need to move fetch logic to ultron core
@OptIn(InternalComposeUiApi::class)
fun UltronComposeSemanticsNodeInteraction.onView(): Matcher<View> = execute(
UltronComposeOperationParams(
operationName = "Fetch and wrap Android interop view of '${semanticsNodeInteraction.getSelectorDescription()}' with Mather<View>",
operationDescription = "Compose fetch and wrap Android interop view of '${semanticsNodeInteraction.getSelectorDescription()}' with Mather<View> during $timeoutMs ms",
operationType = ComposeOperationType.ON_INTEROP_VIEW
)
) {
AndroidViewMatcher(
(semanticsNodeInteraction
.fetchSemanticsNode().layoutInfo as? InteroperableComposeUiNode)
?.getInteropView()
)
}| * Extract view from [androidx.compose.ui.viewinterop.AndroidView] in Compose and wrap with Matcher | ||
| */ | ||
| @OptIn(InternalComposeUiApi::class) | ||
| fun SemanticsNodeInteraction.onView(): Matcher<View> = AndroidViewMatcher((fetchSemanticsNode() |
| * Select Compose Node by [matcher] in a particular View | ||
| */ | ||
| @OptIn(InternalTestApi::class) | ||
| fun View.semanticsNodeInteraction( |
There was a problem hiding this comment.
lets rename this method to getSemanticsNodeInteraction and return ultron wrapper
@OptIn(InternalTestApi::class)
fun View.getSemanticsNodeInteraction(
matcher: SemanticsMatcher,
useUnmergedTree: Boolean = true
): UltronComposeSemanticsNodeInteraction {
val composeView = requireNotNull(this as? AbstractComposeView) { "View is not subtype of AbstractComposeView. It is ${this::class.java}" }
return UltronComposeSemanticsNodeInteraction(SemanticsNodeInteraction(
createTestContext(ViewAndroidTestOwner(composeView)),
useUnmergedTree,
matcher
))
}|
In general, this is a great PR. Thanks a lot for your time. Appreciate that |
No description provided.