forked from facebook/react-native
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(refactor): kotlinify
JSPointerDispatcherTest.java
(facebook#38878)
Summary: This PR converts the java logic inside of `JSPointerDispatcherTest.java` to Kotlin as requested in facebook#38825 We also swap `JSPointerDispatcherTest.java` for `JSPointerDispatcherTest.kt` ## Changelog: [Internal][Changed]: Convert JSPointerDispatcherTest to Kotlin Pull Request resolved: facebook#38878 Test Plan: `./gradlew :packages:react-native:ReactAndroid:test` must pass and CI must be green ## Screenshot of Tests passing locally:  Reviewed By: rshest Differential Revision: D48189629 Pulled By: cortinico fbshipit-source-id: 92d869f690457986413bcae33a15225aa6e006be
- Loading branch information
1 parent
51faa18
commit 5657d2d
Showing
2 changed files
with
82 additions
and
97 deletions.
There are no files selected for viewing
97 changes: 0 additions & 97 deletions
97
...tive/ReactAndroid/src/test/java/com/facebook/react/uimanager/JSPointerDispatcherTest.java
This file was deleted.
Oops, something went wrong.
82 changes: 82 additions & 0 deletions
82
...native/ReactAndroid/src/test/java/com/facebook/react/uimanager/JSPointerDispatcherTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
package com.facebook.react.uimanager | ||
|
||
import android.content.Context | ||
import android.graphics.Rect | ||
import android.os.SystemClock | ||
import android.view.MotionEvent | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import android.widget.LinearLayout | ||
import android.widget.TextView | ||
import com.facebook.react.uimanager.events.Event | ||
import com.facebook.react.uimanager.events.EventDispatcher | ||
import com.facebook.react.uimanager.events.PointerEventHelper | ||
import org.junit.Before | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.mockito.ArgumentMatcher | ||
import org.mockito.Mockito.argThat | ||
import org.mockito.Mockito.mock | ||
import org.mockito.Mockito.verify | ||
import org.robolectric.RobolectricTestRunner | ||
import org.robolectric.RuntimeEnvironment | ||
|
||
@RunWith(RobolectricTestRunner::class) | ||
class JSPointerDispatcherTest { | ||
|
||
private lateinit var root: ViewGroup | ||
private lateinit var pointerDispatcher: JSPointerDispatcher | ||
|
||
class EventWithName(private val eventName: String) : ArgumentMatcher<Event<Event<*>>> { | ||
override fun matches(argument: Event<Event<*>>?): Boolean = argument?.eventName == eventName | ||
|
||
override fun toString(): String = "[event with name: $eventName]" | ||
} | ||
|
||
@Before | ||
fun setupViewHierarchy() { | ||
val ctx: Context = RuntimeEnvironment.application | ||
root = LinearLayout(ctx) | ||
val childView = TextView(ctx) | ||
childView.append("Hello, world!") | ||
childView.id = 100 | ||
root.addView(childView) | ||
root.measure(500, 500) | ||
root.layout(0, 0, 500, 500) | ||
pointerDispatcher = JSPointerDispatcher(root) | ||
} | ||
|
||
private fun createMotionEvent(action: Int, x: Float, y: Float): MotionEvent { | ||
val downTime = SystemClock.uptimeMillis() | ||
val eventTime = downTime | ||
val metaState = 0 // no modifiers pressed | ||
|
||
return MotionEvent.obtain(downTime, eventTime, action, x, y, metaState) | ||
} | ||
|
||
private fun getChildViewRectInRootCoordinates(childIndex: Int): Rect { | ||
val child: View = root.getChildAt(childIndex) | ||
val outRect = Rect() | ||
child.getDrawingRect(outRect) | ||
root.offsetDescendantRectToMyCoords(child, outRect) | ||
return outRect | ||
} | ||
|
||
@Test | ||
fun testPointerEnter() { | ||
val childRect = getChildViewRectInRootCoordinates(0) | ||
val ev = | ||
createMotionEvent( | ||
MotionEvent.ACTION_DOWN, childRect.centerX().toFloat(), childRect.centerY().toFloat()) | ||
val mockDispatcher: EventDispatcher = mock(EventDispatcher::class.java) | ||
pointerDispatcher.handleMotionEvent(ev, mockDispatcher, false) | ||
verify(mockDispatcher).dispatchEvent(argThat(EventWithName(PointerEventHelper.POINTER_DOWN))) | ||
} | ||
} |