diff --git a/ReactAndroid/src/androidTest/java/com/facebook/react/testing/ReactIntegrationTestCase.java b/ReactAndroid/src/androidTest/java/com/facebook/react/testing/ReactIntegrationTestCase.java index b8d85fe0f..8f24a0c1d 100644 --- a/ReactAndroid/src/androidTest/java/com/facebook/react/testing/ReactIntegrationTestCase.java +++ b/ReactAndroid/src/androidTest/java/com/facebook/react/testing/ReactIntegrationTestCase.java @@ -32,6 +32,9 @@ import com.facebook.react.common.ApplicationHolder; import com.facebook.react.common.futures.SimpleSettableFuture; import com.facebook.react.modules.core.Timing; +import com.facebook.soloader.SoLoader; + + /** * Use this class for writing integration tests of catalyst. This class will run all JNI call * within separate android looper, thus you don't need to care about starting your own looper. @@ -170,6 +173,7 @@ public abstract class ReactIntegrationTestCase extends AndroidTestCase { @Override protected void setUp() throws Exception { super.setUp(); + SoLoader.init(getContext(), /* native exopackage */ false); ApplicationHolder.setApplication((Application) getContext().getApplicationContext()); } diff --git a/ReactAndroid/src/androidTest/java/com/facebook/react/tests/BUCK b/ReactAndroid/src/androidTest/java/com/facebook/react/tests/BUCK index 7c678f8fa..5fc6dfeff 100644 --- a/ReactAndroid/src/androidTest/java/com/facebook/react/tests/BUCK +++ b/ReactAndroid/src/androidTest/java/com/facebook/react/tests/BUCK @@ -17,6 +17,8 @@ deps = [ react_native_target('java/com/facebook/react/views/swiperefresh:swiperefresh'), react_native_target('java/com/facebook/react:react'), react_native_target('java/com/facebook/react/common:common'), + react_native_target('java/com/facebook/react/modules/systeminfo:systeminfo'), + react_native_target('java/com/facebook/react/uimanager/annotations:annotations'), react_native_target('java/com/facebook/react/views/progressbar:progressbar'), react_native_target('java/com/facebook/react/views/recyclerview:recyclerview'), react_native_target('java/com/facebook/react/views/scroll:scroll'), diff --git a/ReactAndroid/src/androidTest/java/com/facebook/react/tests/ProgressBarTestCase.java b/ReactAndroid/src/androidTest/java/com/facebook/react/tests/ProgressBarTestCase.java new file mode 100644 index 000000000..b3282629b --- /dev/null +++ b/ReactAndroid/src/androidTest/java/com/facebook/react/tests/ProgressBarTestCase.java @@ -0,0 +1,130 @@ +/** + * Copyright (c) 2014-present, Facebook, Inc. + * All rights reserved. + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ + +package com.facebook.react.tests; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; + +import android.content.res.Resources; +import android.util.DisplayMetrics; +import android.util.TypedValue; +import android.view.View; +import android.view.ViewGroup; +import android.widget.FrameLayout; +import android.widget.ProgressBar; + +import com.facebook.react.ReactRootView; +import com.facebook.react.bridge.CatalystInstance; +import com.facebook.react.bridge.JavaScriptModule; +import com.facebook.react.bridge.UiThreadUtil; +import com.facebook.react.modules.systeminfo.AndroidInfoModule; +import com.facebook.react.uimanager.UIImplementation; +import com.facebook.react.uimanager.UIManagerModule; +import com.facebook.react.uimanager.ViewManager; +import com.facebook.react.views.progressbar.ReactProgressBarViewManager; +import com.facebook.react.views.view.ReactViewManager; +import com.facebook.react.testing.ReactIntegrationTestCase; +import com.facebook.react.testing.ReactTestHelper; + +/** + * Test to verify that Progress bar renders as a view of the right size + */ +public class ProgressBarTestCase extends ReactIntegrationTestCase { + + // Has same order of progressBars in ProgressBarTestModule + private static final String[] styleList = + new String[] {"Horizontal", "Small", "Large", "Inverse", "SmallInverse", "LargeInverse"}; + private static final HashMap styles = new HashMap(); + + static { + styles.put("Horizontal", android.R.attr.progressBarStyleHorizontal); + styles.put("Small", android.R.attr.progressBarStyleSmall); + styles.put("Large", android.R.attr.progressBarStyleLarge); + styles.put("Inverse", android.R.attr.progressBarStyleInverse); + styles.put("SmallInverse", android.R.attr.progressBarStyleSmallInverse); + styles.put("LargeInverse", android.R.attr.progressBarStyleLargeInverse); +} + + private static interface ProgressBarTestModule extends JavaScriptModule { + public void renderProgressBarApplication(int rootTag); + } + + private UIManagerModule mUIManager; + private CatalystInstance mInstance; + private ReactRootView mRootView; + + @Override + protected void setUp() throws Exception { + super.setUp(); + + List viewManagers = Arrays.asList( + new ReactViewManager(), + new ReactProgressBarViewManager()); + mUIManager = new UIManagerModule( + getContext(), + viewManagers, + new UIImplementation(getContext(), viewManagers)); + UiThreadUtil.runOnUiThread( + new Runnable() { + @Override + public void run() { + mUIManager.onHostResume(); + } + }); + waitForIdleSync(); + + mInstance = ReactTestHelper.catalystInstanceBuilder(this) + .addNativeModule(mUIManager) + .addNativeModule(new AndroidInfoModule()) + .addJSModule(ProgressBarTestModule.class) + .build(); + + mRootView = new ReactRootView(getContext()); + DisplayMetrics metrics = getContext().getResources().getDisplayMetrics(); + mRootView.setLayoutParams( + new FrameLayout.LayoutParams(metrics.widthPixels, metrics.heightPixels)); + int rootTag = mUIManager.addMeasuredRootView(mRootView); + mInstance.getJSModule(ProgressBarTestModule.class).renderProgressBarApplication(rootTag); + waitForBridgeAndUIIdle(); + } + + /** + * Test that the sizes of the progressBars are setup correctly + */ + public void testProgressBarSizes() { + for (String style : styleList) { + ProgressBar newProgressBar = + new ProgressBar(getContext(), null, styles.get(style)); + final int spec = View.MeasureSpec.makeMeasureSpec( + ViewGroup.LayoutParams.WRAP_CONTENT, + View.MeasureSpec.UNSPECIFIED); + newProgressBar.measure(spec, spec); + final int expectedHeight = newProgressBar.getMeasuredHeight(); + + // verify correct size of view containing ProgressBar + View viewContainingProgressBar = getViewByTestId(mRootView, style); + assertEquals(expectedHeight, viewContainingProgressBar.getHeight()); + + assertTrue(((ViewGroup) viewContainingProgressBar).getChildAt(0) instanceof ProgressBar); + } + } + + public void testProgressBarWidth() { + View viewContainingProgressBar = getViewByTestId(mRootView, "Horizontal200"); + assertEquals(viewContainingProgressBar.getWidth(), dpToPixels(200)); + ProgressBar progressBar = (ProgressBar) ((ViewGroup) viewContainingProgressBar).getChildAt(0); + assertEquals(progressBar.getWidth(), dpToPixels(200)); + } + + private int dpToPixels(int dp) { + Resources r = getContext().getResources(); + return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, r.getDisplayMetrics()); + } +} diff --git a/ReactAndroid/src/androidTest/js/ProgressBarTestModule.js b/ReactAndroid/src/androidTest/js/ProgressBarTestModule.js new file mode 100644 index 000000000..296cb8a2c --- /dev/null +++ b/ReactAndroid/src/androidTest/js/ProgressBarTestModule.js @@ -0,0 +1,54 @@ +/** + * Copyright (c) 2013-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + * + * @providesModule ProgressBarTestModule + */ + +"use strict"; + +var BatchedBridge = require('BatchedBridge'); +var React = require('React'); +var ProgressBar = require('ProgressBarAndroid'); +var View = require('View'); + +var renderApplication = require('renderApplication'); + +var ProgressBarSampleApp = React.createClass({ + render: function() { + return ( + + + + + + + + + + + + + ); + }, + getInitialState: function() { + return {}; + }, +}); + +var ProgressBarTestModule = { + renderProgressBarApplication: function(rootTag) { + renderApplication(ProgressBarSampleApp, {}, rootTag); + }, +}; + +BatchedBridge.registerCallableModule( + 'ProgressBarTestModule', + ProgressBarTestModule +); + +module.exports = ProgressBarTestModule; diff --git a/ReactAndroid/src/androidTest/js/TestBundle.js b/ReactAndroid/src/androidTest/js/TestBundle.js index 22476ff7b..86d044773 100644 --- a/ReactAndroid/src/androidTest/js/TestBundle.js +++ b/ReactAndroid/src/androidTest/js/TestBundle.js @@ -13,8 +13,9 @@ console.disableYellowBox = true; // Include modules used by integration tests -require('ScrollViewTestModule'); require('PickerAndroidTestModule'); +require('ProgressBarTestModule'); +require('ScrollViewTestModule'); require('SwipeRefreshLayoutTestModule'); require('TextInputTestModule');