mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Add ReactViewGroupTest (#46843)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/46843 Add some simple tests for ReactViewGroup clipping logic Changelog: [Internal] Reviewed By: NickGerleman Differential Revision: D63903975 fbshipit-source-id: 8ce683a4aeba2f3916a26d7b4e93b4a30227c6d5
This commit is contained in:
committed by
Facebook GitHub Bot
parent
276e3a7df7
commit
eb04be8ec0
+79
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* 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.views.view
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.FrameLayout
|
||||
import com.facebook.react.internal.featureflags.ReactNativeFeatureFlagsForTests
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.Robolectric
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
class ReactViewGroupTest {
|
||||
|
||||
private lateinit var context: Context
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
ReactNativeFeatureFlagsForTests.setUp()
|
||||
context = Robolectric.buildActivity(Activity::class.java).create().get()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `View clipping - ensure allChildren properly resizes when adding views in sequence`() {
|
||||
val rvg = ReactViewGroup(context)
|
||||
rvg.left = 0
|
||||
rvg.right = 100
|
||||
rvg.top = 0
|
||||
rvg.bottom = 100
|
||||
FrameLayout(context).addView(rvg)
|
||||
rvg.removeClippedSubviews = true
|
||||
for (i in 0..20) {
|
||||
rvg.addViewWithSubviewClippingEnabled(TestView(context, i * 10), i)
|
||||
}
|
||||
rvg.updateClippingRect()
|
||||
assertThat(rvg.childCount).isEqualTo(10)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `View clipping - ensure allChildren properly resizes when adding views out of sequence`() {
|
||||
val rvg = ReactViewGroup(context)
|
||||
rvg.left = 0
|
||||
rvg.right = 100
|
||||
rvg.top = 0
|
||||
rvg.bottom = 100
|
||||
FrameLayout(context).addView(rvg)
|
||||
rvg.removeClippedSubviews = true
|
||||
for (i in 0..10) {
|
||||
rvg.addViewWithSubviewClippingEnabled(TestView(context, i * 10), i)
|
||||
}
|
||||
repeat(10) { rvg.addViewWithSubviewClippingEnabled(TestView(context, 90), 10) }
|
||||
rvg.updateClippingRect()
|
||||
assertThat(rvg.childCount).isEqualTo(20)
|
||||
}
|
||||
}
|
||||
|
||||
class TestView(context: Context, yPos: Int) : View(context) {
|
||||
init {
|
||||
left = 0
|
||||
right = 100
|
||||
top = yPos
|
||||
bottom = top + 10
|
||||
}
|
||||
}
|
||||
|
||||
class TestParent(context: Context) : ViewGroup(context) {
|
||||
override fun onLayout(changed: Boolean, l: Int, t: Int, r: Int, b: Int) = Unit
|
||||
}
|
||||
Reference in New Issue
Block a user