Open sourced ProgressBarTest
Reviewed By: andreicoman11 Differential Revision: D3287396 fbshipit-source-id: 1a814b72ebcb5d13106c6a612b341f217c4dc5a6
This commit is contained in:
parent
36b085422d
commit
9b56ff6bab
|
@ -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());
|
||||
}
|
||||
|
||||
|
|
|
@ -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'),
|
||||
|
|
|
@ -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<String, Integer> styles = new HashMap<String, Integer>();
|
||||
|
||||
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<ViewManager> viewManagers = Arrays.<ViewManager>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());
|
||||
}
|
||||
}
|
|
@ -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 (
|
||||
<View>
|
||||
<ProgressBar styleAttr="Horizontal" testID="Horizontal"/>
|
||||
<ProgressBar styleAttr="Small" testID="Small"/>
|
||||
<ProgressBar styleAttr="Large" testID="Large"/>
|
||||
<ProgressBar styleAttr="Normal" testID="Normal"/>
|
||||
<ProgressBar styleAttr="Inverse" testID="Inverse"/>
|
||||
<ProgressBar styleAttr="SmallInverse" testID="SmallInverse"/>
|
||||
<ProgressBar styleAttr="LargeInverse" testID="LargeInverse"/>
|
||||
<View style={{width:200}}>
|
||||
<ProgressBar styleAttr="Horizontal" testID="Horizontal200" />
|
||||
</View>
|
||||
</View>
|
||||
);
|
||||
},
|
||||
getInitialState: function() {
|
||||
return {};
|
||||
},
|
||||
});
|
||||
|
||||
var ProgressBarTestModule = {
|
||||
renderProgressBarApplication: function(rootTag) {
|
||||
renderApplication(ProgressBarSampleApp, {}, rootTag);
|
||||
},
|
||||
};
|
||||
|
||||
BatchedBridge.registerCallableModule(
|
||||
'ProgressBarTestModule',
|
||||
ProgressBarTestModule
|
||||
);
|
||||
|
||||
module.exports = ProgressBarTestModule;
|
|
@ -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');
|
||||
|
||||
|
|
Loading…
Reference in New Issue