Browse Source

Add e2e for multiple setRoot (#4993)

Yogev Ben David 5 years ago
parent
commit
9dafd16a8e
No account linked to committer's email address

+ 16
- 0
e2e/SetRoot.test.js View File

1
+const Utils = require('./Utils');
2
+const TestIDs = require('../playground/src/testIDs');
3
+const { elementById } = Utils;
4
+
5
+describe('SetRoot', () => {
6
+  beforeEach(async () => {
7
+    await device.relaunchApp();
8
+    await elementById(TestIDs.NAVIGATION_TAB).tap();
9
+    await elementById(TestIDs.SET_ROOT_BTN).tap();
10
+  });
11
+
12
+  it('set root multiple times with the same componentId', async () => {
13
+    await elementById(TestIDs.SET_MULTIPLE_ROOTS_BTN).tap();
14
+    await expect(elementById(TestIDs.PUSHED_SCREEN_HEADER)).toBeVisible();
15
+  });
16
+});

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

9
   EXTERNAL_COMP_BTN,
9
   EXTERNAL_COMP_BTN,
10
   SHOW_STATIC_EVENTS_SCREEN,
10
   SHOW_STATIC_EVENTS_SCREEN,
11
   SHOW_ORIENTATION_SCREEN,
11
   SHOW_ORIENTATION_SCREEN,
12
-  TOP_BAR_ELEMENT
12
+  SET_ROOT_BTN
13
 } = require('../testIDs');
13
 } = require('../testIDs');
14
 const Screens = require('./Screens');
14
 const Screens = require('./Screens');
15
 
15
 
