Browse Source

Modal unmount e2e test (#3215)

* Update docs

Outdated onAppLaunched part is changed

I just started to a project with v2 and I realized this part of the documentation was wrong. I searched a bit and find this 2 commits: 

104e3f97fd

1d2680c5aa

So, that part is probably forgotten

* Modal unmount e2e test

* Modal unmount e2e test changes.
Yusuf YILDIRIM 6 years ago
parent
commit
81a9cef310

+ 10
- 0
e2e/Modals.test.js View File

21
     await expect(elementById(testIDs.WELCOME_SCREEN_HEADER)).toBeVisible();
21
     await expect(elementById(testIDs.WELCOME_SCREEN_HEADER)).toBeVisible();
22
   });
22
   });
23
 
23
 
24
+  it(':android: unmount modal when dismissed', async () => {
25
+    await elementById(testIDs.SHOW_MODAL_BUTTON).tap();
26
+    await expect(elementById(testIDs.MODAL_SCREEN)).toBeVisible();
27
+    await elementById(testIDs.MODAL_LIFECYCLE_BUTTON).tap();
28
+    await expect(elementByLabel('didAppear')).toBeVisible();
29
+    await elementById(testIDs.DISMISS_MODAL_BUTTON).tap();
30
+    await expect(elementByLabel('componentWillUnmount')).toBeVisible();
31
+    await elementByLabel('OK').atIndex(0).tap();
32
+  });
33
+
24
   it('show multiple modals', async () => {
34
   it('show multiple modals', async () => {
25
     await elementById(testIDs.SHOW_MODAL_BUTTON).tap();
35
     await elementById(testIDs.SHOW_MODAL_BUTTON).tap();
26
     await expect(elementByLabel('Modal Stack Position: 1')).toBeVisible();
36
     await expect(elementByLabel('Modal Stack Position: 1')).toBeVisible();

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

37
         <Text style={styles.h1}>{`Lifecycle Screen`}</Text>
37
         <Text style={styles.h1}>{`Lifecycle Screen`}</Text>
38
         <Text style={styles.h1}>{this.state.text}</Text>
38
         <Text style={styles.h1}>{this.state.text}</Text>
39
         <Button title='Push to test didDisappear' testID={testIDs.PUSH_TO_TEST_DID_DISAPPEAR_BUTTON} onPress={this.onClickPush} />
39
         <Button title='Push to test didDisappear' testID={testIDs.PUSH_TO_TEST_DID_DISAPPEAR_BUTTON} onPress={this.onClickPush} />
40
-        <Button title='Pop' testID={testIDs.POP_BUTTON} onPress={() => this.onClickPop()} />
40
+        {this.props.isModal ?
41
+          (<Button title='Dismiss' testID={testIDs.DISMISS_MODAL_BUTTON} onPress={() => this.onClickDismiss()} />)
42
+          : (<Button title='Pop' testID={testIDs.POP_BUTTON} onPress={() => this.onClickPop()} />)}
41
         <Text style={styles.footer}>{`this.props.componentId = ${this.props.componentId}`}</Text>
43
         <Text style={styles.footer}>{`this.props.componentId = ${this.props.componentId}`}</Text>
42
       </View>
44
       </View>
43
     );
45
     );
50
   onClickPop() {
52
   onClickPop() {
51
     Navigation.pop(this.props.componentId);
53
     Navigation.pop(this.props.componentId);
52
   }
54
   }
55
+
56
+  onClickDismiss() {
57
+    Navigation.dismissModal(this.props.componentId);
58
+  }
53
 }
59
 }
54
 module.exports = LifecycleScreen;
60
 module.exports = LifecycleScreen;
55
 
61
 

+ 16
- 0
playground/src/screens/ModalScreen.js View File

26
     this.onClickDismissAllModals = this.onClickDismissAllModals.bind(this);
26
     this.onClickDismissAllModals = this.onClickDismissAllModals.bind(this);
27
     this.onClickPushScreen = this.onClickPushScreen.bind(this);
27
     this.onClickPushScreen = this.onClickPushScreen.bind(this);
28
     this.onShowModalWithDeepStack = this.onShowModalWithDeepStack.bind(this);
