com.facebook.react.bridge.JavaOnlyArray Java Examples
The following examples show how to use
com.facebook.react.bridge.JavaOnlyArray.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RNInstabugSurveysModuleTest.java From Instabug-React-Native with MIT License | 6 votes |
@Test public void given$getAvailableSurveys_whenQuery_thenShouldCallNativeApiAndInvokeCallback() throws Exception { // given PowerMockito.mockStatic(Surveys.class); PowerMockito.mockStatic(SystemClock.class); PowerMockito.mockStatic(Arguments.class); Callback callback = mock(Callback.class); JSONArray json = mock(JSONArray.class); // when PowerMockito.whenNew(JSONArray.class).withAnyArguments().thenReturn(json); PowerMockito.when(Arguments.createArray()).thenReturn(new JavaOnlyArray()); surveysModule.getAvailableSurveys(callback); // then PowerMockito.verifyStatic(VerificationModeFactory.times(1)); Surveys.getAvailableSurveys(); verify(callback).invoke(any()); }
Example #2
Source File: NativeAnimatedNodeTraversalTest.java From react-native-GPay with MIT License | 6 votes |
@Test public void testNativeAnimatedEventDoNotUpdate() { int viewTag = 1000; createSimpleAnimatedViewWithOpacity(viewTag, 0d); mNativeAnimatedNodesManager.addAnimatedEventToView(viewTag, "otherEvent", JavaOnlyMap.of( "animatedValueTag", 1, "nativeEventPath", JavaOnlyArray.of("contentOffset", "y"))); mNativeAnimatedNodesManager.addAnimatedEventToView(999, "topScroll", JavaOnlyMap.of( "animatedValueTag", 1, "nativeEventPath", JavaOnlyArray.of("contentOffset", "y"))); mNativeAnimatedNodesManager.onEventDispatch(createScrollEvent(viewTag, 10)); ArgumentCaptor<ReactStylesDiffMap> stylesCaptor = ArgumentCaptor.forClass(ReactStylesDiffMap.class); reset(mUIImplementationMock); mNativeAnimatedNodesManager.runUpdates(nextFrameTime()); verify(mUIImplementationMock).synchronouslyUpdateViewOnUIThread(eq(viewTag), stylesCaptor.capture()); assertThat(stylesCaptor.getValue().getDouble("opacity", Double.NaN)).isEqualTo(0); }
Example #3
Source File: RNInstabugBugReportingModuleTest.java From Instabug-React-Native with MIT License | 6 votes |
@Test public void givenOptions$setOptions_whenQuery_thenShouldCallNativeApiWithArgs() { // given PowerMockito.mockStatic(BugReporting.class); final Map<String, Object> args = new HashMap<>(); ArgsRegistry.registerInvocationOptionsArgs(args); final String[] keysArray = args.keySet().toArray(new String[0]); JavaOnlyArray actualArray = new JavaOnlyArray(); actualArray.pushString(keysArray[0]); actualArray.pushString(keysArray[1]); // when bugReportingModule.setOptions(actualArray); // then PowerMockito.verifyStatic(VerificationModeFactory.times(1)); int option1 = (int) args.get(keysArray[0]); int option2 = (int) args.get(keysArray[1]); BugReporting.setOptions(option1); PowerMockito.verifyStatic(VerificationModeFactory.times(1)); BugReporting.setOptions(option2); }
Example #4
Source File: RNInstabugBugReportingModuleTest.java From Instabug-React-Native with MIT License | 6 votes |
@Test public void givenInvocationEvent$setInvocationEvents_whenQuery_thenShouldCallNativeApiWithArgs() { // given PowerMockito.mockStatic(BugReporting.class); final Map<String, Object> args = new HashMap<>(); ArgsRegistry.registerInstabugInvocationEventsArgs(args); final String[] keysArray = args.keySet().toArray(new String[0]); JavaOnlyArray actualArray = new JavaOnlyArray(); for (String key : keysArray) { actualArray.pushString(key); } // when bugReportingModule.setInvocationEvents(actualArray); // then PowerMockito.verifyStatic(VerificationModeFactory.times(1)); BugReporting.setInvocationEvents(args.values().toArray(new InstabugInvocationEvent[0])); }
Example #5
Source File: JSONParserTest.java From react-native-navigation with MIT License | 6 votes |
@Test public void parsesArrays() throws Exception { JavaOnlyArray input = new JavaOnlyArray(); input.pushString("Hello"); input.pushInt(123); input.pushDouble(123.456); input.pushBoolean(true); input.pushArray(new JavaOnlyArray()); input.pushMap(new JavaOnlyMap()); input.pushNull(); JSONArray result = new JSONParser().parse(input); assertThat(result.length()).isEqualTo(6); assertThat(result.get(0)).isEqualTo("Hello"); assertThat(result.get(1)).isEqualTo(123); assertThat(result.get(2)).isEqualTo(123.456); assertThat(result.get(3)).isEqualTo(true); assertThat(result.getJSONArray(4).length()).isZero(); assertThat(result.getJSONObject(5).keys()).isEmpty(); }
Example #6
Source File: RNInstabugBugReportingModuleTest.java From Instabug-React-Native with MIT License | 6 votes |
@Test public void givenArray$setReportTypes_whenQuery_thenShouldCallNativeApiWithEnumArgs() { // given PowerMockito.mockStatic(BugReporting.class); final Map<String, Object> args = new HashMap<>(); ArgsRegistry.registerInstabugReportTypesArgs(args); final String[] keysArray = args.keySet().toArray(new String[0]); JavaOnlyArray actualArray = new JavaOnlyArray(); actualArray.pushString(keysArray[0]); actualArray.pushString(keysArray[1]); // when bugReportingModule.setReportTypes(actualArray); // then PowerMockito.verifyStatic(VerificationModeFactory.times(1)); int type1 = (int) args.get(keysArray[0]); int type2 = (int) args.get(keysArray[1]); BugReporting.setReportTypes(type1, type2); }
Example #7
Source File: RNInstabugBugReportingModuleTest.java From Instabug-React-Native with MIT License | 6 votes |
@Test public void givenArgs$showBugReportingWithReportTypeAndOptions_whenQuery_thenShouldCallNativeApiWithEnums() { // given PowerMockito.mockStatic(BugReporting.class); final Map<String, Object> optionsArgs = new HashMap<>(); final Map<String, Object> reportTypeArgs = new HashMap<>(); ArgsRegistry.registerInvocationOptionsArgs(optionsArgs); ArgsRegistry.registerInstabugReportTypesArgs(reportTypeArgs); final String[] keysArray = optionsArgs.keySet().toArray(new String[0]); final String[] reportTypeKeys = reportTypeArgs.keySet().toArray(new String[0]); JavaOnlyArray actualArray = new JavaOnlyArray(); actualArray.pushString(keysArray[0]); actualArray.pushString(keysArray[1]); // when bugReportingModule.show(reportTypeKeys[0], actualArray); // then int option1 = (int) optionsArgs.get(keysArray[0]); int option2 = (int) optionsArgs.get(keysArray[1]); PowerMockito.verifyStatic(VerificationModeFactory.times(1)); BugReporting.setOptions(option1); PowerMockito.verifyStatic(VerificationModeFactory.times(1)); BugReporting.setOptions(option2); PowerMockito.verifyStatic(VerificationModeFactory.times(1)); BugReporting.show((int) reportTypeArgs.get(reportTypeKeys[0])); }
Example #8
Source File: RNInstabugFeatureRequestsModuleTest.java From Instabug-React-Native with MIT License | 6 votes |
/********Feature Requests*********/ @Test public void givenArgs$setEmailFieldRequiredForFeatureRequests_whenQuery_thenShouldCallNativeApi() { // given PowerMockito.mockStatic(FeatureRequests.class); PowerMockito.mockStatic(Arguments.class); // when PowerMockito.when(Arguments.createArray()).thenReturn(new JavaOnlyArray()); ReadableArray actionTypes = Arguments.createArray(); ((WritableArray) actionTypes).pushString("requestNewFeature"); ((WritableArray) actionTypes).pushString("addCommentToFeature"); featureRequestsModule.setEmailFieldRequiredForFeatureRequests(true, actionTypes ); int[] parsedActionTypes = new int[2]; parsedActionTypes[0] = ActionType.REQUEST_NEW_FEATURE; parsedActionTypes[1] = ActionType.ADD_COMMENT_TO_FEATURE; // then PowerMockito.verifyStatic(VerificationModeFactory.times(1)); FeatureRequests.setEmailFieldRequired(true, parsedActionTypes); }
Example #9
Source File: RNInstabugReactnativeModuleTest.java From Instabug-React-Native with MIT License | 6 votes |
@Test public void givenCallback$getTags_whenQuery_thenShouldCallNativeApiAndInvokeCallback() { // given PowerMockito.mockStatic(Instabug.class); PowerMockito.mockStatic(Arguments.class); Callback callback = mock(Callback.class); // when ArrayList<String> tags = new ArrayList<>(); tags.add("tag1"); tags.add("tag2"); PowerMockito.when(Instabug.getTags()).thenReturn(tags); PowerMockito.when(Arguments.createArray()).thenReturn(new JavaOnlyArray()); rnModule.getTags(callback); // then PowerMockito.verifyStatic(VerificationModeFactory.times(1)); Instabug.getTags(); WritableArray expectedArray = new JavaOnlyArray(); expectedArray.pushString("tag1"); expectedArray.pushString("tag2"); verify(callback).invoke(expectedArray); }
Example #10
Source File: NativeAnimatedNodeTraversalTest.java From react-native-GPay with MIT License | 6 votes |
@Test public void testNativeAnimatedEventDoUpdate() { int viewTag = 1000; createSimpleAnimatedViewWithOpacity(viewTag, 0d); mNativeAnimatedNodesManager.addAnimatedEventToView(viewTag, "topScroll", JavaOnlyMap.of( "animatedValueTag", 1, "nativeEventPath", JavaOnlyArray.of("contentOffset", "y"))); mNativeAnimatedNodesManager.onEventDispatch(createScrollEvent(viewTag, 10)); ArgumentCaptor<ReactStylesDiffMap> stylesCaptor = ArgumentCaptor.forClass(ReactStylesDiffMap.class); reset(mUIImplementationMock); mNativeAnimatedNodesManager.runUpdates(nextFrameTime()); verify(mUIImplementationMock).synchronouslyUpdateViewOnUIThread(eq(viewTag), stylesCaptor.capture()); assertThat(stylesCaptor.getValue().getDouble("opacity", Double.NaN)).isEqualTo(10); }
Example #11
Source File: TimingModuleTest.java From react-native-GPay with MIT License | 6 votes |
@Test public void testPausingAndResuming() { mTiming.onHostResume(); mTiming.createTimer(41, 1, 0, true); stepChoreographerFrame(); verify(mJSTimersMock).callTimers(JavaOnlyArray.of(41)); reset(mJSTimersMock); mTiming.onHostPause(); stepChoreographerFrame(); verifyNoMoreInteractions(mJSTimersMock); reset(mJSTimersMock); mTiming.onHostResume(); stepChoreographerFrame(); verify(mJSTimersMock).callTimers(JavaOnlyArray.of(41)); }
Example #12
Source File: NativeAnimatedNodeTraversalTest.java From react-native-GPay with MIT License | 6 votes |
@Test public void testNodeValueListenerIfNotListening() { int nodeId = 1; createSimpleAnimatedViewWithOpacity(1000, 0d); JavaOnlyArray frames = JavaOnlyArray.of(0d, 0.2d, 0.4d, 0.6d, 0.8d, 1d); Callback animationCallback = mock(Callback.class); AnimatedNodeValueListener valueListener = mock(AnimatedNodeValueListener.class); mNativeAnimatedNodesManager.startListeningToAnimatedNodeValue(nodeId, valueListener); mNativeAnimatedNodesManager.startAnimatingNode( 1, nodeId, JavaOnlyMap.of("type", "frames", "frames", frames, "toValue", 1d), animationCallback); mNativeAnimatedNodesManager.runUpdates(nextFrameTime()); verify(valueListener).onValueUpdate(eq(0d)); mNativeAnimatedNodesManager.stopListeningToAnimatedNodeValue(nodeId); reset(valueListener); mNativeAnimatedNodesManager.runUpdates(nextFrameTime()); verifyNoMoreInteractions(valueListener); }
Example #13
Source File: TimingModuleTest.java From react-native-GPay with MIT License | 6 votes |
@Test public void testHeadlessJsTaskInForeground() { mTiming.onHostResume(); mTiming.onHeadlessJsTaskStart(42); mTiming.createTimer(41, 1, 0, true); stepChoreographerFrame(); verify(mJSTimersMock).callTimers(JavaOnlyArray.of(41)); reset(mJSTimersMock); mTiming.onHeadlessJsTaskFinish(42); stepChoreographerFrame(); verify(mJSTimersMock).callTimers(JavaOnlyArray.of(41)); reset(mJSTimersMock); mTiming.onHostPause(); verifyNoMoreInteractions(mJSTimersMock); }
Example #14
Source File: TimingModuleTest.java From react-native-GPay with MIT License | 6 votes |
@Test public void testHeadlessJsTaskIntertwine() { mTiming.onHostResume(); mTiming.onHeadlessJsTaskStart(42); mTiming.createTimer(41, 1, 0, true); mTiming.onHostPause(); stepChoreographerFrame(); verify(mJSTimersMock).callTimers(JavaOnlyArray.of(41)); reset(mJSTimersMock); mTiming.onHostResume(); mTiming.onHeadlessJsTaskFinish(42); stepChoreographerFrame(); verify(mJSTimersMock).callTimers(JavaOnlyArray.of(41)); reset(mJSTimersMock); mTiming.onHostPause(); stepChoreographerFrame(); verifyNoMoreInteractions(mJSTimersMock); }
Example #15
Source File: UIManagerModuleTest.java From react-native-GPay with MIT License | 6 votes |
@Test public void testDeleteViewsWithChildren() { UIManagerModule uiManager = getUIManagerModule(); TestMoveDeleteHierarchy hierarchy = createMoveDeleteHierarchy(uiManager); View expectedViewAt0 = hierarchy.nativeRootView.getChildAt(0); View expectedViewAt1 = hierarchy.nativeRootView.getChildAt(2); View expectedViewAt2 = hierarchy.nativeRootView.getChildAt(3); uiManager.manageChildren( hierarchy.rootView, null, null, null, null, JavaOnlyArray.of(1)); uiManager.onBatchComplete(); executePendingFrameCallbacks(); assertChildrenAreExactly( hierarchy.nativeRootView, expectedViewAt0, expectedViewAt1, expectedViewAt2); }
Example #16
Source File: TransformAnimatedNode.java From react-native-GPay with MIT License | 6 votes |
public void collectViewUpdates(JavaOnlyMap propsMap) { List<JavaOnlyMap> transforms = new ArrayList<>(mTransformConfigs.size()); for (TransformConfig transformConfig : mTransformConfigs) { double value; if (transformConfig instanceof AnimatedTransformConfig) { int nodeTag = ((AnimatedTransformConfig) transformConfig).mNodeTag; AnimatedNode node = mNativeAnimatedNodesManager.getNodeById(nodeTag); if (node == null) { throw new IllegalArgumentException("Mapped style node does not exists"); } else if (node instanceof ValueAnimatedNode) { value = ((ValueAnimatedNode) node).getValue(); } else { throw new IllegalArgumentException("Unsupported type of node used as a transform child " + "node " + node.getClass()); } } else { value = ((StaticTransformConfig) transformConfig).mValue; } transforms.add(JavaOnlyMap.of(transformConfig.mProperty, value)); } propsMap.putArray("transform", JavaOnlyArray.from(transforms)); }
Example #17
Source File: UIManagerModuleTest.java From react-native-GPay with MIT License | 6 votes |
@Test public void testDeleteViews() { UIManagerModule uiManager = getUIManagerModule(); TestMoveDeleteHierarchy hierarchy = createMoveDeleteHierarchy(uiManager); View expectedViewAt0 = hierarchy.nativeRootView.getChildAt(1); View expectedViewAt1 = hierarchy.nativeRootView.getChildAt(2); uiManager.manageChildren( hierarchy.rootView, null, null, null, null, JavaOnlyArray.of(0, 3)); uiManager.onBatchComplete(); executePendingFrameCallbacks(); assertChildrenAreExactly( hierarchy.nativeRootView, expectedViewAt0, expectedViewAt1); }
Example #18
Source File: UIManagerModuleTest.java From react-native-GPay with MIT License | 6 votes |
@Test public void testMoveAndDeleteViews() { UIManagerModule uiManager = getUIManagerModule(); TestMoveDeleteHierarchy hierarchy = createMoveDeleteHierarchy(uiManager); View expectedViewAt0 = hierarchy.nativeRootView.getChildAt(0); View expectedViewAt1 = hierarchy.nativeRootView.getChildAt(3); View expectedViewAt2 = hierarchy.nativeRootView.getChildAt(2); uiManager.manageChildren( hierarchy.rootView, JavaOnlyArray.of(3), JavaOnlyArray.of(1), null, null, JavaOnlyArray.of(1)); uiManager.onBatchComplete(); executePendingFrameCallbacks(); assertChildrenAreExactly( hierarchy.nativeRootView, expectedViewAt0, expectedViewAt1, expectedViewAt2); }
Example #19
Source File: UIManagerModuleTest.java From react-native-GPay with MIT License | 6 votes |
@Test(expected = IllegalViewOperationException.class) public void testMoveAndDeleteRemoveViewsDuplicateRemove() { UIManagerModule uiManager = getUIManagerModule(); TestMoveDeleteHierarchy hierarchy = createMoveDeleteHierarchy(uiManager); uiManager.manageChildren( hierarchy.rootView, JavaOnlyArray.of(3), JavaOnlyArray.of(1), null, null, JavaOnlyArray.of(3)); uiManager.onBatchComplete(); executePendingFrameCallbacks(); }
Example #20
Source File: UIManagerModuleTest.java From react-native-GPay with MIT License | 6 votes |
@Test(expected = IllegalViewOperationException.class) public void testDuplicateRemove() { UIManagerModule uiManager = getUIManagerModule(); TestMoveDeleteHierarchy hierarchy = createMoveDeleteHierarchy(uiManager); uiManager.manageChildren( hierarchy.rootView, null, null, null, null, JavaOnlyArray.of(3, 3)); uiManager.onBatchComplete(); executePendingFrameCallbacks(); }
Example #21
Source File: NativeAnimatedNodeTraversalTest.java From react-native-GPay with MIT License | 5 votes |
@Test public void testAdditionNode() { createAnimatedGraphWithAdditionNode(50, 100d, 1000d); Callback animationCallback = mock(Callback.class); JavaOnlyArray frames = JavaOnlyArray.of(0d, 1d); mNativeAnimatedNodesManager.startAnimatingNode( 1, 1, JavaOnlyMap.of("type", "frames", "frames", frames, "toValue", 101d), animationCallback); mNativeAnimatedNodesManager.startAnimatingNode( 2, 2, JavaOnlyMap.of("type", "frames", "frames", frames, "toValue", 1010d), animationCallback); ArgumentCaptor<ReactStylesDiffMap> stylesCaptor = ArgumentCaptor.forClass(ReactStylesDiffMap.class); reset(mUIImplementationMock); mNativeAnimatedNodesManager.runUpdates(nextFrameTime()); verify(mUIImplementationMock).synchronouslyUpdateViewOnUIThread(eq(50), stylesCaptor.capture()); assertThat(stylesCaptor.getValue().getDouble("translateX", Double.NaN)).isEqualTo(1100d); reset(mUIImplementationMock); mNativeAnimatedNodesManager.runUpdates(nextFrameTime()); verify(mUIImplementationMock) .synchronouslyUpdateViewOnUIThread(eq(50), stylesCaptor.capture()); assertThat(stylesCaptor.getValue().getDouble("translateX", Double.NaN)).isEqualTo(1111d); reset(mUIImplementationMock); mNativeAnimatedNodesManager.runUpdates(nextFrameTime()); verifyNoMoreInteractions(mUIImplementationMock); }
Example #22
Source File: NativeAnimatedNodeTraversalTest.java From react-native-GPay with MIT License | 5 votes |
/** * Creates a following graph of nodes: * Value(1, firstValue) ----> Add(3) ---> Style(4) ---> Props(5) ---> View(viewTag) * | * Value(2, secondValue) --+ * * Add(3) node maps to a "translateX" attribute of the Style(4) node. */ private void createAnimatedGraphWithAdditionNode( int viewTag, double firstValue, double secondValue) { mNativeAnimatedNodesManager.createAnimatedNode( 1, JavaOnlyMap.of("type", "value", "value", firstValue, "offset", 0d)); mNativeAnimatedNodesManager.createAnimatedNode( 2, JavaOnlyMap.of("type", "value", "value", secondValue, "offset", 0d)); mNativeAnimatedNodesManager.createAnimatedNode( 3, JavaOnlyMap.of("type", "addition", "input", JavaOnlyArray.of(1, 2))); mNativeAnimatedNodesManager.createAnimatedNode( 4, JavaOnlyMap.of("type", "style", "style", JavaOnlyMap.of("translateX", 3))); mNativeAnimatedNodesManager.createAnimatedNode( 5, JavaOnlyMap.of("type", "props", "props", JavaOnlyMap.of("style", 4))); mNativeAnimatedNodesManager.connectAnimatedNodes(1, 3); mNativeAnimatedNodesManager.connectAnimatedNodes(2, 3); mNativeAnimatedNodesManager.connectAnimatedNodes(3, 4); mNativeAnimatedNodesManager.connectAnimatedNodes(4, 5); mNativeAnimatedNodesManager.connectAnimatedNodeToView(5, viewTag); }
Example #23
Source File: NativeAnimatedNodeTraversalTest.java From react-native-GPay with MIT License | 5 votes |
/** * Verifies that {@link NativeAnimatedNodesManager#runUpdates} updates the view correctly in case * when one of the addition input nodes has started animating while the other one has not. * * We expect that the output of the addition node will take the starting value of the second input * node even though the node hasn't been connected to an active animation driver. */ @Test public void testViewReceiveUpdatesIfOneOfAnimationHasntStarted() { createAnimatedGraphWithAdditionNode(50, 100d, 1000d); // Start animating only the first addition input node Callback animationCallback = mock(Callback.class); JavaOnlyArray frames = JavaOnlyArray.of(0d, 1d); mNativeAnimatedNodesManager.startAnimatingNode( 1, 1, JavaOnlyMap.of("type", "frames", "frames", frames, "toValue", 101d), animationCallback); ArgumentCaptor<ReactStylesDiffMap> stylesCaptor = ArgumentCaptor.forClass(ReactStylesDiffMap.class); reset(mUIImplementationMock); mNativeAnimatedNodesManager.runUpdates(nextFrameTime()); verify(mUIImplementationMock).synchronouslyUpdateViewOnUIThread(eq(50), stylesCaptor.capture()); assertThat(stylesCaptor.getValue().getDouble("translateX", Double.NaN)).isEqualTo(1100d); reset(mUIImplementationMock); mNativeAnimatedNodesManager.runUpdates(nextFrameTime()); verify(mUIImplementationMock) .synchronouslyUpdateViewOnUIThread(eq(50), stylesCaptor.capture()); assertThat(stylesCaptor.getValue().getDouble("translateX", Double.NaN)).isEqualTo(1101d); reset(mUIImplementationMock); mNativeAnimatedNodesManager.runUpdates(nextFrameTime()); verifyNoMoreInteractions(mUIImplementationMock); }
Example #24
Source File: UIManagerModuleTest.java From react-native-GPay with MIT License | 5 votes |
/** * Assuming no other views have been created, the root view will have tag 1, Text tag 2, and * RawText tag 3. */ private ViewGroup createSimpleTextHierarchy(UIManagerModule uiManager, String text) { ReactRootView rootView = new ReactRootView(RuntimeEnvironment.application.getApplicationContext()); int rootTag = uiManager.addRootView(rootView); int textTag = rootTag + 1; int rawTextTag = textTag + 1; uiManager.createView( textTag, ReactTextViewManager.REACT_CLASS, rootTag, JavaOnlyMap.of("collapsable", false)); uiManager.createView( rawTextTag, ReactRawTextManager.REACT_CLASS, rootTag, JavaOnlyMap.of(ReactRawTextShadowNode.PROP_TEXT, text, "collapsable", false)); uiManager.manageChildren( textTag, null, null, JavaOnlyArray.of(rawTextTag), JavaOnlyArray.of(0), null); uiManager.manageChildren( rootTag, null, null, JavaOnlyArray.of(textTag), JavaOnlyArray.of(0), null); uiManager.onBatchComplete(); executePendingFrameCallbacks(); return rootView; }
Example #25
Source File: UIManagerModuleTest.java From react-native-GPay with MIT License | 5 votes |
/** * This is to make sure we execute enqueued operations in the order given by JS. */ @Test public void testAddUpdateRemoveInSingleBatch() { UIManagerModule uiManager = getUIManagerModule(); TestMoveDeleteHierarchy hierarchy = createMoveDeleteHierarchy(uiManager); int newViewTag = 10000; uiManager.createView( newViewTag, ReactViewManager.REACT_CLASS, hierarchy.rootView, JavaOnlyMap.of("collapsable", false)); uiManager.manageChildren( hierarchy.rootView, null, null, JavaOnlyArray.of(newViewTag), JavaOnlyArray.of(4), null); uiManager.updateView( newViewTag, ReactViewManager.REACT_CLASS, JavaOnlyMap.of("backgroundColor", Color.RED)); uiManager.manageChildren( hierarchy.rootView, null, null, null, null, JavaOnlyArray.of(4)); uiManager.onBatchComplete(); executePendingFrameCallbacks(); assertThat(hierarchy.nativeRootView.getChildCount()).isEqualTo(4); }
Example #26
Source File: UIManagerModuleTest.java From react-native-GPay with MIT License | 5 votes |
@Test public void testLayoutAppliedToNodes() throws Exception { UIManagerModule uiManager = getUIManagerModule(); TestMoveDeleteHierarchy hierarchy = createMoveDeleteHierarchy(uiManager); int newViewTag = 10000; uiManager.createView( newViewTag, ReactViewManager.REACT_CLASS, hierarchy.rootView, JavaOnlyMap .of("left", 10.0, "top", 20.0, "width", 30.0, "height", 40.0, "collapsable", false)); uiManager.manageChildren( hierarchy.rootView, null, null, JavaOnlyArray.of(newViewTag), JavaOnlyArray.of(4), null); uiManager.onBatchComplete(); executePendingFrameCallbacks(); View newView = hierarchy.nativeRootView.getChildAt(4); assertThat(newView.getLeft()).isEqualTo(10); assertThat(newView.getTop()).isEqualTo(20); assertThat(newView.getWidth()).isEqualTo(30); assertThat(newView.getHeight()).isEqualTo(40); }
Example #27
Source File: UIManagerModuleTest.java From react-native-GPay with MIT License | 5 votes |
@Test public void testMoveViewsWithChildren() { UIManagerModule uiManager = getUIManagerModule(); TestMoveDeleteHierarchy hierarchy = createMoveDeleteHierarchy(uiManager); View expectedViewAt0 = hierarchy.nativeRootView.getChildAt(0); View expectedViewAt1 = hierarchy.nativeRootView.getChildAt(2); View expectedViewAt2 = hierarchy.nativeRootView.getChildAt(1); View expectedViewAt3 = hierarchy.nativeRootView.getChildAt(3); uiManager.manageChildren( hierarchy.rootView, JavaOnlyArray.of(1, 2), JavaOnlyArray.of(2, 1), null, null, null); uiManager.onBatchComplete(); executePendingFrameCallbacks(); assertChildrenAreExactly( hierarchy.nativeRootView, expectedViewAt0, expectedViewAt1, expectedViewAt2, expectedViewAt3); assertThat(((ViewGroup) hierarchy.nativeRootView.getChildAt(2)).getChildCount()).isEqualTo(2); }
Example #28
Source File: RNInstabugReactnativeModuleTest.java From Instabug-React-Native with MIT License | 5 votes |
@Test public void givenArg$appendTags_whenQuery_thenShouldCallNativeApiWithArg() { // given PowerMockito.mockStatic(Instabug.class); JavaOnlyArray array = new JavaOnlyArray(); array.pushString("tag1"); array.pushString("tag2"); // when rnModule.appendTags(array); // then PowerMockito.verifyStatic(VerificationModeFactory.times(1)); String [] expectedArray = {"tag1", "tag2"}; Instabug.addTags(expectedArray); }
Example #29
Source File: UIManagerModuleTest.java From react-native-GPay with MIT License | 5 votes |
@Test public void testMoveAndAddViews() { UIManagerModule uiManager = getUIManagerModule(); TestMoveDeleteHierarchy hierarchy = createMoveDeleteHierarchy(uiManager); int textViewTag = 1000; uiManager.createView( textViewTag, ReactTextViewManager.REACT_CLASS, hierarchy.rootView, JavaOnlyMap.of("collapsable", false)); View expectedViewAt0 = hierarchy.nativeRootView.getChildAt(0); View expectedViewAt1 = hierarchy.nativeRootView.getChildAt(3); View expectedViewAt3 = hierarchy.nativeRootView.getChildAt(1); View expectedViewAt4 = hierarchy.nativeRootView.getChildAt(2); uiManager.manageChildren( hierarchy.rootView, JavaOnlyArray.of(1, 2, 3), JavaOnlyArray.of(3, 4, 1), JavaOnlyArray.of(textViewTag), JavaOnlyArray.of(2), null); uiManager.onBatchComplete(); executePendingFrameCallbacks(); assertThat(hierarchy.nativeRootView.getChildCount()).isEqualTo(5); assertThat(hierarchy.nativeRootView.getChildAt(0)).isEqualTo(expectedViewAt0); assertThat(hierarchy.nativeRootView.getChildAt(1)).isEqualTo(expectedViewAt1); assertThat(hierarchy.nativeRootView.getChildAt(3)).isEqualTo(expectedViewAt3); assertThat(hierarchy.nativeRootView.getChildAt(4)).isEqualTo(expectedViewAt4); }
Example #30
Source File: NativeAnimatedNodeTraversalTest.java From react-native-GPay with MIT License | 5 votes |
@Test public void testFramesAnimation() { createSimpleAnimatedViewWithOpacity(1000, 0d); JavaOnlyArray frames = JavaOnlyArray.of(0d, 0.2d, 0.4d, 0.6d, 0.8d, 1d); Callback animationCallback = mock(Callback.class); mNativeAnimatedNodesManager.startAnimatingNode( 1, 1, JavaOnlyMap.of("type", "frames", "frames", frames, "toValue", 1d), animationCallback); ArgumentCaptor<ReactStylesDiffMap> stylesCaptor = ArgumentCaptor.forClass(ReactStylesDiffMap.class); for (int i = 0; i < frames.size(); i++) { reset(mUIImplementationMock); mNativeAnimatedNodesManager.runUpdates(nextFrameTime()); verify(mUIImplementationMock) .synchronouslyUpdateViewOnUIThread(eq(1000), stylesCaptor.capture()); assertThat(stylesCaptor.getValue().getDouble("opacity", Double.NaN)) .isEqualTo(frames.getDouble(i)); } reset(mUIImplementationMock); mNativeAnimatedNodesManager.runUpdates(nextFrameTime()); verifyNoMoreInteractions(mUIImplementationMock); }