mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-02 22:41:18 +08:00
Open sourced 4 more instrumentation tests for RN Android
Summary: More instrumentation tests in OSS means less work for FB engineers to investigate if a PR breaks some internal tests. + increased timeouts and retries for OSS tests runner Reviewed By: andreicoman11 Differential Revision: D3292582 fbshipit-source-id: 3f8aa4d3536450ea3af7acff044b9bb62be0f9db
This commit is contained in:
committed by
Facebook Github Bot 2
parent
31c8b3bd61
commit
2c3ca4c058
@@ -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(
|
||||
|
||||
@@ -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<Integer[]> mDates = new ArrayList<Integer[]>();
|
||||
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<Integer[]> getDates() {
|
||||
return new ArrayList<Integer[]>(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());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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<Integer[]> mTimes = new ArrayList<Integer[]>();
|
||||
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<Integer[]> getTimes() {
|
||||
return new ArrayList<Integer[]>(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<Integer[]> 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());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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<ViewManager> viewManagers = Arrays.<ViewManager>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());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user