28
     this.onShowModalWithDeepStack = this.onShowModalWithDeepStack.bind(this);
29
+    this.onClickModalLifecycle = this.onClickModalLifecycle.bind(this);
29
   }
30
   }
30
 
31
 
31
   render() {
32
   render() {
37
         <Button title='Dismiss Modal' testID={testIDs.DISMISS_MODAL_BUTTON} onPress={this.onClickDismissModal} />
38
         <Button title='Dismiss Modal' testID={testIDs.DISMISS_MODAL_BUTTON} onPress={this.onClickDismissModal} />
38
         <Button title='Dismiss Unknown Modal' testID={testIDs.DISMISS_UNKNOWN_MODAL_BUTTON} onPress={this.onClickDismissUnknownModal} />
39
         <Button title='Dismiss Unknown Modal' testID={testIDs.DISMISS_UNKNOWN_MODAL_BUTTON} onPress={this.onClickDismissUnknownModal} />
39
         <Button title='Dismiss All Modals' testID={testIDs.DISMISS_ALL_MODALS_BUTTON} onPress={this.onClickDismissAllModals} />
40
         <Button title='Dismiss All Modals' testID={testIDs.DISMISS_ALL_MODALS_BUTTON} onPress={this.onClickDismissAllModals} />
41
+        <Button title='Test Modal Lifecycle' testID={testIDs.MODAL_LIFECYCLE_BUTTON} onPress={this.onClickModalLifecycle} />
40
         <Button title='Push screen' testID={testIDs.PUSH_BUTTON} onPress={this.onClickPushScreen} />
42
         <Button title='Push screen' testID={testIDs.PUSH_BUTTON} onPress={this.onClickPushScreen} />
41
         <Button title='Show Modal With Stack' testID={testIDs.MODAL_WITH_STACK_BUTTON} onPress={this.onShowModalWithDeepStack} />
43
         <Button title='Show Modal With Stack' testID={testIDs.MODAL_WITH_STACK_BUTTON} onPress={this.onShowModalWithDeepStack} />
42
         {this.getPreviousModalId() ? (<Button title='Dismiss Previous Modal' testID={testIDs.DISMISS_PREVIOUS_MODAL_BUTTON}
44
         {this.getPreviousModalId() ? (<Button title='Dismiss Previous Modal' testID={testIDs.DISMISS_PREVIOUS_MODAL_BUTTON}
89
     Navigation.dismissAllModals();
91
     Navigation.dismissAllModals();
90
   }
92
   }
91
 
93
 
94
+  onClickModalLifecycle() {
95
+    Navigation.showModal({
96
+      component: {
97
+        name: 'navigation.playground.LifecycleScreen',
98
+        passProps: {
99
+          isModal: true,
100
+        },
101
+        options: {
102
+          animated: false
103
+        }
104
+      }
105
+    });
106
+  }
107
+
92
   onClickPushScreen() {
108
   onClickPushScreen() {
93
     Navigation.push(this.props.componentId, {
109
     Navigation.push(this.props.componentId, {
94
       component: {
110
       component: {

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

59
   EXTERNAL_COMPONENT_IN_STACK: `EXTERNAL_COMPONENT_IN_STACK`,
59
   EXTERNAL_COMPONENT_IN_STACK: `EXTERNAL_COMPONENT_IN_STACK`,
60
   EXTERNAL_COMPONENT_IN_DEEP_STACK: `EXTERNAL_COMPONENT_IN_DEEP_STACK`,
60
   EXTERNAL_COMPONENT_IN_DEEP_STACK: `EXTERNAL_COMPONENT_IN_DEEP_STACK`,
61
   SET_STACK_ROOT_BUTTON: `SET_STACK_ROOT_BUTTON`,
61
   SET_STACK_ROOT_BUTTON: `SET_STACK_ROOT_BUTTON`,
62
+  MODAL_LIFECYCLE_BUTTON: `MODAL_LIFECYCLE_BUTTON`,
62
 
63
 
63
   // Elements
64
   // Elements
64
   SCROLLVIEW_ELEMENT: `SCROLLVIEW_ELEMENT`,
65
   SCROLLVIEW_ELEMENT: `SCROLLVIEW_ELEMENT`,