Selaa lähdekoodia

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 vuotta sitten
vanhempi
commit
d81b0bf3cf
No account linked to committer's email address

+ 21
- 0
e2e/ExternalComponent.test.js Näytä tiedosto

@@ -20,4 +20,25 @@ describe('External Component', () => {
20 20
     await elementById(TestIDs.MODAL_BTN).tap();
21 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 Näytä tiedosto

@@ -12,9 +12,25 @@
12 12
 }
13 13
 
14 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 36
 - (void)addTestLabel {
@@ -27,4 +43,14 @@
27 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 56
 @end

+ 8
- 1
lib/ios/RNNExternalViewController.m Näytä tiedosto

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

+ 1
- 1
playground/src/components/Root.js Näytä tiedosto

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

+ 7
- 1
playground/src/screens/ExternalComponentScreen.js Näytä tiedosto

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

+ 3
- 2
playground/src/screens/NavigationScreen.js Näytä tiedosto

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

+ 6
- 0
playground/src/testIDs.js Näytä tiedosto

@@ -89,6 +89,7 @@ module.exports = {
89 89
   SEARCH_BTN: 'SEARCH_BTN',
90 90
   SET_STACK_ROOT_BTN: 'SET_STACK_ROOT_BTN',
91 91
   SET_STACK_ROOT_WITH_ID_BTN: 'SET_STACK_ROOT_WITH_ID_BTN',
92
+  NAVIGATION_SCREEN: `NAVIGATION_SCREEN`,
92 93
 
93 94
   // Buttons
94 95
   TAB_BASED_APP_BUTTON: `TAB_BASED_APP_BUTTON`,
@@ -135,7 +136,12 @@ module.exports = {
135 136
   SHOW_LIFECYCLE_BTN: 'SHOW_LIFECYCLE_BTN',
136 137
   CHANGE_BUTTON_PROPS: 'CHANGE_BUTTON_PROPS',
137 138
   GOTO_BUTTONS_SCREEN: 'GOTO_BUTTONS_SCREEN',
139
+  REGISTER_MODAL_DISMISS_EVENT_BTN: 'REGISTER_MODAL_DISMISS_EVENT_BTN',
138 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 146
   // Elements
141 147
   SCROLLVIEW_ELEMENT: `SCROLLVIEW_ELEMENT`,