Преглед изворни кода

added Navigation.dismissAllModals

Daniel Zlotin пре 7 година
родитељ
комит
1e7fa711a5

+ 12
- 8
playground/e2e/app.test.js Прегледај датотеку

@@ -61,7 +61,7 @@ describe('app', () => {
61 61
     elementByLabel('Dismiss Modal').tap();
62 62
     expect(elementByLabel('React Native Navigation!')).toBeVisible();
63 63
   });
64
-  
64
+
65 65
   it('dismiss unknown screen id', () => {
66 66
     elementByLabel('Show Modal').tap();
67 67
     expect(elementByLabel('Modal Stack Position: 1')).toBeVisible();
@@ -81,7 +81,7 @@ describe('app', () => {
81 81
     elementByLabel('Dismiss Modal').tap();
82 82
     expect(elementByLabel('React Native Navigation!')).toBeVisible();
83 83
   });
84
-  
84
+
85 85
   it('dismiss all previous modals by id when they are below top presented modal', () => {
86 86
     elementByLabel('Show Modal').tap();
87 87
     expect(elementByLabel('Modal Stack Position: 1')).toBeVisible();
@@ -89,14 +89,14 @@ describe('app', () => {
89 89
     expect(elementByLabel('Modal Stack Position: 2')).toBeVisible();
90 90
     elementByLabel('Show Modal').tap();
91 91
     expect(elementByLabel('Modal Stack Position: 3')).toBeVisible();
92
-    
92
+
93 93
     elementByLabel('Dismiss ALL Previous Modals').tap();
94 94
     expect(elementByLabel('Modal Stack Position: 3')).toBeVisible();
95
-    
95
+
96 96
     elementByLabel('Dismiss Modal').tap();
97 97
     expect(elementByLabel('React Native Navigation!')).toBeVisible();
98 98
   });
99
-  
99
+
100 100
   it('dismiss some modal by id deep in the stack', () => {
101 101
     elementByLabel('Show Modal').tap();
102 102
     expect(elementByLabel('Modal Stack Position: 1')).toBeVisible();
@@ -104,16 +104,20 @@ describe('app', () => {
104 104
     expect(elementByLabel('Modal Stack Position: 2')).toBeVisible();
105 105
     elementByLabel('Show Modal').tap();
106 106
     expect(elementByLabel('Modal Stack Position: 3')).toBeVisible();
107
-  
107
+
108 108
     elementByLabel('Dismiss First In Stack').tap();
109 109
     expect(elementByLabel('Modal Stack Position: 3')).toBeVisible();
110
-    
110
+
111 111
     elementByLabel('Dismiss Modal').tap();
112 112
     expect(elementByLabel('Modal Stack Position: 2')).toBeVisible();
113
-    
113
+
114 114
     elementByLabel('Dismiss Modal').tap();
115 115
     expect(elementByLabel('React Native Navigation!')).toBeVisible();
116 116
   });
117
+
118
+  xit('dismissAllModals', () => {
119
+    //
120
+  });
117 121
 });
118 122
 
119 123
 describe('reload app', () => {

+ 4
- 0
src/Navigation.js Прегледај датотеку

@@ -42,6 +42,10 @@ class Navigation {
42 42
     return this.appCommands.dismissModal(id);
43 43
   }
44 44
 
45
+  dismissAllModals() {
46
+    return this.appCommands.dismissAllModals();
47
+  }
48
+
45 49
   events() {
46 50
     return this.publicEventsRegistry;
47 51
   }

+ 7
- 0
src/Navigation.test.js Прегледај датотеку

@@ -62,4 +62,11 @@ describe('Navigation', () => {
62 62
   it('starts listening and handles internal events', () => {
63 63
     expect(Navigation.nativeEventsReceiver.containerStart).toHaveBeenCalledTimes(1);
64 64
   });
65
+
66
+  it('dismissAllModals', async () => {
67
+    Navigation.appCommands.dismissAllModals.mockReturnValue(Promise.resolve('result'));
68
+    const result = await Navigation.dismissAllModals();
69
+    expect(Navigation.appCommands.dismissAllModals).toHaveBeenCalledTimes(1);
70
+    expect(result).toEqual('result');
71
+  });
65 72
 });

+ 5
- 0
src/adapters/NativeCommandsSender.js Прегледај датотеку

@@ -29,5 +29,10 @@ export default class NativeCommandsSender {
29 29
     this.nativeCommandsModule.dismissModal(id);
30 30
     return Promise.resolve(id);
31 31
   }
32
+
33
+  dismissAllModals() {
34
+    this.nativeCommandsModule.dismissAllModals();
35
+    return Promise.resolve(true);
36
+  }
32 37
 }
33 38
 

+ 8
- 1
src/adapters/NativeCommandsSender.test.js Прегледај датотеку

@@ -10,7 +10,8 @@ describe('NativeCommandsSender', () => {
10 10
       push: jest.fn(),
11 11
       pop: jest.fn(),
12 12
       showModal: jest.fn(),
13
-      dismissModal: jest.fn()
13
+      dismissModal: jest.fn(),
14
+      dismissAllModals: jest.fn()
14 15
     };
15 16
     NativeModules.RNNBridgeModule = mockNativeModule;
16 17
     uut = new NativeCommandsSender();
@@ -50,4 +51,10 @@ describe('NativeCommandsSender', () => {
50 51
     expect(mockNativeModule.dismissModal).toHaveBeenCalledTimes(1);
51 52
     expect(result).toEqual('id');
52 53
   });
54
+
55
+  it('dismissAllModals', async () => {
56
+    const result = await uut.dismissAllModals();
57
+    expect(mockNativeModule.dismissAllModals).toHaveBeenCalledTimes(1);
58
+    expect(result).toBe(true);
59
+  });
53 60
 });

+ 4
- 0
src/commands/AppCommands.js Прегледај датотеку

@@ -24,5 +24,9 @@ export default class AppCommands {
24 24
   dismissModal(id) {
25 25
     return this.nativeCommandsSender.dismissModal(id);
26 26
   }
27
+
28
+  dismissAllModals() {
29
+    return this.nativeCommandsSender.dismissAllModals();
30
+  }
27 31
 }
28 32
 

+ 14
- 0
src/commands/AppCommands.test.js Прегледај датотеку

@@ -114,4 +114,18 @@ describe('AppCommands', () => {
114 114
       expect(result).toEqual('the id');
115 115
     });
116 116
   });
117
+
118
+  describe('dismissAllModals', () => {
119
+    it('sends command to native', () => {
120
+      uut.dismissAllModals();
121
+      expect(mockCommandsSender.dismissAllModals).toHaveBeenCalledTimes(1);
122
+      expect(mockCommandsSender.dismissAllModals).toHaveBeenCalledWith();
123
+    });
124
+
125
+    it('returns a promise with the id', async () => {
126
+      mockCommandsSender.dismissAllModals.mockReturnValue(Promise.resolve('the id'));
127
+      const result = await uut.dismissAllModals();
128
+      expect(result).toEqual('the id');
129
+    });
130
+  });
117 131
 });