diff --git a/ReactAndroid/src/androidTest/java/com/facebook/react/tests/BUCK b/ReactAndroid/src/androidTest/java/com/facebook/react/tests/BUCK index 5fc6dfeff..60795c49a 100644 --- a/ReactAndroid/src/androidTest/java/com/facebook/react/tests/BUCK +++ b/ReactAndroid/src/androidTest/java/com/facebook/react/tests/BUCK @@ -12,21 +12,24 @@ SANDCASTLE_FLAKY = [ deps = [ react_native_integration_tests_target('java/com/facebook/react/testing:testing'), react_native_target('java/com/facebook/react/bridge:bridge'), - react_native_target('java/com/facebook/react/uimanager:uimanager'), - react_native_target('java/com/facebook/react/views/picker:picker'), - 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/timepicker:timepicker'), + react_native_target('java/com/facebook/react/modules/datepicker:datepicker'), react_native_target('java/com/facebook/react/modules/systeminfo:systeminfo'), + react_native_target('java/com/facebook/react/uimanager:uimanager'), react_native_target('java/com/facebook/react/uimanager/annotations:annotations'), + react_native_target('java/com/facebook/react/views/picker:picker'), 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'), react_native_target('java/com/facebook/react/views/slider:slider'), + react_native_target('java/com/facebook/react/views/swiperefresh:swiperefresh'), react_native_target('java/com/facebook/react/views/text:text'), react_native_target('java/com/facebook/react/views/textinput:textinput'), react_native_target('java/com/facebook/react/views/view:view'), react_native_dep('third-party/android/support/v4:lib-support-v4'), + react_native_dep('third-party/java/junit:junit'), ] android_library( diff --git a/ReactAndroid/src/androidTest/java/com/facebook/react/tests/DatePickerDialogTestCase.java b/ReactAndroid/src/androidTest/java/com/facebook/react/tests/DatePickerDialogTestCase.java new file mode 100644 index 000000000..2ca86f482 --- /dev/null +++ b/ReactAndroid/src/androidTest/java/com/facebook/react/tests/DatePickerDialogTestCase.java @@ -0,0 +1,177 @@ +/** + * 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.ArrayList; +import java.util.Calendar; +import java.util.List; + +import android.app.DatePickerDialog; +import android.content.DialogInterface; +import android.support.v4.app.DialogFragment; +import android.support.v4.app.Fragment; +import android.widget.DatePicker; + +import com.facebook.react.bridge.BaseJavaModule; +import com.facebook.react.testing.ReactInstanceSpecForTest; +import com.facebook.react.bridge.ReactMethod; +import com.facebook.react.bridge.JavaScriptModule; +import com.facebook.react.bridge.WritableMap; +import com.facebook.react.bridge.WritableNativeMap; +import com.facebook.react.modules.datepicker.DatePickerDialogModule; +import com.facebook.react.testing.ReactAppInstrumentationTestCase; + +/** + * Test case for {@link DatePickerDialogModule} options and callbacks. + */ +public class DatePickerDialogTestCase extends ReactAppInstrumentationTestCase { + + private static interface DatePickerDialogTestModule extends JavaScriptModule { + public void showDatePickerDialog(WritableMap options); + } + + private static class DatePickerDialogRecordingModule extends BaseJavaModule { + + private final List mDates = new ArrayList(); + private int mDismissed = 0; + private int mErrors = 0; + + @Override + public String getName() { + return "DatePickerDialogRecordingModule"; + } + + @ReactMethod + public void recordDate(int year, int month, int day) { + mDates.add(new Integer[] {year, month, day}); + } + + @ReactMethod + public void recordDismissed() { + mDismissed++; + } + + @ReactMethod + public void recordError() { + mErrors++; + } + + public List getDates() { + return new ArrayList(mDates); + } + + public int getDismissed() { + return mDismissed; + } + + public int getErrors() { + return mErrors; + } + } + + final DatePickerDialogRecordingModule mRecordingModule = new DatePickerDialogRecordingModule(); + + @Override + protected ReactInstanceSpecForTest createReactInstanceSpecForTest() { + return super.createReactInstanceSpecForTest() + .addNativeModule(mRecordingModule) + .addJSModule(DatePickerDialogTestModule.class); + } + + @Override + protected String getReactApplicationKeyUnderTest() { + return "DatePickerDialogTestApp"; + } + + private static long getDateInMillis(int year, int month, int date) { + final Calendar c = Calendar.getInstance(); + c.set(Calendar.YEAR, year); + c.set(Calendar.MONTH, month); + c.set(Calendar.DATE, date); + return c.getTimeInMillis(); + } + + private DatePickerDialogTestModule getTestModule() { + return getReactContext().getCatalystInstance().getJSModule(DatePickerDialogTestModule.class); + } + + private DialogFragment showDialog(WritableMap options) { + getTestModule().showDatePickerDialog(options); + + waitForBridgeAndUIIdle(); + getInstrumentation().waitForIdleSync(); + + return (DialogFragment) getActivity().getSupportFragmentManager() + .findFragmentByTag(DatePickerDialogModule.FRAGMENT_TAG); + } + + public void testShowBasicDatePicker() { + final Fragment datePickerFragment = showDialog(null); + + assertNotNull(datePickerFragment); + } + + public void testPresetDate() { + final WritableMap options = new WritableNativeMap(); + options.putDouble("date", getDateInMillis(2020, 5, 6)); + + final DialogFragment datePickerFragment = showDialog(options); + final DatePicker datePicker = + ((DatePickerDialog) datePickerFragment.getDialog()).getDatePicker(); + + assertEquals(2020, datePicker.getYear()); + assertEquals(5, datePicker.getMonth()); + assertEquals(6, datePicker.getDayOfMonth()); + } + + public void testCallback() throws Throwable { + final WritableMap options = new WritableNativeMap(); + options.putDouble("date", getDateInMillis(2020, 5, 6)); + + final DialogFragment datePickerFragment = showDialog(options); + + runTestOnUiThread( + new Runnable() { + @Override + public void run() { + ((DatePickerDialog) datePickerFragment.getDialog()) + .getButton(DialogInterface.BUTTON_POSITIVE).performClick(); + } + }); + + getInstrumentation().waitForIdleSync(); + waitForBridgeAndUIIdle(); + + assertEquals(0, mRecordingModule.getErrors()); + assertEquals(1, mRecordingModule.getDates().size()); + assertEquals(2020, (int) mRecordingModule.getDates().get(0)[0]); + assertEquals(5, (int) mRecordingModule.getDates().get(0)[1]); + assertEquals(6, (int) mRecordingModule.getDates().get(0)[2]); + } + + public void testDismissCallback() throws Throwable { + final DialogFragment datePickerFragment = showDialog(null); + + runTestOnUiThread( + new Runnable() { + @Override + public void run() { + datePickerFragment.getDialog().dismiss(); + } + }); + + getInstrumentation().waitForIdleSync(); + waitForBridgeAndUIIdle(); + + assertEquals(0, mRecordingModule.getErrors()); + assertEquals(0, mRecordingModule.getDates().size()); + assertEquals(1, mRecordingModule.getDismissed()); + } + +} diff --git a/ReactAndroid/src/androidTest/java/com/facebook/react/tests/ReactRootViewTestCase.java b/ReactAndroid/src/androidTest/java/com/facebook/react/tests/ReactRootViewTestCase.java new file mode 100644 index 000000000..6ee0bed87 --- /dev/null +++ b/ReactAndroid/src/androidTest/java/com/facebook/react/tests/ReactRootViewTestCase.java @@ -0,0 +1,106 @@ +/** + * 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 android.view.View; +import android.view.ViewGroup; +import android.widget.FrameLayout; + +import com.facebook.react.testing.ReactInstanceSpecForTest; +import com.facebook.react.testing.ReactAppInstrumentationTestCase; +import com.facebook.react.testing.StringRecordingModule; +import com.facebook.react.ReactRootView; + +import org.junit.Ignore; + +/** + * Integration test for {@link ReactRootView}. + */ +public class ReactRootViewTestCase extends ReactAppInstrumentationTestCase { + + private StringRecordingModule mRecordingModule; + + @Override + protected String getReactApplicationKeyUnderTest() { + return "CatalystRootViewTestApp"; + } + + @Ignore("t6596940: fix intermittently failing test") + public void testResizeRootView() throws Throwable { + final ReactRootView rootView = (ReactRootView) getRootView(); + final View childView = rootView.getChildAt(0); + + assertEquals(rootView.getWidth(), childView.getWidth()); + + final int newWidth = rootView.getWidth() / 2; + + runTestOnUiThread( + new Runnable() { + @Override + public void run() { + rootView.setLayoutParams(new FrameLayout.LayoutParams( + newWidth, + ViewGroup.LayoutParams.MATCH_PARENT)); + } + }); + + getInstrumentation().waitForIdleSync(); + waitForBridgeAndUIIdle(); + + assertEquals(newWidth, childView.getWidth()); + } + + /** + * Verify that removing the root view from hierarchy will trigger subviews removal both on JS and + * native side + */ + public void testRemoveRootView() throws Throwable { + final ReactRootView rootView = (ReactRootView) getRootView(); + + assertEquals(1, rootView.getChildCount()); + + runTestOnUiThread( + new Runnable() { + @Override + public void run() { + ViewGroup parent = (ViewGroup) rootView.getParent(); + parent.removeView(rootView); + // removing from parent should not remove child views, child views should be removed as + // an effect of native call to UIManager.removeRootView + assertEquals(1, rootView.getChildCount()); + } + }); + + getInstrumentation().waitForIdleSync(); + waitForBridgeAndUIIdle(); + + assertEquals("root component should not be automatically unmounted", 0, mRecordingModule.getCalls().size()); + assertEquals(1, rootView.getChildCount()); + + runTestOnUiThread( + new Runnable() { + @Override + public void run() { + rootView.unmountReactApplication(); + } + }); + waitForBridgeAndUIIdle(); + + assertEquals(1, mRecordingModule.getCalls().size()); + assertEquals("RootComponentWillUnmount", mRecordingModule.getCalls().get(0)); + assertEquals(0, rootView.getChildCount()); + } + + @Override + protected ReactInstanceSpecForTest createReactInstanceSpecForTest() { + mRecordingModule = new StringRecordingModule(); + return new ReactInstanceSpecForTest() + .addNativeModule(mRecordingModule); + } +} diff --git a/ReactAndroid/src/androidTest/java/com/facebook/react/tests/TimePickerDialogTestCase.java b/ReactAndroid/src/androidTest/java/com/facebook/react/tests/TimePickerDialogTestCase.java new file mode 100644 index 000000000..516170de4 --- /dev/null +++ b/ReactAndroid/src/androidTest/java/com/facebook/react/tests/TimePickerDialogTestCase.java @@ -0,0 +1,161 @@ +/** + * 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.ArrayList; +import java.util.List; + +import android.app.TimePickerDialog; +import android.content.DialogInterface; +import android.support.v4.app.DialogFragment; + +import com.facebook.react.bridge.BaseJavaModule; +import com.facebook.react.testing.ReactInstanceSpecForTest; +import com.facebook.react.bridge.ReactMethod; +import com.facebook.react.bridge.JavaScriptModule; +import com.facebook.react.bridge.WritableMap; +import com.facebook.react.bridge.WritableNativeMap; +import com.facebook.react.modules.timepicker.TimePickerDialogModule; +import com.facebook.react.testing.ReactAppInstrumentationTestCase; + +/** + * Test case for {@link TimePickerDialogModule} options and callbacks. + */ +public class TimePickerDialogTestCase extends ReactAppInstrumentationTestCase { + + private static interface TimePickerDialogTestModule extends JavaScriptModule { + public void showTimePickerDialog(WritableMap options); + } + + private static class TimePickerDialogRecordingModule extends BaseJavaModule { + + private final List mTimes = new ArrayList(); + private int mDismissed = 0; + private int mErrors = 0; + + @Override + public String getName() { + return "TimePickerDialogRecordingModule"; + } + + @ReactMethod + public void recordTime(int hour, int minute) { + mTimes.add(new Integer[] {hour, minute}); + } + + @ReactMethod + public void recordDismissed() { + mDismissed++; + } + + @ReactMethod + public void recordError() { + mErrors++; + } + + public List getTimes() { + return new ArrayList(mTimes); + } + + public int getDismissed() { + return mDismissed; + } + + public int getErrors() { + return mErrors; + } + } + + final TimePickerDialogRecordingModule mRecordingModule = new TimePickerDialogRecordingModule(); + + @Override + protected ReactInstanceSpecForTest createReactInstanceSpecForTest() { + return super.createReactInstanceSpecForTest() + .addNativeModule(mRecordingModule) + .addJSModule(TimePickerDialogTestModule.class); + } + + @Override + protected String getReactApplicationKeyUnderTest() { + return "TimePickerDialogTestApp"; + } + + private TimePickerDialogTestModule getTestModule() { + return getReactContext().getCatalystInstance().getJSModule(TimePickerDialogTestModule.class); + } + + private DialogFragment showDialog(WritableMap options) { + getTestModule().showTimePickerDialog(options); + + waitForBridgeAndUIIdle(); + getInstrumentation().waitForIdleSync(); + + return (DialogFragment) getActivity().getSupportFragmentManager() + .findFragmentByTag(TimePickerDialogModule.FRAGMENT_TAG); + } + + public void testShowBasicTimePicker() { + final DialogFragment fragment = showDialog(null); + + assertNotNull(fragment); + } + + public void testPresetTimeAndCallback() throws Throwable { + final WritableMap options = new WritableNativeMap(); + options.putInt("hour", 4); + options.putInt("minute", 5); + + final DialogFragment fragment = showDialog(options); + + List recordedTimes = mRecordingModule.getTimes(); + assertEquals(0, recordedTimes.size()); + + runTestOnUiThread( + new Runnable() { + @Override + public void run() { + ((TimePickerDialog) fragment.getDialog()) + .getButton(DialogInterface.BUTTON_POSITIVE).performClick(); + } + }); + + getInstrumentation().waitForIdleSync(); + waitForBridgeAndUIIdle(); + + assertEquals(0, mRecordingModule.getErrors()); + assertEquals(0, mRecordingModule.getDismissed()); + + recordedTimes = mRecordingModule.getTimes(); + assertEquals(1, recordedTimes.size()); + assertEquals(4, (int) recordedTimes.get(0)[0]); + assertEquals(5, (int) recordedTimes.get(0)[1]); + } + + public void testDismissCallback() throws Throwable { + final DialogFragment fragment = showDialog(null); + + assertEquals(0, mRecordingModule.getDismissed()); + + runTestOnUiThread( + new Runnable() { + @Override + public void run() { + fragment.getDialog().dismiss(); + } + }); + + getInstrumentation().waitForIdleSync(); + waitForBridgeAndUIIdle(); + + assertEquals(0, mRecordingModule.getErrors()); + assertEquals(0, mRecordingModule.getTimes().size()); + assertEquals(1, mRecordingModule.getDismissed()); + } + +} diff --git a/ReactAndroid/src/androidTest/java/com/facebook/react/tests/ViewRenderingTestCase.java b/ReactAndroid/src/androidTest/java/com/facebook/react/tests/ViewRenderingTestCase.java new file mode 100644 index 000000000..f4f817c2b --- /dev/null +++ b/ReactAndroid/src/androidTest/java/com/facebook/react/tests/ViewRenderingTestCase.java @@ -0,0 +1,150 @@ +/** + * 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.List; + +import android.graphics.Color; +import android.view.View; +import android.view.ViewGroup; + +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.PixelUtil; +import com.facebook.react.uimanager.UIImplementation; +import com.facebook.react.uimanager.UIManagerModule; +import com.facebook.react.uimanager.ViewManager; +import com.facebook.react.views.view.ReactViewGroup; +import com.facebook.react.views.view.ReactViewManager; +import com.facebook.react.testing.ReactIntegrationTestCase; +import com.facebook.react.testing.ReactTestHelper; + +public class ViewRenderingTestCase extends ReactIntegrationTestCase { + + private interface ViewRenderingTestModule extends JavaScriptModule { + void renderViewApplication(int rootTag); + void renderMarginApplication(int rootTag); + void renderBorderApplication(int rootTag); + void updateMargins(); + void renderTransformApplication(int rootTag); + } + + private CatalystInstance mCatalystInstance; + private ReactRootView mRootView; + private int mRootTag; + + @Override + protected void setUp() throws Exception { + super.setUp(); + + List viewManagers = Arrays.asList(new ReactViewManager()); + final UIManagerModule uiManager = new UIManagerModule( + getContext(), + viewManagers, + new UIImplementation(getContext(), viewManagers)); + UiThreadUtil.runOnUiThread( + new Runnable() { + @Override + public void run() { + uiManager.onHostResume(); + } + }); + waitForIdleSync(); + + mCatalystInstance = ReactTestHelper.catalystInstanceBuilder(this) + .addNativeModule(uiManager) + .addNativeModule(new AndroidInfoModule()) + .addJSModule(ViewRenderingTestModule.class) + .build(); + + mRootView = new ReactRootView(getContext()); + mRootTag = uiManager.addMeasuredRootView(mRootView); + } + + public void testViewRenderedWithCorrectProperties() { + float expectedOpacity = 0.75f; + int expectedBackgroundColor = Color.rgb(255, 0, 0); + + mCatalystInstance.getJSModule(ViewRenderingTestModule.class).renderViewApplication(mRootTag); + waitForBridgeAndUIIdle(); + + ReactViewGroup view = getViewAtPath(mRootView); + assertEquals("Incorrect (or not applied) opacity", expectedOpacity, view.getAlpha()); + assertEquals( + "Incorrect (or not applied) backgroundColor", + expectedBackgroundColor, + view.getBackgroundColor()); + } + + public void testMarginsApplied() { + mCatalystInstance.getJSModule(ViewRenderingTestModule.class).renderMarginApplication(mRootTag); + waitForBridgeAndUIIdle(); + + View view = getViewAtPath(mRootView); + + int expectedMargin = Math.round(PixelUtil.toPixelFromDIP(10)); + int expectedMarginLeft = Math.round(PixelUtil.toPixelFromDIP(20)); + + assertEquals(expectedMarginLeft, (int) view.getX()); + assertEquals(expectedMargin, (int) view.getY()); + } + + public void testMarginUpdateDoesntForgetPreviousValue() { + mCatalystInstance.getJSModule(ViewRenderingTestModule.class).renderMarginApplication(mRootTag); + waitForBridgeAndUIIdle(); + + View view = getViewAtPath(mRootView); + + // before: margin: 10, marginLeft: 20 + mCatalystInstance.getJSModule(ViewRenderingTestModule.class).updateMargins(); + waitForBridgeAndUIIdle(); + // after: margin: 15; it should not forget marginLeft was set to 20 + + int expectedMargin = Math.round(PixelUtil.toPixelFromDIP(15)); + int expectedMarginLeft = Math.round(PixelUtil.toPixelFromDIP(20)); + + assertEquals(expectedMarginLeft, (int) view.getX()); + assertEquals(expectedMargin, (int) view.getY()); + } + + public void testBordersApplied() { + mCatalystInstance.getJSModule(ViewRenderingTestModule.class).renderBorderApplication(mRootTag); + waitForBridgeAndUIIdle(); + + View view = getViewAtPath(mRootView); + View child = ((ViewGroup) view).getChildAt(0); + + int expectedBorderX = Math.round(PixelUtil.toPixelFromDIP(20)); + int expectedBorderY = Math.round(PixelUtil.toPixelFromDIP(5)); + + assertEquals(expectedBorderX, (int) child.getX()); + assertEquals(expectedBorderY, (int) child.getY()); + } + + public void testTransformations() { + mCatalystInstance.getJSModule(ViewRenderingTestModule.class) + .renderTransformApplication(mRootTag); + waitForBridgeAndUIIdle(); + + View view = getViewAtPath(mRootView); + + float expectedTranslateX = PixelUtil.toPixelFromDIP(20); + float expectedTranslateY = PixelUtil.toPixelFromDIP(25); + + assertEquals(5f, view.getScaleX()); + assertEquals(10f, view.getScaleY()); + assertEquals(15f, view.getRotation()); + assertEquals(expectedTranslateX, view.getTranslationX()); + assertEquals(expectedTranslateY, view.getTranslationY()); + } +} diff --git a/ReactAndroid/src/androidTest/js/CatalystRootViewTestModule.js b/ReactAndroid/src/androidTest/js/CatalystRootViewTestModule.js new file mode 100644 index 000000000..1086567a1 --- /dev/null +++ b/ReactAndroid/src/androidTest/js/CatalystRootViewTestModule.js @@ -0,0 +1,29 @@ +/** + * 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 CatalystRootViewTestModule + */ + +'use strict'; + +var React = require('React'); +var Recording = require('NativeModules').Recording; +var View = require('View'); + +var CatalystRootViewTestApp = React.createClass({ + componentWillUnmount: function() { + Recording.record('RootComponentWillUnmount'); + }, + render: function() { + return ; + }, +}); + +module.exports = { + CatalystRootViewTestApp: CatalystRootViewTestApp, +}; diff --git a/ReactAndroid/src/androidTest/js/DatePickerDialogTestModule.js b/ReactAndroid/src/androidTest/js/DatePickerDialogTestModule.js new file mode 100644 index 000000000..a15eabd4b --- /dev/null +++ b/ReactAndroid/src/androidTest/js/DatePickerDialogTestModule.js @@ -0,0 +1,47 @@ +/** + * 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 DatePickerDialogTestModule + */ + +'use strict'; + +var BatchedBridge = require('BatchedBridge'); +var DatePickerAndroid = require('DatePickerAndroid'); +var React = require('React'); +var RecordingModule = require('NativeModules').DatePickerDialogRecordingModule; +var View = require('View'); + +var DatePickerDialogTestApp = React.createClass({ + render: function() { + return (); + }, +}); + +var DatePickerDialogTestModule = { + DatePickerDialogTestApp: DatePickerDialogTestApp, + showDatePickerDialog: function(options) { + DatePickerAndroid.open(options).then( + ({action, year, month, day}) => { + if (action === DatePickerAndroid.dateSetAction) { + RecordingModule.recordDate(year, month, day); + } else if (action === DatePickerAndroid.dismissedAction) { + RecordingModule.recordDismissed(); + } + }, + ({code, message}) => RecordingModule.recordError() + ); + }, +}; + +BatchedBridge.registerCallableModule( + 'DatePickerDialogTestModule', + DatePickerDialogTestModule +); + +module.exports = DatePickerDialogTestModule; diff --git a/ReactAndroid/src/androidTest/js/TestBundle.js b/ReactAndroid/src/androidTest/js/TestBundle.js index 86d044773..9af72339c 100644 --- a/ReactAndroid/src/androidTest/js/TestBundle.js +++ b/ReactAndroid/src/androidTest/js/TestBundle.js @@ -12,17 +12,30 @@ // Disable YellowBox so we do not have to mock its dependencies console.disableYellowBox = true; -// Include modules used by integration tests -require('PickerAndroidTestModule'); +// Include callable JS modules first, in case one of the other ones below throws require('ProgressBarTestModule'); +require('ViewRenderingTestModule'); + +require('PickerAndroidTestModule'); +require('CatalystRootViewTestModule'); +require('DatePickerDialogTestModule'); require('ScrollViewTestModule'); require('SwipeRefreshLayoutTestModule'); require('TextInputTestModule'); +require('TimePickerDialogTestModule'); // Define catalyst test apps used in integration tests var AppRegistry = require('AppRegistry'); var apps = [ +{ + appKey: 'CatalystRootViewTestApp', + component: () => require('CatalystRootViewTestModule').CatalystRootViewTestApp +}, +{ + appKey: 'DatePickerDialogTestApp', + component: () => require('DatePickerDialogTestModule').DatePickerDialogTestApp +}, { appKey: 'HorizontalScrollViewTestApp', component: () => require('ScrollViewTestModule').HorizontalScrollViewTestApp, @@ -47,6 +60,10 @@ var apps = [ appKey: 'TestIdTestApp', component: () => require('TestIdTestModule').TestIdTestApp }, +{ + appKey: 'TimePickerDialogTestApp', + component: () => require('TimePickerDialogTestModule').TimePickerDialogTestApp +}, ]; diff --git a/ReactAndroid/src/androidTest/js/TimePickerDialogTestModule.js b/ReactAndroid/src/androidTest/js/TimePickerDialogTestModule.js new file mode 100644 index 000000000..4f1f16672 --- /dev/null +++ b/ReactAndroid/src/androidTest/js/TimePickerDialogTestModule.js @@ -0,0 +1,47 @@ +/** + * 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 TimePickerDialogTestModule + */ + +'use strict'; + +var BatchedBridge = require('BatchedBridge'); +var TimePickerAndroid = require('TimePickerAndroid'); +var React = require('React'); +var RecordingModule = require('NativeModules').TimePickerDialogRecordingModule; +var View = require('View'); + +var TimePickerDialogTestApp = React.createClass({ + render: function() { + return ; + }, +}); + +var TimePickerDialogTestModule = { + TimePickerDialogTestApp: TimePickerDialogTestApp, + showTimePickerDialog: function(options) { + TimePickerAndroid.open(options).then( + ({action, hour, minute}) => { + if (action === TimePickerAndroid.timeSetAction) { + RecordingModule.recordTime(hour, minute); + } else if (action === TimePickerAndroid.dismissedAction) { + RecordingModule.recordDismissed(); + } + }, + ({code, message}) => RecordingModule.recordError() + ); + }, +}; + +BatchedBridge.registerCallableModule( + 'TimePickerDialogTestModule', + TimePickerDialogTestModule +); + +module.exports = TimePickerDialogTestModule; diff --git a/ReactAndroid/src/androidTest/js/ViewRenderingTestModule.js b/ReactAndroid/src/androidTest/js/ViewRenderingTestModule.js new file mode 100644 index 000000000..03c093df7 --- /dev/null +++ b/ReactAndroid/src/androidTest/js/ViewRenderingTestModule.js @@ -0,0 +1,102 @@ +/** + * 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 ViewRenderingTestModule + */ + +"use strict"; + +var BatchedBridge = require('BatchedBridge'); +var React = require('React'); +var View = require('View'); +var StyleSheet = require('StyleSheet'); + +var renderApplication = require('renderApplication'); + +var styles = StyleSheet.create({ + view: { + opacity: 0.75, + backgroundColor: "rgb(255, 0, 0)", + }, +}); + +var ViewSampleApp = React.createClass({ + render: function() { + return ( + + ); + }, + getInitialState: function() { + return {}; + }, +}); + +var updateMargins; +var MarginSampleApp = React.createClass({ + getInitialState: function() { + return {margin: 10}; + }, + render: function() { + updateMargins = this.setState.bind(this, {margin: 15}); + return ( + + ) + }, +}); + +var BorderSampleApp = React.createClass({ + render: function() { + return ( + + + + ); + } +}); + +var TransformSampleApp = React.createClass({ + render: function() { + var style = { + transform: [ + {translateX: 20}, + {translateY: 25}, + {rotate: '15deg'}, + {scaleX: 5}, + {scaleY: 10}, + ] + }; + return ( + + ); + } +}); + +var ViewRenderingTestModule = { + renderViewApplication: function(rootTag) { + renderApplication(ViewSampleApp, {}, rootTag); + }, + renderMarginApplication: function(rootTag) { + renderApplication(MarginSampleApp, {}, rootTag); + }, + renderBorderApplication: function(rootTag) { + renderApplication(BorderSampleApp, {}, rootTag); + }, + renderTransformApplication: function(rootTag) { + renderApplication(TransformSampleApp, {}, rootTag); + }, + updateMargins: function() { + updateMargins(); + }, +}; + +BatchedBridge.registerCallableModule( + 'ViewRenderingTestModule', + ViewRenderingTestModule +); + +module.exports = ViewRenderingTestModule;