Skip to content

Commit 58881fc

Browse files
bestanderFacebook Github Bot 6
authored andcommitted
<Replace this line with a title. Use 1 line only, 67 chars or less>
Reviewed By: matryoshcow Differential Revision: D3432084 fbshipit-source-id: fa94b1aca40c931cc273a5561adf37f458aaa0ff
1 parent 503fdc6 commit 58881fc

File tree

10 files changed

+511
-1
lines changed

10 files changed

+511
-1
lines changed
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
/**
2+
* Copyright (c) 2014-present, Facebook, Inc.
3+
* All rights reserved.
4+
* This source code is licensed under the BSD-style license found in the
5+
* LICENSE file in the root directory of this source tree. An additional grant
6+
* of patent rights can be found in the PATENTS file in the same directory.
7+
*/
8+
9+
package com.facebook.react.tests;
10+
11+
import android.os.Bundle;
12+
import android.test.ActivityInstrumentationTestCase2;
13+
14+
import com.facebook.react.bridge.BaseJavaModule;
15+
import com.facebook.react.testing.ReactInstanceSpecForTest;
16+
import com.facebook.react.bridge.ReactMethod;
17+
import com.facebook.react.bridge.ReadableArray;
18+
import com.facebook.react.bridge.ReadableMap;
19+
import com.facebook.react.testing.ReactAppTestActivity;
20+
21+
/**
22+
* Simple test case for passing initial props to the root React application.
23+
*/
24+
public class InitialPropsTestCase extends
25+
ActivityInstrumentationTestCase2<ReactAppTestActivity> {
26+
27+
public static final String DEFAULT_JS_BUNDLE = "AndroidTestBundle.js";
28+
29+
private static class RecordingModule extends BaseJavaModule {
30+
private int mCount = 0;
31+
private ReadableMap mProps;
32+
33+
@Override
34+
public String getName() {
35+
return "InitialPropsRecordingModule";
36+
}
37+
38+
@ReactMethod
39+
public void recordProps(ReadableMap props) {
40+
mProps = props;
41+
mCount++;
42+
}
43+
44+
public int getCount() {
45+
return mCount;
46+
}
47+
48+
public ReadableMap getProps() {
49+
return mProps;
50+
}
51+
}
52+
53+
private RecordingModule mRecordingModule;
54+
55+
public InitialPropsTestCase() {
56+
super(ReactAppTestActivity.class);
57+
}
58+
59+
@Override
60+
protected void setUp() throws Exception {
61+
super.setUp();
62+
63+
mRecordingModule = new RecordingModule();
64+
}
65+
66+
public void testInitialProps() throws Throwable {
67+
final ReactAppTestActivity activity = getActivity();
68+
runTestOnUiThread(
69+
new Runnable() {
70+
@Override
71+
public void run() {
72+
ReactInstanceSpecForTest catalystInstanceSpec = new ReactInstanceSpecForTest();
73+
catalystInstanceSpec.addNativeModule(mRecordingModule);
74+
Bundle props = new Bundle();
75+
props.putString("key1", "string");
76+
props.putInt("key2", 5);
77+
props.putDouble("key3", 5.5);
78+
props.putFloat("key4", 5.6f);
79+
props.putBoolean("key5", true);
80+
props.putStringArray("key6", new String[]{"one", "two", "three"});
81+
props.putIntArray("key7", new int[]{1, 2, 3});
82+
props.putDoubleArray("key8", new double[]{1.5, 2.5, 3.5});
83+
props.putFloatArray("key9", new float[]{1.6f, 2.6f, 3.6f});
84+
props.putBooleanArray("key10", new boolean[]{true, false});
85+
activity.loadApp(
86+
"InitialPropsTestApp",
87+
catalystInstanceSpec,
88+
props,
89+
DEFAULT_JS_BUNDLE,
90+
false);
91+
}
92+
});
93+
activity.waitForBridgeAndUIIdle();
94+
95+
assertEquals(1, mRecordingModule.getCount());
96+
ReadableMap props = mRecordingModule.getProps();
97+
assertEquals("string", props.getString("key1"));
98+
assertEquals(5, props.getInt("key2"));
99+
assertEquals(5.5, props.getDouble("key3"));
100+
assertEquals(5.6f, (float) props.getDouble("key4"));
101+
assertEquals(true, props.getBoolean("key5"));
102+
103+
ReadableArray stringArray = props.getArray("key6");
104+
assertEquals("one", stringArray.getString(0));
105+
assertEquals("two", stringArray.getString(1));
106+
assertEquals("three", stringArray.getString(2));
107+
108+
ReadableArray intArray = props.getArray("key7");
109+
assertEquals(1, intArray.getInt(0));
110+
assertEquals(2, intArray.getInt(1));
111+
assertEquals(3, intArray.getInt(2));
112+
113+
ReadableArray doubleArray = props.getArray("key8");
114+
assertEquals(1.5, doubleArray.getDouble(0));
115+
assertEquals(2.5, doubleArray.getDouble(1));
116+
assertEquals(3.5, doubleArray.getDouble(2));
117+
118+
ReadableArray floatArray = props.getArray("key9");
119+
assertEquals(1.6f, (float) floatArray.getDouble(0));
120+
assertEquals(2.6f, (float) floatArray.getDouble(1));
121+
assertEquals(3.6f, (float) floatArray.getDouble(2));
122+
123+
ReadableArray booleanArray = props.getArray("key10");
124+
assertEquals(true, booleanArray.getBoolean(0));
125+
assertEquals(false, booleanArray.getBoolean(1));
126+
}
127+
}
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/**
2+
* Copyright (c) 2014-present, Facebook, Inc.
3+
* All rights reserved.
4+
* This source code is licensed under the BSD-style license found in the
5+
* LICENSE file in the root directory of this source tree. An additional grant
6+
* of patent rights can be found in the PATENTS file in the same directory.
7+
*/
8+
9+
package com.facebook.react.tests;
10+
11+
import java.util.Arrays;
12+
import java.util.List;
13+
14+
import com.facebook.react.testing.ReactIntegrationTestCase;
15+
import com.facebook.react.testing.ReactTestHelper;
16+
import com.facebook.react.testing.StringRecordingModule;
17+
import com.facebook.react.bridge.CatalystInstance;
18+
import com.facebook.react.bridge.JavaScriptModule;
19+
import com.facebook.react.bridge.UiThreadUtil;
20+
import com.facebook.react.uimanager.UIImplementation;
21+
import com.facebook.react.uimanager.UIManagerModule;
22+
import com.facebook.react.uimanager.ViewManager;
23+
import com.facebook.react.views.view.ReactViewManager;
24+
25+
/**
26+
* Test locale-based functionality of JS VM
27+
*/
28+
public class JSLocaleTest extends ReactIntegrationTestCase {
29+
30+
private interface TestJSLocaleModule extends JavaScriptModule {
31+
void toUpper(String string);
32+
void toLower(String string);
33+
}
34+
35+
StringRecordingModule mStringRecordingModule;
36+
37+
private CatalystInstance mInstance;
38+
39+
@Override
40+
protected void setUp() throws Exception {
41+
super.setUp();
42+
43+
List<ViewManager> viewManagers = Arrays.<ViewManager>asList(
44+
new ReactViewManager());
45+
final UIManagerModule mUIManager = new UIManagerModule(
46+
getContext(),
47+
viewManagers,
48+
new UIImplementation(getContext(), viewManagers));
49+
UiThreadUtil.runOnUiThread(
50+
new Runnable() {
51+
@Override
52+
public void run() {
53+
mUIManager.onHostResume();
54+
}
55+
});
56+
waitForIdleSync();
57+
58+
mStringRecordingModule = new StringRecordingModule();
59+
mInstance = ReactTestHelper.catalystInstanceBuilder(this)
60+
.addNativeModule(mStringRecordingModule)
61+
.addNativeModule(mUIManager)
62+
.addJSModule(TestJSLocaleModule.class)
63+
.build();
64+
65+
}
66+
67+
public void testToUpper() {
68+
TestJSLocaleModule testModule = mInstance.getJSModule(TestJSLocaleModule.class);
69+
waitForBridgeAndUIIdle();
70+
71+
testModule.toUpper("test");
72+
testModule.toUpper("W niżach mógł zjeść truflę koń bądź psy");
73+
testModule.toUpper("Шеф взъярён тчк щипцы с эхом гудбай Жюль");
74+
testModule.toUpper("Γαζίες καὶ μυρτιὲς δὲν θὰ βρῶ πιὰ στὸ χρυσαφὶ ξέφωτο");
75+
testModule.toUpper("chinese: 幓 厏吪吙 鈊釿閍 碞碠粻 曮禷");
76+
waitForBridgeAndUIIdle();
77+
78+
String[] answers = mStringRecordingModule.getCalls().toArray(new String[0]);
79+
assertEquals("TEST", answers[0]);
80+
assertEquals("W NIŻACH MÓGŁ ZJEŚĆ TRUFLĘ KOŃ BĄDŹ PSY", answers[1]);
81+
assertEquals("ШЕФ ВЗЪЯРЁН ТЧК ЩИПЦЫ С ЭХОМ ГУДБАЙ ЖЮЛЬ", answers[2]);
82+
assertEquals("ΓΑΖΊΕΣ ΚΑῚ ΜΥΡΤΙῈΣ ΔῈΝ ΘᾺ ΒΡΩ͂ ΠΙᾺ ΣΤῸ ΧΡΥΣΑΦῚ ΞΈΦΩΤΟ", answers[3]);
83+
assertEquals("CHINESE: 幓 厏吪吙 鈊釿閍 碞碠粻 曮禷", answers[4]);
84+
}
85+
86+
public void testToLower() {
87+
TestJSLocaleModule testModule = mInstance.getJSModule(TestJSLocaleModule.class);
88+
89+
testModule.toLower("TEST");
90+
testModule.toLower("W NIŻACH MÓGŁ ZJEŚĆ TRUFLĘ KOŃ BĄDŹ psy");
91+
testModule.toLower("ШЕФ ВЗЪЯРЁН ТЧК ЩИПЦЫ С ЭХОМ ГУДБАЙ ЖЮЛЬ");
92+
testModule.toLower("ΓΑΖΊΕΣ ΚΑῚ ΜΥΡΤΙῈΣ ΔῈΝ ΘᾺ ΒΡΩ͂ ΠΙᾺ ΣΤῸ ΧΡΥΣΑΦῚ ΞΈΦΩΤΟ");
93+
testModule.toLower("CHINESE: 幓 厏吪吙 鈊釿閍 碞碠粻 曮禷");
94+
waitForBridgeAndUIIdle();
95+
96+
String[] answers = mStringRecordingModule.getCalls().toArray(new String[0]);
97+
assertEquals("test", answers[0]);
98+
assertEquals("w niżach mógł zjeść truflę koń bądź psy", answers[1]);
99+
assertEquals("шеф взъярён тчк щипцы с эхом гудбай жюль", answers[2]);
100+
assertEquals("γαζίες καὶ μυρτιὲς δὲν θὰ βρῶ πιὰ στὸ χρυσαφὶ ξέφωτο", answers[3]);
101+
assertEquals("chinese: 幓 厏吪吙 鈊釿閍 碞碠粻 曮禷", answers[4]);
102+
}
103+
104+
105+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/**
2+
* Copyright (c) 2014-present, Facebook, Inc.
3+
* All rights reserved.
4+
* This source code is licensed under the BSD-style license found in the
5+
* LICENSE file in the root directory of this source tree. An additional grant
6+
* of patent rights can be found in the PATENTS file in the same directory.
7+
*/
8+
9+
package com.facebook.react.tests;
10+
11+
import android.widget.ScrollView;
12+
13+
import com.facebook.react.uimanager.PixelUtil;
14+
import com.facebook.react.testing.ReactAppInstrumentationTestCase;
15+
import com.facebook.react.testing.SingleTouchGestureGenerator;
16+
17+
/**
18+
* Test case to verify that JSResponder flow work correctly.
19+
*
20+
* In a single test case scenario we have a view with pan gesture recognizer containing a scrollview
21+
* We werify that by vertical drags affects a scrollview while horizontal drags are suppose to
22+
* be recognized by pan responder and setJSResponder should be triggered resulting in scrollview
23+
* events being intercepted.
24+
*/
25+
public class JSResponderTestCase extends ReactAppInstrumentationTestCase {
26+
27+
@Override
28+
protected String getReactApplicationKeyUnderTest() {
29+
return "JSResponderTestApp";
30+
}
31+
32+
public void testResponderLocksScrollView() {
33+
ScrollView scrollView = getViewByTestId("scroll_view");
34+
assertNotNull(scrollView);
35+
assertEquals(0, scrollView.getScrollY());
36+
37+
float inpx40dp = PixelUtil.toPixelFromDIP(40f);
38+
float inpx100dp = PixelUtil.toPixelFromDIP(100f);
39+
40+
SingleTouchGestureGenerator gestureGenerator = createGestureGenerator();
41+
42+
gestureGenerator
43+
.startGesture(30, 30 + inpx100dp)
44+
.dragTo(30 + inpx40dp, 30, 10, 1200)
45+
.endGesture(180, 100);
46+
47+
waitForBridgeAndUIIdle();
48+
49+
assertTrue("Expected to scroll by at least 80 dp", scrollView.getScrollY() >= inpx100dp * .8f);
50+
51+
int previousScroll = scrollView.getScrollY();
52+
53+
gestureGenerator
54+
.startGesture(30, 30 + inpx100dp)
55+
.dragTo(30 + inpx40dp, 30 + inpx100dp, 10, 1200);
56+
57+
waitForBridgeAndUIIdle();
58+
59+
gestureGenerator
60+
.dragTo(30 + inpx40dp, 30, 10, 1200)
61+
.endGesture();
62+
63+
waitForBridgeAndUIIdle();
64+
assertEquals("Expected not to scroll", scrollView.getScrollY(), previousScroll);
65+
66+
}
67+
68+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
* Copyright (c) 2014-present, Facebook, Inc.
3+
* All rights reserved.
4+
* This source code is licensed under the BSD-style license found in the
5+
* LICENSE file in the root directory of this source tree. An additional grant
6+
* of patent rights can be found in the PATENTS file in the same directory.
7+
*/
8+
9+
package com.facebook.react.tests;
10+
11+
import com.facebook.react.testing.ReactAppInstrumentationTestCase;
12+
import com.facebook.react.testing.ReactInstanceSpecForTest;
13+
import com.facebook.react.testing.StringRecordingModule;
14+
15+
/**
16+
* Simple test to verify that layout events (onLayout) propagate to JS from native.
17+
*/
18+
public class LayoutEventsTestCase extends ReactAppInstrumentationTestCase {
19+
20+
private StringRecordingModule mStringRecordingModule;
21+
22+
@Override
23+
protected String getReactApplicationKeyUnderTest() {
24+
return "LayoutEventsTestApp";
25+
}
26+
27+
/**
28+
* Creates a UI in JS and verifies the onLayout handler is called.
29+
*/
30+
public void testOnLayoutCalled() {
31+
assertEquals(1, mStringRecordingModule.getCalls().size());
32+
assertEquals("10,10-100x100", mStringRecordingModule.getCalls().get(0));
33+
}
34+
35+
@Override
36+
protected ReactInstanceSpecForTest createReactInstanceSpecForTest() {
37+
mStringRecordingModule = new StringRecordingModule();
38+
return super.createReactInstanceSpecForTest()
39+
.addNativeModule(mStringRecordingModule);
40+
}
41+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* Copyright (c) 2013-present, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*
9+
* @providesModule InitialPropsTestApp
10+
*/
11+
12+
'use strict';
13+
14+
var React = require('React');
15+
var RecordingModule = require('NativeModules').InitialPropsRecordingModule;
16+
var Text = require('Text');
17+
18+
var InitialPropsTestApp = React.createClass({
19+
componentDidMount: function() {
20+
RecordingModule.recordProps(this.props);
21+
},
22+
render: function() {
23+
return <Text>dummy</Text>;
24+
}
25+
});
26+
27+
module.exports = InitialPropsTestApp;

0 commit comments

Comments
 (0)