mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
1490ab12ef
Summary:
Includes React Native and its dependencies Fresco, Metro, and Yoga. Excludes samples/examples/docs.
find: ^(?:( *)|( *(?:[\*~#]|::))( )? *)?Copyright (?:\(c\) )?(\d{4})\b.+Facebook[\s\S]+?BSD[\s\S]+?(?:this source tree|the same directory)\.$
replace: $1$2$3Copyright (c) $4-present, Facebook, Inc.\n$2\n$1$2$3This source code is licensed under the MIT license found in the\n$1$2$3LICENSE file in the root directory of this source tree.
Reviewed By: TheSavior, yungsters
Differential Revision: D7007050
fbshipit-source-id: 37dd6bf0ffec0923bfc99c260bb330683f35553e
108 lines
2.9 KiB
Java
108 lines
2.9 KiB
Java
/**
|
|
* Copyright (c) 2014-present, Facebook, Inc.
|
|
*
|
|
* 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 java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
import android.app.Activity;
|
|
import android.app.AlertDialog;
|
|
import android.app.Instrumentation.ActivityMonitor;
|
|
import android.content.DialogInterface;
|
|
import android.content.Intent;
|
|
import android.content.IntentFilter;
|
|
import android.content.IntentFilter.MalformedMimeTypeException;
|
|
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.share.ShareModule;
|
|
import com.facebook.react.testing.ReactAppInstrumentationTestCase;
|
|
|
|
/**
|
|
* Test case for {@link ShareModule}.
|
|
*/
|
|
public class ShareTestCase extends ReactAppInstrumentationTestCase {
|
|
|
|
private static interface ShareTestModule extends JavaScriptModule {
|
|
public void showShareDialog(WritableMap content, WritableMap options);
|
|
}
|
|
|
|
private static class ShareRecordingModule extends BaseJavaModule {
|
|
|
|
private int mOpened = 0;
|
|
private int mErrors = 0;
|
|
|
|
@Override
|
|
public String getName() {
|
|
return "ShareRecordingModule";
|
|
}
|
|
|
|
@ReactMethod
|
|
public void recordOpened() {
|
|
mOpened++;
|
|
}
|
|
|
|
@ReactMethod
|
|
public void recordError() {
|
|
mErrors++;
|
|
}
|
|
|
|
public int getOpened() {
|
|
return mOpened;
|
|
}
|
|
|
|
public int getErrors() {
|
|
return mErrors;
|
|
}
|
|
|
|
}
|
|
|
|
final ShareRecordingModule mRecordingModule = new ShareRecordingModule();
|
|
|
|
@Override
|
|
protected ReactInstanceSpecForTest createReactInstanceSpecForTest() {
|
|
return super.createReactInstanceSpecForTest()
|
|
.addNativeModule(mRecordingModule);
|
|
}
|
|
|
|
@Override
|
|
protected String getReactApplicationKeyUnderTest() {
|
|
return "ShareTestApp";
|
|
}
|
|
|
|
private ShareTestModule getTestModule() {
|
|
return getReactContext().getCatalystInstance().getJSModule(ShareTestModule.class);
|
|
}
|
|
|
|
public void testShowBasicShareDialog() {
|
|
final WritableMap content = new WritableNativeMap();
|
|
content.putString("message", "Hello, ReactNative!");
|
|
final WritableMap options = new WritableNativeMap();
|
|
|
|
IntentFilter intentFilter = new IntentFilter(Intent.ACTION_CHOOSER);
|
|
intentFilter.addCategory(Intent.CATEGORY_DEFAULT);
|
|
ActivityMonitor monitor = getInstrumentation().addMonitor(intentFilter, null, true);
|
|
|
|
getTestModule().showShareDialog(content, options);
|
|
|
|
waitForBridgeAndUIIdle();
|
|
getInstrumentation().waitForIdleSync();
|
|
|
|
assertEquals(1, monitor.getHits());
|
|
assertEquals(1, mRecordingModule.getOpened());
|
|
assertEquals(0, mRecordingModule.getErrors());
|
|
|
|
}
|
|
|
|
}
|