mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
3b31e69e28
Summary: Changelog: [General] [Fixed] - License header cleanup Reviewed By: yungsters Differential Revision: D17952694 fbshipit-source-id: 17c87de7ebb271fa2ac8d00af72a4d1addef8bd0
93 lines
2.6 KiB
Java
93 lines
2.6 KiB
Java
/*
|
|
* 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.Instrumentation.ActivityMonitor;
|
|
import android.content.Intent;
|
|
import android.content.IntentFilter;
|
|
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.share.ShareModule;
|
|
import com.facebook.react.testing.ReactAppInstrumentationTestCase;
|
|
import com.facebook.react.testing.ReactInstanceSpecForTest;
|
|
|
|
/** 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());
|
|
}
|
|
}
|