Browse Source

popTo api

Daniel Zlotin 7 years ago
parent
commit
490581f29a

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

20
     return Promise.resolve(containerId);
20
     return Promise.resolve(containerId);
21
   }
21
   }
22
 
22
 
23
+  popTo(containerId, targetContainerId) {
24
+    this.nativeCommandsModule.popTo(containerId, targetContainerId);
25
+    return Promise.resolve(targetContainerId);
26
+  }
27
+
23
   showModal(layout) {
28
   showModal(layout) {
24
     this.nativeCommandsModule.showModal(layout);
29
     this.nativeCommandsModule.showModal(layout);
25
     return Promise.resolve(layout);
30
     return Promise.resolve(layout);

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

9
       setRoot: jest.fn(),
9
       setRoot: jest.fn(),
10
       push: jest.fn(),
10
       push: jest.fn(),
11
       pop: jest.fn(),
11
       pop: jest.fn(),
12
+      popTo: jest.fn(),
12
       showModal: jest.fn(),
13
       showModal: jest.fn(),
13
       dismissModal: jest.fn(),
14
       dismissModal: jest.fn(),
14
       dismissAllModals: jest.fn()
15
       dismissAllModals: jest.fn()
40
     expect(result).toBeDefined();
41
     expect(result).toBeDefined();
41
   });
42
   });
42
 
43
 
44
+  it('popTo sends to native with containerId and targetId', async () => {
45
+    const result = await uut.popTo('theContainerId', 'targetId');
46
+    expect(mockNativeModule.popTo).toHaveBeenCalledTimes(1);
47
+    expect(result).toBeDefined();
48
+  });
49
+
43
   it('showModal sends to native', async () => {
50
   it('showModal sends to native', async () => {
44
     const result = await uut.showModal({});
51
     const result = await uut.showModal({});
45
     expect(mockNativeModule.showModal).toHaveBeenCalledTimes(1);
52
     expect(mockNativeModule.showModal).toHaveBeenCalledTimes(1);

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

18
   pop() {
18
   pop() {
19
     return this.nativeCommandsSender.pop(this.containerId);
19
     return this.nativeCommandsSender.pop(this.containerId);
20
   }
20
   }
21
+
22
+  popTo(toContainerId) {
23
+    return this.nativeCommandsSender.popTo(this.containerId, toContainerId);
24
+  }
21
 }
25
 }

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

58
       expect(result).toEqual(containerId);
58
       expect(result).toEqual(containerId);
59
     });
59
     });
60
   });
60
   });
61
+
62
+  describe('popTo', () => {
63
+    it('pops all containers until the passed Id is top', () => {
64
+      uut.popTo('someOtherContainerId');
65
+      expect(mockCommandsSender.popTo).toHaveBeenCalledTimes(1);
66
+      expect(mockCommandsSender.popTo).toHaveBeenCalledWith(containerId, 'someOtherContainerId');
67
+    });
68
+
69
+    it('returns a promise that resolves to targetId', async () => {
70
+      mockCommandsSender.popTo.mockReturnValue(Promise.resolve(containerId));
71
+      const result = await uut.popTo('someOtherContainerId');
72
+      expect(result).toEqual(containerId);
73
+    });
74
+  });
61
 });
75
 });