Improve iOS Instrumented Tests for textfields - #3277
Conversation
b85c9db to
ed10805
Compare
| } | ||
|
|
||
| /** Taps character [offset] in the text field tagged [tag]. */ | ||
| internal fun UIKitInstrumentedTest.tapCharacter(tag: String, offset: Int) { |
There was a problem hiding this comment.
In the touches simulation API we're using the UIKitInstrumentedTest only to start initial touch. All other manipulations are done with the UITouch itself. The reason here - to narrow down API surface of the UIKitInstrumentedTest.
Here I would suggest doing kinda the same - make tapCharacter and other methods as extension of the SemanticsNode (or even AccessibilityTestNode - see P.S section).
P.S. Totally optional, but anyway:
Technically, AccessibilityTestNode also contains reference to the corresponding SemanticsNode. It will be (AccessibilityTestNode.element as? AccessibilityElement).node?.semanticsNode, but the problem is - AccessibilityElement is private. So we need some workaround to access the semanticsNode.
There was a problem hiding this comment.
done
also added dragSelectionHandle to the AccessibilityTestNode, however, inside there're lots of implementation methods which I didn't want to move to the UIKitInstrumentTest, so I had to leave UIKitInstrumentTest.dragSelectionHandleImpl.
…ew`. Removed comment in `TextFieldCaretPlacementTest`. Added examples for caret placement and selection handles tests using new API, rewritten multitap tests using new API, extracted BasicTextFieldType to the TextField+Utils.kt to reduce duplicates Added SelectionContainer tests examples for new API refactored native handles detection and dragging, refactored drag gesture, considered positional hysteresis for native handles, fine-tuned stop conditions, cleaned the code and comments Moved `objcClassName` utility to UIView+Utils; removed redundant imports in TextField+Utils. Added todo Fixed native selection handle dragging, updated & fixed comments Updated `characterPosition` documentation to clarify iOS caret snap behavior to word boundaries. Added support for native iOS text selection handles and updated handle utilities for unified behavior across native and Compose-rendered handles. Simplify `TestHandle` and `TestSelectionHandleAnchor` enums by removing unused cases for iOS rendering. Removed the method of fetching cursor handle from the semantics - it would be noop on ios Add utilities for testing text selection handles and update `rootForTestListener` handling in iOS platform code to be able to grab selection handles since they're popups Added character-based text field utilities for iOS (`characterPosition`, `tapCharacter`, `longPressCharacter`, and `multiTapCharacter`) to support advanced gesture handling. Implemented `rootForTestListener` to support test roots tracking in iOS platform code.
6f34aab to
b558553
Compare
…tyTestNode` API, removed redundant utility methods, and updated gesture interaction logic for iOS.
…`internal` to `private`.
|
I tried the API, especially for the selection handles, looks like what we needed for our cases, thank you. So for now approve from my side. |
PlatformContext.RootForTestListenerpropagation to the iOS layerNew test API (internal)
test/utils/TextField+Utils.kt
provides character positioning and tap utilities:
tapCharacter(tag, offset)longPressCharacter(tag, offset)multiTapCharacter(tag, offset, count)(for double/triple tap)All of these are based on
characterPosition, which reads fromTextLayoutResultviaRootForTestListenertest/utils/SelectionHandle+Utils.kt
provides utilities for selection handles:
selectionHandles()returns aSelectionHandlePairdragSelectionHandle(handle, tag, toOffset, duration = 0.5s)provides a single entry point for dragging a handle in Compose TextField, Native TextField, and SelectionContainerSelectionHandlePairis a helper data class that stores the start and end TestSelectionHandle in deterministic orderTestSelectionHandleis a data class containing the information required by tests, parsed from Compose SelectionHandle and iOS native SelectionHandle (_UITextSelectionLollipopView)Fixes:
CMP-10037 Extend iOSInstrumentedTest API for TextField testing
CMP-10648 [iOS] Instrumented Tests: native selection handle has a positional hysteresis when dragged downwards
Release Notes
N/A