Browse Source

popToRoot api

Daniel Zlotin 7 years ago
parent
commit
acbdc1b9eb

+ 5
- 0
src/adapters/NativeCommandsSender.js View File

25
     return Promise.resolve(targetContainerId);
25
     return Promise.resolve(targetContainerId);
26
   }
26
   }
27
 
27
 
28
+  popToRoot(containerId) {
29
+    this.nativeCommandsModule.popToRoot(containerId);
30
+    return Promise.resolve(containerId);
31
+  }
32
+
28
   showModal(layout) {
33
   showModal(layout) {
29
     this.nativeCommandsModule.showModal(layout);
34
     this.nativeCommandsModule.showModal(layout);
30
     return Promise.resolve(layout);
35
     return Promise.resolve(layout);

+ 7
- 0
src/adapters/NativeCommandsSender.test.js View File

10
       push: jest.fn(),
10
       push: jest.fn(),
11
       pop: jest.fn(),
11
       pop: jest.fn(),
12
       popTo: jest.fn(),
12
       popTo: jest.fn(),
13
+      popToRoot: jest.fn(),
13
       showModal: jest.fn(),
14
       showModal: jest.fn(),
14
       dismissModal: jest.fn(),
15
       dismissModal: jest.fn(),
15
       dismissAllModals: jest.fn()
16
       dismissAllModals: jest.fn()
47
     expect(result).toBeDefined();
48
     expect(result).toBeDefined();
48
   });
49
   });
49
 
50
 
51
+  it('popToRoot', async () => {
52
+    const result = await uut.popToRoot('theContainerId');
53
+    expect(mockNativeModule.popToRoot).toHaveBeenCalledTimes(1);
54
+    expect(result).toBeDefined();
55
+  });
56
+
50
   it('showModal sends to native', async () => {
57
   it('showModal sends to native', async () => {
51
     const result = await uut.showModal({});
58
     const result = await uut.showModal({});
52
     expect(mockNativeModule.showModal).toHaveBeenCalledTimes(1);
59
     expect(mockNativeModule.showModal).toHaveBeenCalledTimes(1);

+ 4
- 0
src/commands/ContainerCommands.js View File

22
   popTo(toContainerId) {
22
   popTo(toContainerId) {
23
     return this.nativeCommandsSender.popTo(this.containerId, toContainerId);
23
     return this.nativeCommandsSender.popTo(this.containerId, toContainerId);
24
   }
24
   }
25
+
26
+  popToRoot() {
27
+    return this.nativeCommandsSender.popToRoot(this.containerId);
28
+  }
25
 }
29
 }

+ 14
- 0
src/commands/ContainerCommands.test.js View File

72
       expect(result).toEqual(containerId);
72
       expect(result).toEqual(containerId);
73
     });
73
     });
74
   });
74
   });
75
+
76
+  describe('popToRoot', () => {
77
+    it('pops all containers to root', () => {
78
+      uut.popToRoot();
79
+      expect(mockCommandsSender.popToRoot).toHaveBeenCalledTimes(1);
80
+      expect(mockCommandsSender.popToRoot).toHaveBeenCalledWith(containerId);
81
+    });
82
+
83
+    it('returns a promise that resolves to targetId', async () => {
84
+      mockCommandsSender.popToRoot.mockReturnValue(Promise.resolve(containerId));
85
+      const result = await uut.popToRoot();
86
+      expect(result).toEqual(containerId);
87
+    });
88
+  });
75
 });
89
 });