Browse Source

Add external components e2e, resolve navigationItem from external component (#5861)

* Add external components e2e, resolve navigationItem from external component

* Update ExternalComponent.test.js

* Update ExternalComponent.test.js

* Fix lint
Yogev Ben David 4 years ago
parent
commit
d81b0bf3cf
No account linked to committer's email address

+ 21
- 0
e2e/ExternalComponent.test.js View File

20
     await elementById(TestIDs.MODAL_BTN).tap();
20
     await elementById(TestIDs.MODAL_BTN).tap();
21
     await expect(elementByLabel('External component in deep stack')).toBeVisible();
21
     await expect(elementByLabel('External component in deep stack')).toBeVisible();
22
   });
22
   });
23
+
24
+  test(':ios: Dismiss modal from external component should not crash', async () => {
25
+    await elementById(TestIDs.PUSH_BTN).tap();
26
+    await expect(elementByLabel('This is an external component')).toBeVisible();
27
+    await elementById(TestIDs.EXTERNAL_DISMISS_MODAL_BTN).tap();
28
+    await expect(elementById(TestIDs.NAVIGATION_SCREEN)).toBeVisible();
29
+  });
30
+
31
+  test(':ios: Top bar buttons should be visible', async () => {
32
+    await elementById(TestIDs.PUSH_BTN).tap();
33
+    await expect(elementByLabel('This is an external component')).toBeVisible();
34
+    await expect(elementById(TestIDs.EXTERNAL_TOP_BAR_RIGHT_BTN)).toBeVisible();
35
+  });
36
+
37
+  test(':ios: Dismiss modal from external component should not crash when registered to modalDismissed event', async () => {
38
+    await elementById(TestIDs.REGISTER_MODAL_DISMISS_EVENT_BTN).tap();
39
+    await elementById(TestIDs.PUSH_BTN).tap();
40
+    await expect(elementByLabel('This is an external component')).toBeVisible();
41
+    await elementById(TestIDs.EXTERNAL_DISMISS_MODAL_BTN).tap();
42
+    await expect(elementById(TestIDs.NAVIGATION_SCREEN)).toBeVisible();
43
+  });
23
 });
44
 });

+ 29
- 3
lib/ios/RNNCustomViewController.m View File

12
 }
12
 }
13
 
13
 
14
 - (void)viewDidLoad {
14
 - (void)viewDidLoad {
15
-    [super viewDidLoad];
16
-    [self addTestLabel];
17
-    [[self view] setBackgroundColor:UIColor.whiteColor];
15
+	[super viewDidLoad];
16
+	[self addTestLabel];
17
+	[self addDismissModalButton];
18
+	[self addNavigationBarButtons];
19
+	
20
+	[[self view] setBackgroundColor:UIColor.whiteColor];
21
+}
22
+
23
+- (void)dismissModal {
24
+	[self dismissViewControllerAnimated:YES completion:nil];
25
+}
26
+
27
+- (void)addDismissModalButton {
28
+	UIButton* dismissModalButton = [[UIButton alloc] initWithFrame:CGRectMake(self.view.center.x - 70, 300, 140, 50)];
29
+	dismissModalButton.backgroundColor = UIColor.systemBlueColor;
30
+	dismissModalButton.accessibilityIdentifier = @"EXTERNAL_DISMISS_MODAL_BTN";
31
+	[dismissModalButton setTitle:@"Dismiss modal" forState:UIControlStateNormal];
32
+	[dismissModalButton addTarget:self action:@selector(dismissModal) forControlEvents:UIControlEventTouchDown];
33
+	[self.view addSubview:dismissModalButton];
18
 }
34
 }
19
 
35
 
20
 - (void)addTestLabel {
36
 - (void)addTestLabel {
27
 	[self.view addSubview:label];
43
 	[self.view addSubview:label];
28
 }
44
 }
29
 
45
 
46
+- (void)addNavigationBarButtons {
47
+	UIBarButtonItem* rightButton = [[UIBarButtonItem alloc] initWithTitle:@"Right button" style:UIBarButtonItemStylePlain target:self action:@selector(rightButtonPressed)];
48
+	rightButton.accessibilityIdentifier = @"EXTERNAL_TOP_BAR_RIGHT_BTN";
49
+	self.navigationItem.rightBarButtonItem = rightButton;
50
+}
51
+
52
+- (void)rightButtonPressed {
53
+	
54
+}
55
+
30
 @end
56
 @end

+ 8
- 1
lib/ios/RNNExternalViewController.m View File

