1- import { afterAll , beforeAll , describe , expect , it } from '@jest/globals' ;
1+ import { afterAll , beforeAll , beforeEach , describe , expect , it , jest } from '@jest/globals' ;
22
33import {
44 firebase ,
@@ -10,6 +10,14 @@ import {
1010 triggerEvent ,
1111} from '../lib' ;
1212
13+ import {
14+ createCheckV9Deprecation ,
15+ CheckV9DeprecationFunction ,
16+ } from '../../app/lib/common/unitTestUtils' ;
17+
18+ // @ts -ignore test
19+ import FirebaseModule from '../../app/lib/internal/FirebaseModule' ;
20+
1321describe ( 'in-app-messaging' , function ( ) {
1422 describe ( 'namespace' , function ( ) {
1523 beforeAll ( async function ( ) {
@@ -25,10 +33,36 @@ describe('in-app-messaging', function () {
2533 it ( 'accessible from firebase.app()' , function ( ) {
2634 const app = firebase . app ( ) ;
2735 expect ( app . inAppMessaging ) . toBeDefined ( ) ;
36+ expect ( app . inAppMessaging ( ) . app ) . toEqual ( app ) ;
2837 } ) ;
2938 } ) ;
3039
3140 describe ( 'modular' , function ( ) {
41+ beforeEach ( async function ( ) {
42+ // @ts -ignore test
43+ jest . spyOn ( FirebaseModule . prototype , 'native' , 'get' ) . mockImplementation ( ( ) => {
44+ return new Proxy (
45+ { } ,
46+ {
47+ get : ( _target , prop ) => {
48+ if (
49+ prop === 'isMessagesDisplaySuppressed' ||
50+ prop === 'isAutomaticDataCollectionEnabled'
51+ ) {
52+ return false ;
53+ }
54+
55+ return jest . fn ( ) . mockResolvedValue ( null as never ) ;
56+ } ,
57+ } ,
58+ ) ;
59+ } ) ;
60+
61+ const inAppMessaging = getInAppMessaging ( ) ;
62+ await setMessagesDisplaySuppressed ( inAppMessaging , false ) ;
63+ await setAutomaticDataCollectionEnabled ( inAppMessaging , false ) ;
64+ } ) ;
65+
3266 it ( '`getInAppMessaging` function is properly exposed to end user' , function ( ) {
3367 expect ( getInAppMessaging ) . toBeDefined ( ) ;
3468 } ) ;
@@ -52,5 +86,103 @@ describe('in-app-messaging', function () {
5286 it ( '`triggerEvent` function is properly exposed to end user' , function ( ) {
5387 expect ( triggerEvent ) . toBeDefined ( ) ;
5488 } ) ;
89+
90+ it ( 'updates isMessagesDisplaySuppressed synchronously after setMessagesDisplaySuppressed' , function ( ) {
91+ const inAppMessaging = getInAppMessaging ( ) ;
92+ expect ( isMessagesDisplaySuppressed ( inAppMessaging ) ) . toBe ( false ) ;
93+ setMessagesDisplaySuppressed ( inAppMessaging , true ) ;
94+ expect ( isMessagesDisplaySuppressed ( inAppMessaging ) ) . toBe ( true ) ;
95+ } ) ;
96+
97+ it ( 'updates isMessagesDisplaySuppressed after setMessagesDisplaySuppressed resolves' , async function ( ) {
98+ const inAppMessaging = getInAppMessaging ( ) ;
99+ await setMessagesDisplaySuppressed ( inAppMessaging , true ) ;
100+ expect ( isMessagesDisplaySuppressed ( inAppMessaging ) ) . toBe ( true ) ;
101+ } ) ;
102+
103+ it ( 'updates isAutomaticDataCollectionEnabled synchronously after setAutomaticDataCollectionEnabled' , function ( ) {
104+ const inAppMessaging = getInAppMessaging ( ) ;
105+ expect ( isAutomaticDataCollectionEnabled ( inAppMessaging ) ) . toBe ( false ) ;
106+ setAutomaticDataCollectionEnabled ( inAppMessaging , true ) ;
107+ expect ( isAutomaticDataCollectionEnabled ( inAppMessaging ) ) . toBe ( true ) ;
108+ } ) ;
109+
110+ it ( 'updates isAutomaticDataCollectionEnabled after setAutomaticDataCollectionEnabled resolves' , async function ( ) {
111+ const inAppMessaging = getInAppMessaging ( ) ;
112+ await setAutomaticDataCollectionEnabled ( inAppMessaging , true ) ;
113+ expect ( isAutomaticDataCollectionEnabled ( inAppMessaging ) ) . toBe ( true ) ;
114+ } ) ;
115+ } ) ;
116+
117+ describe ( 'test `console.warn` is called for RNFB v8 API & not called for v9 API' , function ( ) {
118+ let inAppMessagingV9Deprecation : CheckV9DeprecationFunction ;
119+
120+ beforeEach ( function ( ) {
121+ inAppMessagingV9Deprecation = createCheckV9Deprecation ( [ 'inAppMessaging' ] ) ;
122+
123+ // @ts -ignore test
124+ jest . spyOn ( FirebaseModule . prototype , 'native' , 'get' ) . mockImplementation ( ( ) => {
125+ return new Proxy (
126+ { } ,
127+ {
128+ get : ( _target , prop ) => {
129+ if (
130+ prop === 'isMessagesDisplaySuppressed' ||
131+ prop === 'isAutomaticDataCollectionEnabled'
132+ ) {
133+ return false ;
134+ }
135+
136+ return jest . fn ( ) . mockResolvedValue ( null as never ) ;
137+ } ,
138+ } ,
139+ ) ;
140+ } ) ;
141+ } ) ;
142+
143+ it ( 'isMessagesDisplaySuppressed' , function ( ) {
144+ const inAppMessaging = getInAppMessaging ( ) ;
145+ inAppMessagingV9Deprecation (
146+ ( ) => isMessagesDisplaySuppressed ( inAppMessaging ) ,
147+ ( ) => inAppMessaging . isMessagesDisplaySuppressed ,
148+ 'isMessagesDisplaySuppressed' ,
149+ ) ;
150+ } ) ;
151+
152+ it ( 'setMessagesDisplaySuppressed' , function ( ) {
153+ const inAppMessaging = getInAppMessaging ( ) ;
154+ inAppMessagingV9Deprecation (
155+ ( ) => setMessagesDisplaySuppressed ( inAppMessaging , true ) ,
156+ ( ) => inAppMessaging . setMessagesDisplaySuppressed ( true ) ,
157+ 'setMessagesDisplaySuppressed' ,
158+ ) ;
159+ } ) ;
160+
161+ it ( 'isAutomaticDataCollectionEnabled' , function ( ) {
162+ const inAppMessaging = getInAppMessaging ( ) ;
163+ inAppMessagingV9Deprecation (
164+ ( ) => isAutomaticDataCollectionEnabled ( inAppMessaging ) ,
165+ ( ) => inAppMessaging . isAutomaticDataCollectionEnabled ,
166+ 'isAutomaticDataCollectionEnabled' ,
167+ ) ;
168+ } ) ;
169+
170+ it ( 'setAutomaticDataCollectionEnabled' , function ( ) {
171+ const inAppMessaging = getInAppMessaging ( ) ;
172+ inAppMessagingV9Deprecation (
173+ ( ) => setAutomaticDataCollectionEnabled ( inAppMessaging , false ) ,
174+ ( ) => inAppMessaging . setAutomaticDataCollectionEnabled ( false ) ,
175+ 'setAutomaticDataCollectionEnabled' ,
176+ ) ;
177+ } ) ;
178+
179+ it ( 'triggerEvent' , function ( ) {
180+ const inAppMessaging = getInAppMessaging ( ) ;
181+ inAppMessagingV9Deprecation (
182+ ( ) => triggerEvent ( inAppMessaging , 'test-event' ) ,
183+ ( ) => inAppMessaging . triggerEvent ( 'test-event' ) ,
184+ 'triggerEvent' ,
185+ ) ;
186+ } ) ;
55187 } ) ;
56188} ) ;
0 commit comments