@@ -48,7 +48,8 @@ void main() {
4848
4949 // events and views in background and then after we come to foreground
5050 // depending on which view is started first after fg, we can have 9 or 10 events
51- expect (eventList.length, anyOf ([9 , 10 ]));
51+ // But for android, we have 11 events or 12 because end view calls are not recorded to the RQ
52+ expect (eventList.length, Platform .isAndroid ? anyOf ([11 , 12 ]) : anyOf ([9 , 10 ]));
5253
5354 for (var entry in requestList.asMap ().entries) {
5455 int index = entry.key;
@@ -64,13 +65,13 @@ void main() {
6465 // when going to bg
6566 if (index == 2 ) {
6667 expect (queryParams['end_session' ]? [0 ], '1' );
67- expect (queryParams['session_duration' ]? [0 ], '2' );
68+ expect (queryParams['session_duration' ]? [0 ], anyOf ([ '2' , '3' ]) );
6869 }
6970 if (index == 1 ) {
7071 var rqEvents = jsonDecode (queryParams['events' ]! [0 ]);
71- expect (rqEvents.length, 7 );
72+ expect (rqEvents.length, Platform .isAndroid ? 6 : 7 );
7273
73- // events nad views at initial fg
74+ // events and views at initial fg
7475 checkEventAndViews (rqEvents, true );
7576 // events and views after going to bg and coming back to fg
7677 checkEventAndViews (
@@ -87,41 +88,60 @@ void main() {
8788
8889void checkEventAndViews (eventArray, isFGEvents) {
8990 if (isFGEvents) {
90- checkEvent (eventArray[0 ], 'E1_FG' , true );
91- checkViewStart (eventArray[1 ], 'V1_FG' , true );
92- checkEvent (eventArray[2 ], 'E2_FG' , true );
93- checkViewStart ((eventArray[3 ]), 'V2_FG' , true );
94- checkEvent ((eventArray[4 ]), 'E3_FG' , true );
91+ int index = 0 ;
92+ if (Platform .isAndroid) {
93+ // in Android 0th element is orientation event
94+ index = 1 ;
95+ expect (eventArray[0 ]['key' ], "[CLY]_orientation" );
96+ }
97+ checkEvent (eventArray[index], 'E1_FG' , true );
98+ checkViewStart (eventArray[index + 1 ], 'V1_FG' , true );
99+ checkEvent (eventArray[index + 2 ], 'E2_FG' , true );
100+ checkViewStart ((eventArray[index + 3 ]), 'V2_FG' , true );
101+ checkEvent ((eventArray[index + 4 ]), 'E3_FG' , true );
95102 // closed in random order
96- try {
97- checkViewEnd ((eventArray[5 ]), 'V2_FG' , true );
98- checkViewEnd ((eventArray[6 ]), 'V1_FG' , true );
99- } catch (e) {
100- checkViewEnd ((eventArray[5 ]), 'V1_FG' , true );
101- checkViewEnd ((eventArray[6 ]), 'V2_FG' , true );
103+ if (! Platform .isAndroid) {
104+ try {
105+ checkViewEnd ((eventArray[5 ]), 'V2_FG' , true );
106+ checkViewEnd ((eventArray[6 ]), 'V1_FG' , true );
107+ } catch (e) {
108+ checkViewEnd ((eventArray[5 ]), 'V1_FG' , true );
109+ checkViewEnd ((eventArray[6 ]), 'V2_FG' , true );
110+ }
102111 }
103112 } else {
104- checkEvent (jsonDecode (eventArray[0 ]), 'E1_BG' , false );
105- checkViewStart (jsonDecode (eventArray[1 ]), 'V1_BG' , false );
106- checkEvent (jsonDecode (eventArray[2 ]), 'E2_BG' , false );
107- checkViewStart (jsonDecode (eventArray[3 ]), 'V2_BG' , false );
108- checkEvent (jsonDecode (eventArray[4 ]), 'E3_BG' , false );
109- expect (jsonDecode (eventArray[5 ])['key' ], '[CLY]_orientation' );
110- checkViewEnd (jsonDecode (eventArray[6 ]), 'V2_BG' , false );
113+ int index = 0 ;
114+ if (Platform .isAndroid) {
115+ try {
116+ checkViewEnd (jsonDecode (eventArray[index]), 'V2_FG' , true );
117+ checkViewEnd (jsonDecode (eventArray[index + 1 ]), 'V1_FG' , true );
118+ } catch (e) {
119+ checkViewEnd (jsonDecode (eventArray[index]), 'V1_FG' , true );
120+ checkViewEnd (jsonDecode (eventArray[index + 1 ]), 'V2_FG' , true );
121+ }
122+ index = 2 ;
123+ }
124+ checkEvent (jsonDecode (eventArray[index]), 'E1_BG' , false );
125+ checkViewStart (jsonDecode (eventArray[index + 1 ]), 'V1_BG' , false );
126+ checkEvent (jsonDecode (eventArray[index + 2 ]), 'E2_BG' , false );
127+ checkViewStart (jsonDecode (eventArray[index + 3 ]), 'V2_BG' , false );
128+ checkEvent (jsonDecode (eventArray[index + 4 ]), 'E3_BG' , false );
129+ expect (jsonDecode (eventArray[index + 5 ])['key' ], '[CLY]_orientation' );
130+ checkViewEnd (jsonDecode (eventArray[index + 6 ]), 'V2_BG' , false );
111131 // this part is random as autoStopped or normal view can start first
112132 try {
113- checkRestartedView (jsonDecode (eventArray[7 ]), 'V2_FG' , true , false );
133+ checkRestartedView (jsonDecode (eventArray[index + 7 ]), 'V2_FG' , true , false );
114134
115- expect (jsonDecode (eventArray[8 ])['segmentation' ]['name' ], 'V2_FG' );
116- expect (jsonDecode (eventArray[8 ])['segmentation' ]['fg_events' ], false );
117- expect (jsonDecode (eventArray[8 ])['segmentation' ]['cly_v' ], isNull);
118- expect (jsonDecode (eventArray[8 ])['segmentation' ]['visit' ], isNull);
119- expect (jsonDecode (eventArray[8 ])['segmentation' ]['cly_pvn' ], cvn_end);
135+ expect (jsonDecode (eventArray[index + 8 ])['segmentation' ]['name' ], 'V2_FG' );
136+ expect (jsonDecode (eventArray[index + 8 ])['segmentation' ]['fg_events' ], false );
137+ expect (jsonDecode (eventArray[index + 8 ])['segmentation' ]['cly_v' ], isNull);
138+ expect (jsonDecode (eventArray[index + 8 ])['segmentation' ]['visit' ], isNull);
139+ expect (jsonDecode (eventArray[index + 8 ])['segmentation' ]['cly_pvn' ], cvn_end);
120140
121- checkRestartedView (jsonDecode (eventArray[9 ]), 'V1_FG' , true , false );
141+ checkRestartedView (jsonDecode (eventArray[index + 9 ]), 'V1_FG' , true , false );
122142 } catch (e) {
123- checkRestartedView (jsonDecode (eventArray[7 ]), 'V1_FG' , true , false );
124- checkRestartedView (jsonDecode (eventArray[8 ]), 'V2_FG' , true , false );
143+ checkRestartedView (jsonDecode (eventArray[index + 7 ]), 'V1_FG' , true , false );
144+ checkRestartedView (jsonDecode (eventArray[index + 8 ]), 'V2_FG' , true , false );
125145 }
126146 }
127147}
@@ -138,7 +158,7 @@ void checkViewStart(view, name, isVisible) {
138158 expect (view['segmentation' ]['name' ], name);
139159 expect (view['segmentation' ]['fg_events' ], isVisible);
140160 expect (view['segmentation' ]['cly_v' ], isVisible ? 1 : 0 );
141- expect (view['segmentation' ]['visit' ], 1 );
161+ expect (view['segmentation' ]['visit' ], Platform .isAndroid ? '1' : 1 );
142162 expect (view['segmentation' ]['cly_pvn' ], cvn);
143163 cvn_end = cvn;
144164 cvn = name;
@@ -156,7 +176,7 @@ void checkRestartedView(view, name, isVisible, globalSegmentation) {
156176 expect (view['segmentation' ]['name' ], name);
157177 expect (view['segmentation' ]['fg_events' ], globalSegmentation);
158178 expect (view['segmentation' ]['cly_v' ], isVisible ? 1 : 0 );
159- expect (view['segmentation' ]['visit' ], 1 );
179+ expect (view['segmentation' ]['visit' ], Platform .isAndroid ? '1' : 1 );
160180 expect (view['segmentation' ]['cly_pvn' ], cvn);
161181 cvn_end = cvn;
162182 cvn = name;
0 commit comments