Browse Source

Added static events e2e

yogevbd 6 years ago
parent
commit
92cbc08e25

+ 20
- 0
e2e/StaticLifecycleEvents.test.js View File

16
     await expect(elementByLabel('componentDidDisappear | navigation.playground.WelcomeScreen')).toBeVisible();
16
     await expect(elementByLabel('componentDidDisappear | navigation.playground.WelcomeScreen')).toBeVisible();
17
   });
17
   });
18
 
18
 
19
+  it('pushing and poping screen dispatch static event', async () => {
20
+    await elementById(testIDs.PUSH_STATIC_LIFECYCLE_BUTTON).tap();
21
+    await expect(elementByLabel('Static Lifecycle Events Overlay')).toBeVisible();
22
+    await expect(elementByLabel('componentDidAppear | navigation.playground.StaticLifecycleOverlay')).toBeVisible();
23
+    await elementById(testIDs.PUSH_BUTTON).tap();
24
+    await expect(elementByLabel('push')).toBeVisible();
25
+    await elementById(testIDs.POP_BUTTON).tap();
26
+    await expect(elementByLabel('pop')).toBeVisible();
27
+  });
28
+
29
+  it('showModal and dismissModal dispatch static event', async () => {
30
+    await elementById(testIDs.PUSH_STATIC_LIFECYCLE_BUTTON).tap();
31
+    await expect(elementByLabel('Static Lifecycle Events Overlay')).toBeVisible();
32
+    await expect(elementByLabel('componentDidAppear | navigation.playground.StaticLifecycleOverlay')).toBeVisible();
33
+    await elementById(testIDs.SHOW_MODAL_BUTTON).tap();
34
+    await expect(elementByLabel('showModal')).toBeVisible();
35
+    await elementById(testIDs.DISMISS_MODAL_BUTTON).tap();
36
+    await expect(elementByLabel('dismissModal')).toBeVisible();
37
+  });
38
+
19
   it(':ios: unmounts when dismissed', async () => {
39
   it(':ios: unmounts when dismissed', async () => {
20
     await elementById(testIDs.PUSH_STATIC_LIFECYCLE_BUTTON).tap();
40
     await elementById(testIDs.PUSH_STATIC_LIFECYCLE_BUTTON).tap();
21
     await expect(elementByLabel('Static Lifecycle Events Overlay')).toBeVisible();
41
     await expect(elementByLabel('Static Lifecycle Events Overlay')).toBeVisible();

+ 7
- 10
lib/ios/RNNCommandsHandler.m View File

127
 			[rootVc registerForPreviewingWithDelegate:(id)rootVc sourceView:elementView];
127
 			[rootVc registerForPreviewingWithDelegate:(id)rootVc sourceView:elementView];
128
 		}
128
 		}
129
 	} else {
129
 	} else {
130
-		[_eventEmitter sendOnNavigationCommand:push params:@{@"componentId": componentId}];
131
 		[_navigationStackManager push:newVc onTop:componentId completion:^{
130
 		[_navigationStackManager push:newVc onTop:componentId completion:^{
132
 			[_eventEmitter sendOnNavigationCommandCompletion:push params:@{@"componentId": componentId}];
131
 			[_eventEmitter sendOnNavigationCommandCompletion:push params:@{@"componentId": componentId}];
133
 			completion();
132
 			completion();
137
 
136
 
138
 -(void)setStackRoot:(NSString*)componentId layout:(NSDictionary*)layout completion:(RNNTransitionCompletionBlock)completion rejection:(RCTPromiseRejectBlock)rejection {
137
 -(void)setStackRoot:(NSString*)componentId layout:(NSDictionary*)layout completion:(RNNTransitionCompletionBlock)completion rejection:(RCTPromiseRejectBlock)rejection {
139
 	[self assertReady];
138
 	[self assertReady];
140
-	[_eventEmitter sendOnNavigationCommand:setStackRoot params:@{@"componentId": componentId}];
141
 	
139
 	
142
 	UIViewController<RNNRootViewProtocol> *newVc = [_controllerFactory createLayoutAndSaveToStore:layout];
140
 	UIViewController<RNNRootViewProtocol> *newVc = [_controllerFactory createLayoutAndSaveToStore:layout];
143
 	__weak typeof(RNNEventEmitter*) weakEventEmitter = _eventEmitter;
141
 	__weak typeof(RNNEventEmitter*) weakEventEmitter = _eventEmitter;
149
 
147
 
150
 -(void)pop:(NSString*)componentId options:(NSDictionary*)options completion:(RNNTransitionCompletionBlock)completion rejection:(RCTPromiseRejectBlock)rejection {
148
 -(void)pop:(NSString*)componentId options:(NSDictionary*)options completion:(RNNTransitionCompletionBlock)completion rejection:(RCTPromiseRejectBlock)rejection {
151
 	[self assertReady];
149
 	[self assertReady];
152
-	[_eventEmitter sendOnNavigationCommand:pop params:@{@"componentId": componentId}];
150
+
153
 	[CATransaction begin];
151
 	[CATransaction begin];
154
 	[CATransaction setCompletionBlock:^{
152
 	[CATransaction setCompletionBlock:^{
155
 		[_eventEmitter sendOnNavigationCommandCompletion:pop params:@{@"componentId": componentId}];
153
 		[_eventEmitter sendOnNavigationCommandCompletion:pop params:@{@"componentId": componentId}];
169
 
167
 
170
 -(void) popTo:(NSString*)componentId completion:(RNNTransitionCompletionBlock)completion rejection:(RCTPromiseRejectBlock)rejection {
168
 -(void) popTo:(NSString*)componentId completion:(RNNTransitionCompletionBlock)completion rejection:(RCTPromiseRejectBlock)rejection {
171
 	[self assertReady];
169
 	[self assertReady];
172
-	[_eventEmitter sendOnNavigationCommand:popTo params:@{@"componentId": componentId}];
173
 	[CATransaction begin];
170
 	[CATransaction begin];
174
 	[CATransaction setCompletionBlock:^{
171
 	[CATransaction setCompletionBlock:^{
175
 		[_eventEmitter sendOnNavigationCommandCompletion:popTo params:@{@"componentId": componentId}];
172
 		[_eventEmitter sendOnNavigationCommandCompletion:popTo params:@{@"componentId": componentId}];
183
 
180
 
184
 -(void) popToRoot:(NSString*)componentId completion:(RNNTransitionCompletionBlock)completion rejection:(RCTPromiseRejectBlock)rejection {
181
 -(void) popToRoot:(NSString*)componentId completion:(RNNTransitionCompletionBlock)completion rejection:(RCTPromiseRejectBlock)rejection {
185
 	[self assertReady];
182
 	[self assertReady];
186
-	[_eventEmitter sendOnNavigationCommand:popToRoot params:@{@"componentId": componentId}];
183
+
187
 	[CATransaction begin];
184
 	[CATransaction begin];
188
 	[CATransaction setCompletionBlock:^{
185
 	[CATransaction setCompletionBlock:^{
189
 		[_eventEmitter sendOnNavigationCommandCompletion:popToRoot params:@{@"componentId": componentId}];
186
 		[_eventEmitter sendOnNavigationCommandCompletion:popToRoot params:@{@"componentId": componentId}];
197
 
194
 
198
 -(void) showModal:(NSDictionary*)layout completion:(RNNTransitionCompletionBlock)completion {
195
 -(void) showModal:(NSDictionary*)layout completion:(RNNTransitionCompletionBlock)completion {
199
 	[self assertReady];
196
 	[self assertReady];
200
-	[_eventEmitter sendOnNavigationCommand:showModal params:@{@"layout": layout}];
197
+
201
 	UIViewController<RNNRootViewProtocol> *newVc = [_controllerFactory createLayoutAndSaveToStore:layout];
198
 	UIViewController<RNNRootViewProtocol> *newVc = [_controllerFactory createLayoutAndSaveToStore:layout];
202
 	[_modalManager showModal:newVc completion:^{
199
 	[_modalManager showModal:newVc completion:^{
203
 		[_eventEmitter sendOnNavigationCommandCompletion:showModal params:@{@"layout": layout}];
200
 		[_eventEmitter sendOnNavigationCommandCompletion:showModal params:@{@"layout": layout}];
207
 
204
 
208
 -(void) dismissModal:(NSString*)componentId completion:(RNNTransitionCompletionBlock)completion {
205
 -(void) dismissModal:(NSString*)componentId completion:(RNNTransitionCompletionBlock)completion {
209
 	[self assertReady];
206
 	[self assertReady];
210
-	[_eventEmitter sendOnNavigationCommand:dismissModal params:@{@"componentId": componentId}];
207
+
211
 	[CATransaction begin];
208
 	[CATransaction begin];
212
 	[CATransaction setCompletionBlock:^{
209
 	[CATransaction setCompletionBlock:^{
213
 		[_eventEmitter sendOnNavigationCommandCompletion:dismissModal params:@{@"componentId": componentId}];
210
 		[_eventEmitter sendOnNavigationCommandCompletion:dismissModal params:@{@"componentId": componentId}];
221
 
218
 
222
 -(void) dismissAllModalsWithCompletion:(RNNTransitionCompletionBlock)completion {
219
 -(void) dismissAllModalsWithCompletion:(RNNTransitionCompletionBlock)completion {
223
 	[self assertReady];
220
 	[self assertReady];
224
-	[_eventEmitter sendOnNavigationCommand:dismissAllModals params:@{}];
221
+
225
 	[CATransaction begin];
222
 	[CATransaction begin];
226
 	[CATransaction setCompletionBlock:^{
223
 	[CATransaction setCompletionBlock:^{
227
 		[_eventEmitter sendOnNavigationCommandCompletion:dismissAllModals params:@{}];
224
 		[_eventEmitter sendOnNavigationCommandCompletion:dismissAllModals params:@{}];
235
 
232
 
236
 -(void)showOverlay:(NSDictionary *)layout completion:(RNNTransitionCompletionBlock)completion {
233
 -(void)showOverlay:(NSDictionary *)layout completion:(RNNTransitionCompletionBlock)completion {
237
 	[self assertReady];
234
 	[self assertReady];
238
-	[_eventEmitter sendOnNavigationCommand:showOverlay params:@{@"layout": layout}];
235
+
239
 	UIViewController<RNNRootViewProtocol>* overlayVC = [_controllerFactory createOverlay:layout];
236
 	UIViewController<RNNRootViewProtocol>* overlayVC = [_controllerFactory createOverlay:layout];
240
 	[_overlayManager showOverlay:overlayVC completion:^{
237
 	[_overlayManager showOverlay:overlayVC completion:^{
241
 		[_eventEmitter sendOnNavigationCommandCompletion:showOverlay params:@{@"layout": layout}];
238
 		[_eventEmitter sendOnNavigationCommandCompletion:showOverlay params:@{@"layout": layout}];
245
 
242
 
246
 - (void)dismissOverlay:(NSString*)componentId completion:(RNNTransitionCompletionBlock)completion {
243
 - (void)dismissOverlay:(NSString*)componentId completion:(RNNTransitionCompletionBlock)completion {
247
 	[self assertReady];
244
 	[self assertReady];
248
-	[_eventEmitter sendOnNavigationCommand:dismissModal params:@{@"componentId": componentId}];
245
+
249
 	[_overlayManager dismissOverlay:componentId completion:^{
246
 	[_overlayManager dismissOverlay:componentId completion:^{
250
 		[_eventEmitter sendOnNavigationCommandCompletion:dismissModal params:@{@"componentId": componentId}];
247
 		[_eventEmitter sendOnNavigationCommandCompletion:dismissModal params:@{@"componentId": componentId}];
251
 		completion();
248
 		completion();

+ 1
- 3
lib/ios/RNNEventEmitter.m View File

45
 }
45
 }
46
 
46
 
47
 -(void)sendOnNavigationCommandCompletion:(NSString *)commandName params:(NSDictionary*)params {
47
 -(void)sendOnNavigationCommandCompletion:(NSString *)commandName params:(NSDictionary*)params {
48
-	NSMutableDictionary* mutableParams = [NSMutableDictionary dictionaryWithDictionary:params];
49
-	[mutableParams setObject:[RNNUtils getCurrentTimestamp] forKey:@"timestamp"];
50
-	[self send:commandComplete body:@{@"name":commandName , @"params": mutableParams}];
48
+	[self send:commandComplete body:@{@"commandId":commandName , @"params": params, @"completionTime": [RNNUtils getCurrentTimestamp] }];
51
 }
49
 }
52
 
50
 
53
 -(void)sendOnNavigationEvent:(NSString *)commandName params:(NSDictionary*)params {
51
 -(void)sendOnNavigationEvent:(NSString *)commandName params:(NSDictionary*)params {

+ 13
- 4
playground/src/screens/StaticLifecycleOverlay.js View File

22
         events: [...this.state.events, { event: 'componentDidDisappear', componentId, componentName }]
22
         events: [...this.state.events, { event: 'componentDidDisappear', componentId, componentName }]
23
       });
23
       });
24
     }));
24
     }));
25
-    this.listeners.push(Navigation.events().registerCommandListener((name, params) => {
26
-      // console.log('RNN', `name: ${JSON.stringify(name)}`);
27
-      // console.log('RNN', `params: ${JSON.stringify(params)}`);
25
+    this.listeners.push(Navigation.events().registerCommandCompletedListener((commandId, completionTime, params) => {
26
+      this.setState({
27
+        events: [...this.state.events, { event: 'commandCompleted', commandId }]
28
+      });
28
     }));
29
     }));
29
   }
30
   }
30
 
31
 
34
     alert('Overlay Unmounted');
35
     alert('Overlay Unmounted');
35
   }
36
   }
36
 
37
 
38
+  renderEvent(event) {
39
+    if (event.commandId) {
40
+      return <Text style={styles.h2}>{`${event.commandId}`}</Text>;
41
+    } else {
42
+      return <Text style={styles.h2}>{`${event.event} | ${event.componentName}`}</Text>;
43
+    }
44
+  }
45
+
37
   render() {
46
   render() {
38
     const events = this.state.events.map((event, idx) =>
47
     const events = this.state.events.map((event, idx) =>
39
       (
48
       (
40
         <View key={`${event.componentId}${idx}`}>
49
         <View key={`${event.componentId}${idx}`}>
41
-          <Text style={styles.h2}>{`${event.event} | ${event.componentName}`}</Text>
50
+          {this.renderEvent(event)}
42
         </View>
51
         </View>
43
       ));
52
       ));
44
     return (
53
     return (