-
Notifications
You must be signed in to change notification settings - Fork 25.1k
SimpleViewPropertyTest.java => SimpleViewPropertyTest.kt #38856
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
sapkotamadhusudan
wants to merge
2
commits into
facebook:main
from
sapkotamadhusudan:kotlin-ify-SimpleViewPropertyTest
Closed
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
118 changes: 0 additions & 118 deletions
118
...ative/ReactAndroid/src/test/java/com/facebook/react/uimanager/SimpleViewPropertyTest.java
This file was deleted.
Oops, something went wrong.
102 changes: 102 additions & 0 deletions
102
...-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/SimpleViewPropertyTest.kt
This file contains hidden or 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,102 @@ | ||
| /* | ||
| * 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.graphics.drawable.ColorDrawable | ||
| import android.view.View | ||
| import com.facebook.react.bridge.CatalystInstance | ||
| import com.facebook.react.bridge.JavaOnlyMap | ||
| import com.facebook.react.bridge.ReactApplicationContext | ||
| import com.facebook.react.bridge.ReactTestHelper.createMockCatalystInstance | ||
| import com.facebook.react.bridge.ReadableMap | ||
| import com.facebook.react.touch.JSResponderHandler | ||
| import com.facebook.react.uimanager.annotations.ReactProp | ||
| import org.assertj.core.api.Assertions | ||
| import org.junit.Before | ||
| import org.junit.Rule | ||
| import org.junit.Test | ||
| import org.junit.runner.RunWith | ||
| import org.powermock.core.classloader.annotations.PowerMockIgnore | ||
| import org.powermock.modules.junit4.rule.PowerMockRule | ||
| import org.robolectric.RobolectricTestRunner | ||
| import org.robolectric.RuntimeEnvironment | ||
|
|
||
| /** Verify [View] view property being applied properly by [SimpleViewManager] */ | ||
| @RunWith(RobolectricTestRunner::class) | ||
| @PowerMockIgnore("org.mockito.*", "org.robolectric.*", "androidx.*", "android.*") | ||
| class SimpleViewPropertyTest { | ||
|
|
||
| @get:Rule var rule = PowerMockRule() | ||
|
|
||
| private class ConcreteViewManager : SimpleViewManager<View?>() { | ||
| @ReactProp(name = "foo") fun setFoo(view: View, foo: Boolean) {} | ||
|
|
||
| @ReactProp(name = "bar") fun setBar(view: View, bar: ReadableMap?) {} | ||
|
|
||
| override fun createViewInstance(reactContext: ThemedReactContext): View { | ||
| return View(reactContext) | ||
| } | ||
|
|
||
| override fun getName(): String { | ||
| return "View" | ||
| } | ||
| } | ||
|
|
||
| private lateinit var mContext: ReactApplicationContext | ||
| private lateinit var mCatalystInstanceMock: CatalystInstance | ||
| private lateinit var mThemedContext: ThemedReactContext | ||
| private lateinit var mManager: ConcreteViewManager | ||
|
|
||
| @Before | ||
| fun setup() { | ||
| mContext = ReactApplicationContext(RuntimeEnvironment.getApplication()) | ||
| mCatalystInstanceMock = createMockCatalystInstance() | ||
| mContext.initializeWithInstance(mCatalystInstanceMock) | ||
| mThemedContext = ThemedReactContext(mContext, mContext) | ||
| mManager = ConcreteViewManager() | ||
| } | ||
|
|
||
| fun buildStyles(vararg keysAndValues: Any?): ReactStylesDiffMap { | ||
| return ReactStylesDiffMap(JavaOnlyMap.of(*keysAndValues)) | ||
| } | ||
|
|
||
| @Test | ||
| fun testOpacity() { | ||
| val view = | ||
| mManager.createView(sViewTag, mThemedContext, buildStyles(), null, JSResponderHandler()) | ||
| mManager.updateProperties(view, buildStyles()) | ||
| Assertions.assertThat(view.alpha).isEqualTo(1.0f) | ||
| mManager.updateProperties(view, buildStyles("opacity", 0.31)) | ||
| Assertions.assertThat(view.alpha).isEqualTo(0.31f, Assertions.offset(1e-5f)) | ||
| mManager.updateProperties(view, buildStyles("opacity", null)) | ||
| Assertions.assertThat(view.alpha).isEqualTo(1.0f) | ||
| } | ||
|
|
||
| @Test | ||
| fun testBackgroundColor() { | ||
| val view = | ||
| mManager.createView(sViewTag, mThemedContext, buildStyles(), null, JSResponderHandler()) | ||
| mManager.updateProperties(view, buildStyles()) | ||
| Assertions.assertThat(view.background).isEqualTo(null) | ||
| mManager.updateProperties(view, buildStyles("backgroundColor", 12)) | ||
| Assertions.assertThat((view.background as ColorDrawable).color).isEqualTo(12) | ||
| mManager.updateProperties(view, buildStyles("backgroundColor", null)) | ||
| Assertions.assertThat((view.background as ColorDrawable).color).isEqualTo(0) | ||
| } | ||
|
|
||
| @Test | ||
| fun testGetNativeProps() { | ||
| val nativeProps = mManager.nativeProps | ||
| Assertions.assertThat(nativeProps["foo"]).isEqualTo("boolean") | ||
| Assertions.assertThat(nativeProps["bar"]).isEqualTo("Map") | ||
| } | ||
|
|
||
| companion object { | ||
| private const val sViewTag = 2 | ||
|
||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIT: let's rename:
mContext -> context
mCatalystInstanceMock -> catalystInstanceMock
and so on...