mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Move TimePickerAndroid to FB internal
Summary: Moving TimePickerAndroid to FB internal. Changelog: [Android][Changed] - Moved TimePickerAndroid to FB internal. Reviewed By: cpojer Differential Revision: D21504128 fbshipit-source-id: 400c6ee7cff96a0d6b4205f7806ef8951b611b8c
This commit is contained in:
committed by
Facebook GitHub Bot
parent
1a77943e8b
commit
c8fed9e385
@@ -28,7 +28,6 @@ rn_android_library(
|
||||
react_native_target("java/com/facebook/react/modules/deviceinfo:deviceinfo"),
|
||||
react_native_target("java/com/facebook/react/modules/share:share"),
|
||||
react_native_target("java/com/facebook/react/modules/systeminfo:systeminfo"),
|
||||
react_native_target("java/com/facebook/react/modules/timepicker:timepicker"),
|
||||
react_native_target("java/com/facebook/react/touch:touch"),
|
||||
react_native_target("java/com/facebook/react/uimanager:uimanager"),
|
||||
react_native_target("java/com/facebook/react/uimanager/annotations:annotations"),
|
||||
|
||||
-156
@@ -1,156 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
package com.facebook.react.tests;
|
||||
|
||||
import android.app.TimePickerDialog;
|
||||
import android.content.DialogInterface;
|
||||
import androidx.fragment.app.DialogFragment;
|
||||
import com.facebook.react.bridge.BaseJavaModule;
|
||||
import com.facebook.react.bridge.JavaScriptModule;
|
||||
import com.facebook.react.bridge.ReactMethod;
|
||||
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;
|
||||
import com.facebook.react.testing.ReactInstanceSpecForTest;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/** 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);
|
||||
}
|
||||
|
||||
@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());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user