Skip to content

Commit

Permalink
add new test, init new promise in android related to InAppcomment func (
Browse files Browse the repository at this point in the history
  • Loading branch information
MinaSamir11 committed Apr 16, 2022
1 parent 039ff2d commit 283b89f
Show file tree
Hide file tree
Showing 4 changed files with 27,919 additions and 27,897 deletions.
6 changes: 4 additions & 2 deletions __tests__/InAppReview-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jest.mock('react-native/Libraries/BatchedBridge/NativeModules', () => {
let _NativeModules = {};

_NativeModules = {
InAppReviewModule: {show: jest.fn()},
InAppReviewModule: {show: jest.fn(), showInAppCommentHMS: jest.fn()},
RNInAppReviewIOS: {requestReview: jest.fn(), isAvailable: jest.fn()},
};

Expand Down Expand Up @@ -64,7 +64,9 @@ describe('test-react-native-in-app-review-when-NativeModules-exist', () => {

await InAppReview.requestInAppCommentAppGallery();

expect(NativeModules.InAppReviewModule.show.mock.calls).toHaveLength(1);
expect(
NativeModules.InAppReviewModule.showInAppCommentHMS.mock.calls,
).toHaveLength(1);
});

it('should show Review Dialog in iOS if native module exist', async () => {
Expand Down
10 changes: 10 additions & 0 deletions __tests__/InAppReviewWithoutNativeModules-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,14 @@ describe('test-react-native-in-app-review-without-NativeModules-exist', () => {
InAppReview.RequestInAppReview();
}).toThrow(errorMessageExpected);
});

it('should throw error in calling in app comment Module if module not exist', async () => {
Platform.OS = 'android';

const errorMessageExpected =
'InAppReview native module not available, did you forget to link the library?';
expect(() => {
InAppReview.requestInAppCommentAppGallery();
}).toThrow(errorMessageExpected);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class AppReviewModule extends ReactContextBaseJavaModule implements Activ

private final ReactApplicationContext mContext;
private Promise pendingPromise;
private Promise pendingInAppCommentPromise;

public AppReviewModule(ReactApplicationContext reactContext) {
super(reactContext);
Expand Down Expand Up @@ -87,15 +88,16 @@ public void show(final Promise promise) {
}

@ReactMethod
public void showInAppCommentHMS () {
public void showInAppCommentHMS (final Promise promise) {
this.pendingInAppCommentPromise = promise;
Activity currentActivity = getCurrentActivity();

Intent intent = new Intent("com.huawei.appmarket.intent.action.guidecomment");
intent.setPackage("com.huawei.appmarket");
if (currentActivity != null) {
currentActivity.startActivityForResult(intent, 1001);
}else {
rejectPromise("24", new Error("ACTIVITY_DOESN'T_EXIST"));
rejectPromiseHMS("24", new Error("ACTIVITY_DOESN'T_EXIST"));
}

}
Expand All @@ -107,6 +109,13 @@ private void rejectPromise(String code, Error err) {
}
}

private void rejectPromiseHMS(String code, Error err) {
if (this.pendingInAppCommentPromise != null) {
this.pendingInAppCommentPromise.reject(code, err);
this.pendingInAppCommentPromise = null;
}
}

private void resolvePromise(boolean hasFlowFinishedSuccessfully) {
if (this.pendingPromise != null) {
this.pendingPromise.resolve(hasFlowFinishedSuccessfully);
Expand All @@ -115,12 +124,12 @@ private void resolvePromise(boolean hasFlowFinishedSuccessfully) {
}

private void resolvePromiseHMS(int resultCode) {
if (this.pendingPromise != null) {
this.pendingPromise.resolve(resultCode);
this.pendingPromise = null;
if (this.pendingInAppCommentPromise != null) {
this.pendingInAppCommentPromise.resolve(resultCode);
}
}


private boolean isGooglePlayServicesAvailable() {
GoogleApiAvailability GMS = GoogleApiAvailability.getInstance();
int isGMS = GMS.isGooglePlayServicesAvailable(mContext);
Expand All @@ -133,10 +142,10 @@ public void onActivityResult(Activity activity, int requestCode, int resultCode,
if (resultCode == 101) {
// Ensure that your app has been correctly released on AppGallery.
Log.e("huawei_errorrr1 Ensure that your app has been correctly released on AppGallery", isGooglePlayServicesAvailable() + "");
rejectPromise("101", new Error("Ensure that your app has been correctly released on AppGallery"));
rejectPromiseHMS("101", new Error("Ensure that your app has been correctly released on AppGallery"));
} else if (resultCode == 0){
Log.e("huawei_errorrr1 in app comment Unknown error.", "Unknown error");
rejectPromise("0", new Error("in app comment Unknown error"));
rejectPromiseHMS("0", new Error("in app comment Unknown error"));
}
else if (resultCode == 102){
Log.e("huawei_errorrr1 rating submitted", "rating done");
Expand All @@ -145,20 +154,20 @@ else if (resultCode == 102){
Log.e("huawei_errorrr1 Comment submitted", "rating done");
resolvePromiseHMS(103);
} else if (resultCode == 104) {
rejectPromise("104", new Error("check the HUAWEI ID sign-in status"));
rejectPromiseHMS("104", new Error("check the HUAWEI ID sign-in status"));
// Prompt the user to check the HUAWEI ID sign-in status.
Log.e("huawei_errorrr1 check the HUAWEI ID sign-in status", "");
} else if (resultCode == 105) {
rejectPromise("105", new Error("The user does not meet the conditions for displaying the comment pop-up"));
rejectPromiseHMS("105", new Error("The user does not meet the conditions for displaying the comment pop-up"));
Log.e("huawei_errorrr1 The user does not meet the conditions for displaying the comment pop-up", "");
} else if (resultCode == 106){
rejectPromise("106", new Error("The commenting function is disabled"));
rejectPromiseHMS("106", new Error("The commenting function is disabled"));
Log.e(" huawei_errorrr1 The commenting function is disabled", "disabled");
} else if (resultCode == 107){
rejectPromise("107", new Error("The in-app commenting service is not supported. (Apps released in the Chinese mainland do not support this service.)"));
rejectPromiseHMS("107", new Error("The in-app commenting service is not supported. (Apps released in the Chinese mainland do not support this service.)"));
Log.e("huawei_errorrr1 The in-app commenting service is not supported. (Apps released in the Chinese mainland do not support this service.)", "in-app commenting service is not supported");
} else if (resultCode == 108){
rejectPromise("108", new Error("The user canceled the comment"));
rejectPromiseHMS("108", new Error("The user canceled the comment"));
Log.e("huawei_errorrr1 The user canceled the comment.", "user canceled");
}
}
Expand Down
Loading

0 comments on commit 283b89f

Please sign in to comment.