16
-class NavigationScreen extends React.Component {
16
+class NavigationScreen  extends React.Component {
17
   static options() {
17
   static options() {
18
     return {
18
     return {
19
       topBar: {
19
       topBar: {
32
   render() {
32
   render() {
33
     return (
33
     return (
34
       <Root componentId={this.props.componentId}>
34
       <Root componentId={this.props.componentId}>
35
+        <Button label='Set Root' testID={SET_ROOT_BTN} onPress={this.setRoot} />
35
         <Button label='Modal' testID={MODAL_BTN} onPress={this.showModal} />
36
         <Button label='Modal' testID={MODAL_BTN} onPress={this.showModal} />
36
         <Button label='Overlay' testID={OVERLAY_BTN} onPress={this.showOverlay} />
37
         <Button label='Overlay' testID={OVERLAY_BTN} onPress={this.showOverlay} />
37
         <Button label='External Component' testID={EXTERNAL_COMP_BTN} onPress={this.externalComponent} />
38
         <Button label='External Component' testID={EXTERNAL_COMP_BTN} onPress={this.externalComponent} />
45
     );
46
     );
46
   }
47
   }
47
 
48
 
49
+  setRoot = () => Navigation.showModal(Screens.SetRoot);
48
   showModal = () => Navigation.showModal(Screens.Modal);
50
   showModal = () => Navigation.showModal(Screens.Modal);
49
   showOverlay = () => Navigation.showModal(Screens.Overlay);
51
   showOverlay = () => Navigation.showModal(Screens.Overlay);
50
   externalComponent = () => Navigation.showModal(Screens.ExternalComponent);
52
   externalComponent = () => Navigation.showModal(Screens.ExternalComponent);
51
   pushStaticEventsScreen = () => Navigation.showModal(Screens.EventsScreen)
53
   pushStaticEventsScreen = () => Navigation.showModal(Screens.EventsScreen)
52
   orientation = () => Navigation.showModal(Screens.Orientation);
54
   orientation = () => Navigation.showModal(Screens.Orientation);
53
-  preview = ({ reactTag }) => {
55
+  preview = ({reactTag}) => {
54
     Navigation.push(this.props.componentId, {
56
     Navigation.push(this.props.componentId, {
55
       component: {
57
       component: {
56
         name: Screens.Pushed,
58
         name: Screens.Pushed,

+ 1
- 0
playground/src/screens/Screens.js View File

5
   Options: 'Options',
5
   Options: 'Options',
6
   Stack: 'Stack',
6
   Stack: 'Stack',
7
   Modal: 'Modal',
7
   Modal: 'Modal',
8
+  SetRoot: 'SetRoot',
8
   Overlay: 'Overlay',
9
   Overlay: 'Overlay',
9
   OverlayAlert: 'OverlayAlert',
10
   OverlayAlert: 'OverlayAlert',
10
   ScrollViewOverlay: 'ScrollViewOverlay',
11
   ScrollViewOverlay: 'ScrollViewOverlay',

+ 55
- 0
playground/src/screens/SetRootScreen.js View File

1
+const React = require('react');
2
+const Root = require('../components/Root');
3
+const Button = require('../components/Button')
4
+const Navigation = require('./../services/Navigation');
5
+const {
6
+  NAVIGATION_TAB,
7
+  SET_MULTIPLE_ROOTS_BTN
8
+} = require('../testIDs');
9
+const Screens = require('./Screens');
10
+
11
+class SetRootScreen  extends React.Component {
12
+  static options() {
13
+    return {
14
+      topBar: {
15
+        title: {
16
+          text: 'Navigation'
17
+        }
18
+      },
19
+      bottomTab: {
20
+        text: 'Navigation',
21
+        icon: require('../../img/navigation.png'),
22
+        testID: NAVIGATION_TAB
23
+      }
24
+    };
25
+  }
26
+
27
+  render() {
28
+    return (
29
+      <Root componentId={this.props.componentId}>
30
+        <Button label='Set Multiple Roots' testID={SET_MULTIPLE_ROOTS_BTN} onPress={this.setMultipleRoot} />
31
+      </Root>
32
+    );
33
+  }
34
+
35
+  setMultipleRoot = async () => {
36
+    await this.setRoot();
37
+    await this.setRoot();
38
+  };
39
+
40
+  setRoot = async () => await Navigation.setRoot({
41
+    root: {
42
+      stack: {
43
+        id: 'stack',
44
+        children: [{
45
+          component: {
46
+            id: 'component',
47
+            name: Screens.Pushed
48
+          }
49
+        }]
50
+      }
51
+    }
52
+  });
53
+}
54
+
55
+module.exports = SetRootScreen;

+ 1
- 0
playground/src/screens/index.js View File

19
   Navigation.registerComponent(Screens.Stack, () => require('./StackScreen'));
19
   Navigation.registerComponent(Screens.Stack, () => require('./StackScreen'));
20
   Navigation.registerComponent(Screens.Pushed, () => require('./PushedScreen'));
20
   Navigation.registerComponent(Screens.Pushed, () => require('./PushedScreen'));
21
   Navigation.registerComponent(Screens.Modal, () => require('./ModalScreen'))
21
   Navigation.registerComponent(Screens.Modal, () => require('./ModalScreen'))
22
+  Navigation.registerComponent(Screens.SetRoot, () => require('./SetRootScreen'))
22
   Navigation.registerComponent(Screens.Navigation, () => require('./NavigationScreen'));
23
   Navigation.registerComponent(Screens.Navigation, () => require('./NavigationScreen'));
23
   Navigation.registerComponent(Screens.FirstBottomTabsScreen, () => require('./FirstBottomTabScreen'));
24
   Navigation.registerComponent(Screens.FirstBottomTabsScreen, () => require('./FirstBottomTabScreen'));
24
   Navigation.registerComponent(Screens.SecondBottomTabsScreen, () => require('./SecondBottomTabScreen'));
25
   Navigation.registerComponent(Screens.SecondBottomTabsScreen, () => require('./SecondBottomTabScreen'));

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

61
   DISMISS_UNKNOWN_MODAL_BTN: 'DISMISS_UNKNOWN_MODAL_BTN',
61
   DISMISS_UNKNOWN_MODAL_BTN: 'DISMISS_UNKNOWN_MODAL_BTN',
62
   PUSH_TO_TEST_DID_DISAPPEAR_BTN: 'PUSH_TO_TEST_DID_DISAPPEAR_BTN',
62
   PUSH_TO_TEST_DID_DISAPPEAR_BTN: 'PUSH_TO_TEST_DID_DISAPPEAR_BTN',
63
   SET_ROOT_BTN: 'SET_ROOT_BTN',
63
   SET_ROOT_BTN: 'SET_ROOT_BTN',
64
+  SET_MULTIPLE_ROOTS_BTN: 'SET_MULTIPLE_ROOTS_BTN',
64
   ADD_BACK_HANDLER: 'ADD_BACK_HANDLER',
65
   ADD_BACK_HANDLER: 'ADD_BACK_HANDLER',
65
   REMOVE_BACK_HANDLER: 'REMOVE_BACK_HANDLER',
66
   REMOVE_BACK_HANDLER: 'REMOVE_BACK_HANDLER',
66
   OPEN_LEFT_SIDE_MENU_BTN: 'OPEN_LEFT_SIDE_MENU_BTN',
67
   OPEN_LEFT_SIDE_MENU_BTN: 'OPEN_LEFT_SIDE_MENU_BTN',