소스 검색

Add e2e for multiple setRoot (#4993)

Yogev Ben David 5 년 전
부모
커밋
9dafd16a8e
No account linked to committer's email address

+ 16
- 0
e2e/SetRoot.test.js 파일 보기

@@ -0,0 +1,16 @@
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 파일 보기

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

+ 1
- 0
playground/src/screens/Screens.js 파일 보기

@@ -5,6 +5,7 @@ module.exports = {
5 5
   Options: 'Options',
6 6
   Stack: 'Stack',
7 7
   Modal: 'Modal',
8
+  SetRoot: 'SetRoot',
8 9
   Overlay: 'Overlay',
9 10
   OverlayAlert: 'OverlayAlert',
10 11
   ScrollViewOverlay: 'ScrollViewOverlay',

+ 55
- 0
playground/src/screens/SetRootScreen.js 파일 보기

@@ -0,0 +1,55 @@
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 파일 보기

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

+ 1
- 0
playground/src/testIDs.js 파일 보기

@@ -61,6 +61,7 @@ module.exports = {
61 61
   DISMISS_UNKNOWN_MODAL_BTN: 'DISMISS_UNKNOWN_MODAL_BTN',
62 62
   PUSH_TO_TEST_DID_DISAPPEAR_BTN: 'PUSH_TO_TEST_DID_DISAPPEAR_BTN',
63 63
   SET_ROOT_BTN: 'SET_ROOT_BTN',
64
+  SET_MULTIPLE_ROOTS_BTN: 'SET_MULTIPLE_ROOTS_BTN',
64 65
   ADD_BACK_HANDLER: 'ADD_BACK_HANDLER',
65 66
   REMOVE_BACK_HANDLER: 'REMOVE_BACK_HANDLER',
66 67
   OPEN_LEFT_SIDE_MENU_BTN: 'OPEN_LEFT_SIDE_MENU_BTN',