1
 #import "RNNExternalViewController.h"
1
 #import "RNNExternalViewController.h"
2
 
2
 
3
-@implementation RNNExternalViewController
3
+@implementation RNNExternalViewController {
4
+    UIViewController* _boundViewController;
5
+}
4
 
6
 
5
 - (instancetype)initWithLayoutInfo:(RNNLayoutInfo *)layoutInfo eventEmitter:(RNNEventEmitter *)eventEmitter presenter:(RNNComponentPresenter *)presenter options:(RNNNavigationOptions *)options defaultOptions:(RNNNavigationOptions *)defaultOptions viewController:(UIViewController *)viewController {
7
 - (instancetype)initWithLayoutInfo:(RNNLayoutInfo *)layoutInfo eventEmitter:(RNNEventEmitter *)eventEmitter presenter:(RNNComponentPresenter *)presenter options:(RNNNavigationOptions *)options defaultOptions:(RNNNavigationOptions *)defaultOptions viewController:(UIViewController *)viewController {
6
 	self = [super initWithLayoutInfo:layoutInfo rootViewCreator:nil eventEmitter:eventEmitter presenter:presenter options:options defaultOptions:defaultOptions];
8
 	self = [super initWithLayoutInfo:layoutInfo rootViewCreator:nil eventEmitter:eventEmitter presenter:presenter options:options defaultOptions:defaultOptions];
9
 }
11
 }
10
 
12
 
11
 - (void)bindViewController:(UIViewController *)viewController {
13
 - (void)bindViewController:(UIViewController *)viewController {
14
+    _boundViewController = viewController;
12
     [self addChildViewController:viewController];
15
     [self addChildViewController:viewController];
13
     [self.view addSubview:viewController.view];
16
     [self.view addSubview:viewController.view];
14
     [viewController didMoveToParentViewController:self];
17
     [viewController didMoveToParentViewController:self];
15
 }
18
 }
16
 
19
 
20
+- (UINavigationItem *)navigationItem {
21
+    return _boundViewController.navigationItem;
22
+}
23
+
17
 - (void)loadView {
24
 - (void)loadView {
18
 	self.view = [UIView new];
25
 	self.view = [UIView new];
19
 }
26
 }

+ 1
- 1
playground/src/components/Root.js View File

5
 const { showTextInputToTestKeyboardInteraction } = require('../flags');
5
 const { showTextInputToTestKeyboardInteraction } = require('../flags');
6
 
6
 
7
 module.exports = (props) =>
7
 module.exports = (props) =>
8
-  <SafeAreaView style={styles.root}>
8
+  <SafeAreaView style={styles.root} testID={props.testID}>
9
     <ScrollView contentContainerStyle={[styles.scrollView, props.style]}>
9
     <ScrollView contentContainerStyle={[styles.scrollView, props.style]}>
10
       {props.children}
10
       {props.children}
11
       {renderFooter(props)}
11
       {renderFooter(props)}

+ 7
- 1
playground/src/screens/ExternalComponentScreen.js View File

6
 const { stack } = require('../commons/Layouts');
6
 const { stack } = require('../commons/Layouts');
7
 const {
7
 const {
8
   PUSH_BTN,
8
   PUSH_BTN,
9
-  MODAL_BTN
9
+  MODAL_BTN,
10
+  REGISTER_MODAL_DISMISS_EVENT_BTN
10
 } = require('../testIDs');
11
 } = require('../testIDs');
11
 
12
 
12
 class ExternalComponentScreen extends React.Component {
13
 class ExternalComponentScreen extends React.Component {
25
       <Root componentId={this.props.componentId}>
26
       <Root componentId={this.props.componentId}>
26
         <Button label='Push' testID={PUSH_BTN} onPress={this.push} />
27
         <Button label='Push' testID={PUSH_BTN} onPress={this.push} />
27
         <Button label='Show Modal' testID={MODAL_BTN} onPress={this.modal} />
28
         <Button label='Show Modal' testID={MODAL_BTN} onPress={this.modal} />
29
+        <Button label='Register modal dismiss event' testID={REGISTER_MODAL_DISMISS_EVENT_BTN} onPress={this.registerModalDismissEvent} />
28
       </Root>
30
       </Root>
29
     );
31
     );
30
   }
32
   }
31
 
33
 
