Skip to content

Commit

Permalink
Java Unit Test checkForKeyboardEvents
Browse files Browse the repository at this point in the history
basic setup of the test passing green verifies that the event is invoked
twice

Still have to understand why the event is triggered twice

I faked the implementation of getWindowVisibleDisplayFrame to simulate
the keyboard opening that triggers keyboardDidShow event
  • Loading branch information
fabOnReact committed Feb 12, 2021
1 parent d3613a9 commit cc7ca27
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions ReactAndroid/src/test/java/com/facebook/react/RootViewTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,19 @@

package com.facebook.react;

import com.facebook.react.uimanager.ReactRoot;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.modules.core.DeviceEventManagerModule;
import com.facebook.react.bridge.WritableMap;
import android.util.Log;
import android.graphics.Rect;

import static org.fest.assertions.api.Assertions.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import org.mockito.Mockito;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
Expand Down Expand Up @@ -204,4 +213,31 @@ public void testRemountApplication() {
rootView.unmountReactApplication();
rootView.startReactApplication(instanceManager, "");
}

@Test
public void testCheckForKeyboardEvents() {
ReactInstanceManager instanceManager = mock(ReactInstanceManager.class);
when(instanceManager.getCurrentReactContext()).thenReturn(mReactContext);
UIManagerModule uiManager = mock(UIManagerModule.class);
EventDispatcher eventDispatcher = mock(EventDispatcher.class);
DeviceEventManagerModule.RCTDeviceEventEmitter eventEmitterModuleMock = mock(DeviceEventManagerModule.RCTDeviceEventEmitter.class);
when(mReactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)).thenReturn(eventEmitterModuleMock);
when(mCatalystInstanceMock.getNativeModule(UIManagerModule.class)).thenReturn(uiManager);
when(uiManager.getEventDispatcher()).thenReturn(eventDispatcher);

int rootViewId = 7;

ReactRootView rootView = new ReactRootView(mReactContext) {
@Override
public void getWindowVisibleDisplayFrame(Rect outRect) {
outRect.bottom += 100;
}
};
rootView.setId(rootViewId);
rootView.setRootViewTag(rootViewId);
rootView.startReactApplication(instanceManager, "");
rootView.simulateAttachForTesting();
rootView.getCustomGlobalLayoutListener().checkForKeyboardEvents();
verify(instanceManager, Mockito.times(2)).getCurrentReactContext();
}
}

0 comments on commit cc7ca27

Please sign in to comment.