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,6 +21,16 @@ describe('modal', () => {
21 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 34
   it('show multiple modals', async () => {
25 35
     await elementById(testIDs.SHOW_MODAL_BUTTON).tap();
26 36
     await expect(elementByLabel('Modal Stack Position: 1')).toBeVisible();

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

@@ -37,7 +37,9 @@ class LifecycleScreen extends Component {
37 37
         <Text style={styles.h1}>{`Lifecycle Screen`}</Text>
38 38
         <Text style={styles.h1}>{this.state.text}</Text>
39 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 43
         <Text style={styles.footer}>{`this.props.componentId = ${this.props.componentId}`}</Text>
42 44
       </View>
43 45
     );
@@ -50,6 +52,10 @@ class LifecycleScreen extends Component {
50 52
   onClickPop() {
51 53
     Navigation.pop(this.props.componentId);
52 54
   }
55
+
56
+  onClickDismiss() {
57
+    Navigation.dismissModal(this.props.componentId);
58
+  }
53 59
 }
54 60
 module.exports = LifecycleScreen;
55 61
 

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

@@ -26,6 +26,7 @@ class ModalScreen extends Component {
26 26
     this.onClickDismissAllModals = this.onClickDismissAllModals.bind(this);
27 27
     this.onClickPushScreen = this.onClickPushScreen.bind(this);
28 28
     this.onShowModalWithDeepStack = this.onShowModalWithDeepStack.bind(this);
29
+    this.onClickModalLifecycle = this.onClickModalLifecycle.bind(this);
29 30
   }
30 31
 
31 32
   render() {
@@ -37,6 +38,7 @@ class ModalScreen extends Component {
37 38
         <Button title='Dismiss Modal' testID={testIDs.DISMISS_MODAL_BUTTON} onPress={this.onClickDismissModal} />
38 39
         <Button title='Dismiss Unknown Modal' testID={testIDs.DISMISS_UNKNOWN_MODAL_BUTTON} onPress={this.onClickDismissUnknownModal} />
39 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 42
         <Button title='Push screen' testID={testIDs.PUSH_BUTTON} onPress={this.onClickPushScreen} />
41 43
         <Button title='Show Modal With Stack' testID={testIDs.MODAL_WITH_STACK_BUTTON} onPress={this.onShowModalWithDeepStack} />
42 44
         {this.getPreviousModalId() ? (<Button title='Dismiss Previous Modal' testID={testIDs.DISMISS_PREVIOUS_MODAL_BUTTON}
@@ -89,6 +91,20 @@ class ModalScreen extends Component {
89 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 108
   onClickPushScreen() {
93 109
     Navigation.push(this.props.componentId, {
94 110
       component: {

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

@@ -59,6 +59,7 @@ module.exports = {
59 59
   EXTERNAL_COMPONENT_IN_STACK: `EXTERNAL_COMPONENT_IN_STACK`,
60 60
   EXTERNAL_COMPONENT_IN_DEEP_STACK: `EXTERNAL_COMPONENT_IN_DEEP_STACK`,
61 61
   SET_STACK_ROOT_BUTTON: `SET_STACK_ROOT_BUTTON`,
62
+  MODAL_LIFECYCLE_BUTTON: `MODAL_LIFECYCLE_BUTTON`,
62 63
 
63 64
   // Elements
64 65
   SCROLLVIEW_ELEMENT: `SCROLLVIEW_ELEMENT`,