[go: nahoru, domu]

[TextField Selection] Add FloatingToolbar

Bug: 139311080
Bug: 139311179
Bug: 139311532

Test: Manually Tested.
Test: ./gradlew :ui:ui-core:testDebugUnitTest
Test: ./gradlew :ui:ui-text:testDebugUnitTest

RelNote: Add FloatingToolbar for TextField Selection.
Change-Id: Ie8b07e4405940f9d4b4147c34406c80a557b4d45
diff --git a/ui/ui-text/src/test/kotlin/androidx/ui/text/selection/TextFieldSelectionManagerTest.kt b/ui/ui-text/src/test/kotlin/androidx/ui/text/selection/TextFieldSelectionManagerTest.kt
index 7ed0c43..3a226e0 100644
--- a/ui/ui-text/src/test/kotlin/androidx/ui/text/selection/TextFieldSelectionManagerTest.kt
+++ b/ui/ui-text/src/test/kotlin/androidx/ui/text/selection/TextFieldSelectionManagerTest.kt
@@ -22,6 +22,8 @@
 import androidx.ui.core.clipboard.ClipboardManager
 import androidx.ui.core.hapticfeedback.HapticFeedback
 import androidx.ui.core.hapticfeedback.HapticFeedbackType
+import androidx.ui.core.texttoolbar.TextToolbar
+import androidx.ui.geometry.Rect
 import androidx.ui.geometry.Offset
 import androidx.ui.input.OffsetMap
 import androidx.ui.input.TextFieldValue
@@ -66,6 +68,7 @@
     private val manager = TextFieldSelectionManager()
 
     private val clipboardManager = mock<ClipboardManager>()
+    private val textToolbar = mock<TextToolbar>()
     private val hapticFeedback = mock<HapticFeedback>()
 
     @Before
@@ -75,6 +78,7 @@
         manager.state = state
         manager.value = value
         manager.clipboardManager = clipboardManager
+        manager.textToolbar = textToolbar
         manager.hapticFeedBack = hapticFeedback
 
         state.layoutResult = mock()
@@ -100,6 +104,7 @@
         whenever(state.layoutResult!!.getWordBoundary(dragOffset)).thenReturn(dragTextRange)
         whenever(state.layoutResult!!.getBidiRunDirection(any()))
             .thenReturn(ResolvedTextDirection.Ltr)
+        whenever(state.layoutResult!!.getBoundingBox(any())).thenReturn(Rect.zero)
     }
 
     @Test
@@ -276,4 +281,16 @@
         assertThat(value.selection).isEqualTo(TextRange("Hello".length, "Hello".length))
         assertThat(state.selectionIsOn).isFalse()
     }
+
+    @Test
+    fun showSelectionToolbar_trigger_textToolbar_showPasteMenu() {
+        manager.value = TextFieldValue(
+            text = text + text,
+            selection = TextRange("Hello".length, text.length)
+        )
+
+        manager.showSelectionToolbar()
+
+        verify(textToolbar, times(1)).showPasteMenu(any(), any(), any(), any())
+    }
 }