|
| 1 | +/** |
| 2 | + * Copyright (c) Facebook, Inc. and its affiliates. |
| 3 | + * |
| 4 | + * This source code is licensed under the MIT license found in the |
| 5 | + * LICENSE file in the root directory of this source tree. |
| 6 | + * |
| 7 | + * @format |
| 8 | + */ |
| 9 | + |
| 10 | +import {NativeModules, Platform} from 'react-native'; |
| 11 | +import InAppReview from '../'; |
| 12 | + |
| 13 | +jest.mock('react-native/Libraries/Utilities/Platform', () => { |
| 14 | + let platform = { |
| 15 | + OS: 'ios', |
| 16 | + }; |
| 17 | + |
| 18 | + const select = jest.fn().mockImplementation((obj) => { |
| 19 | + const value = obj[platform.OS]; |
| 20 | + return !value ? obj.default : value; |
| 21 | + }); |
| 22 | + |
| 23 | + platform.select = select; |
| 24 | + |
| 25 | + return platform; |
| 26 | +}); |
| 27 | + |
| 28 | +describe('react-native-in-app-review', () => { |
| 29 | + it('should show Review Dialog in iOS if native module exist', () => { |
| 30 | + Platform.OS = 'ios'; |
| 31 | + |
| 32 | + InAppReview.RequestInAppReview(); |
| 33 | + |
| 34 | + expect( |
| 35 | + NativeModules.RNInAppReviewIOS.requestReview.mock.calls, |
| 36 | + ).toHaveLength(1); |
| 37 | + }); |
| 38 | + |
| 39 | + it('should lanuch in App review in android if native module exist and android api >= 21', () => { |
| 40 | + Platform.OS = 'android'; |
| 41 | + Platform.Version = 21; |
| 42 | + |
| 43 | + InAppReview.RequestInAppReview(); |
| 44 | + |
| 45 | + expect(NativeModules.InAppReviewModule.show.mock.calls).toHaveLength(1); |
| 46 | + }); |
| 47 | + |
| 48 | + it('should not lanuch in App review in android if native module exist and android api < 21', () => { |
| 49 | + Platform.OS = 'android'; |
| 50 | + Platform.Version = 19; |
| 51 | + |
| 52 | + InAppReview.RequestInAppReview(); |
| 53 | + |
| 54 | + expect(NativeModules.InAppReviewModule.show.mock.calls).toHaveLength(0); |
| 55 | + }); |
| 56 | + |
| 57 | + it('should return isAvailable true in android if android api >= 21', () => { |
| 58 | + Platform.OS = 'android'; |
| 59 | + Platform.Version = 22; |
| 60 | + |
| 61 | + expect(InAppReview.isAvailable()).toBeTruthy(); |
| 62 | + }); |
| 63 | + it('should return isAvailable false in android if android api < 21', () => { |
| 64 | + Platform.OS = 'android'; |
| 65 | + Platform.Version = 19; |
| 66 | + expect(InAppReview.isAvailable()).toBeFalsy(); |
| 67 | + }); |
| 68 | +}); |
0 commit comments