34
+  registerModalDismissEvent = () => Navigation.events().registerModalDismissedListener(() => {
35
+    
36
+  });
37
+
32
   push = () => Navigation.push(this, {
38
   push = () => Navigation.push(this, {
33
     externalComponent: {
39
     externalComponent: {
34
       name: Screens.NativeScreen,
40
       name: Screens.NativeScreen,

+ 3
- 2
playground/src/screens/NavigationScreen.js View File

11
   SHOW_STATIC_EVENTS_SCREEN,
11
   SHOW_STATIC_EVENTS_SCREEN,
12
   SHOW_ORIENTATION_SCREEN,
12
   SHOW_ORIENTATION_SCREEN,
13
   SET_ROOT_BTN,
13
   SET_ROOT_BTN,
14
-  PAGE_SHEET_MODAL_BTN
14
+  PAGE_SHEET_MODAL_BTN,
15
+  NAVIGATION_SCREEN
15
 } = require('../testIDs');
16
 } = require('../testIDs');
16
 const Screens = require('./Screens');
17
 const Screens = require('./Screens');
17
 
18
 
33
 
34
 
34
   render() {
35
   render() {
35
     return (
36
     return (
36
-      <Root componentId={this.props.componentId}>
37
+      <Root componentId={this.props.componentId} testID={NAVIGATION_SCREEN}>
37
         <Button label='Set Root' testID={SET_ROOT_BTN} onPress={this.setRoot} />
38
         <Button label='Set Root' testID={SET_ROOT_BTN} onPress={this.setRoot} />
38
         <Button label='Modal' testID={MODAL_BTN} onPress={this.showModal} />
39
         <Button label='Modal' testID={MODAL_BTN} onPress={this.showModal} />
39
         {Platform.OS === 'ios' && <Button label='PageSheet modal' testID={PAGE_SHEET_MODAL_BTN} onPress={this.showPageSheetModal} />}
40
         {Platform.OS === 'ios' && <Button label='PageSheet modal' testID={PAGE_SHEET_MODAL_BTN} onPress={this.showPageSheetModal} />}

+ 6
- 0
playground/src/testIDs.js View File

89
   SEARCH_BTN: 'SEARCH_BTN',
89
   SEARCH_BTN: 'SEARCH_BTN',
90
   SET_STACK_ROOT_BTN: 'SET_STACK_ROOT_BTN',
90
   SET_STACK_ROOT_BTN: 'SET_STACK_ROOT_BTN',
91
   SET_STACK_ROOT_WITH_ID_BTN: 'SET_STACK_ROOT_WITH_ID_BTN',
91
   SET_STACK_ROOT_WITH_ID_BTN: 'SET_STACK_ROOT_WITH_ID_BTN',
92
+  NAVIGATION_SCREEN: `NAVIGATION_SCREEN`,
92
 
93
 
93
   // Buttons
94
   // Buttons
94
   TAB_BASED_APP_BUTTON: `TAB_BASED_APP_BUTTON`,
95
   TAB_BASED_APP_BUTTON: `TAB_BASED_APP_BUTTON`,
135
   SHOW_LIFECYCLE_BTN: 'SHOW_LIFECYCLE_BTN',
136
   SHOW_LIFECYCLE_BTN: 'SHOW_LIFECYCLE_BTN',
136
   CHANGE_BUTTON_PROPS: 'CHANGE_BUTTON_PROPS',
137
   CHANGE_BUTTON_PROPS: 'CHANGE_BUTTON_PROPS',
137
   GOTO_BUTTONS_SCREEN: 'GOTO_BUTTONS_SCREEN',
138
   GOTO_BUTTONS_SCREEN: 'GOTO_BUTTONS_SCREEN',
139
+  REGISTER_MODAL_DISMISS_EVENT_BTN: 'REGISTER_MODAL_DISMISS_EVENT_BTN',
138
   HIDE_PREVIOUS_SCREEN_TOP_BAR: 'HIDE_PREVIOUS_SCREEN_TOP_BAR',
140
   HIDE_PREVIOUS_SCREEN_TOP_BAR: 'HIDE_PREVIOUS_SCREEN_TOP_BAR',
141
+  
142
+  //External Component Buttons
143
+  EXTERNAL_DISMISS_MODAL_BTN: 'EXTERNAL_DISMISS_MODAL_BTN',
144
+  EXTERNAL_TOP_BAR_RIGHT_BTN: 'EXTERNAL_TOP_BAR_RIGHT_BTN',
139
 
145
 
140
   // Elements
146
   // Elements
141
   SCROLLVIEW_ELEMENT: `SCROLLVIEW_ELEMENT`,
147
   SCROLLVIEW_ELEMENT: `SCROLLVIEW_ELEMENT`,