Daniel Zlotin hace 7 años
padre
commit
490581f29a

+ 5
- 0
src/adapters/NativeCommandsSender.js Ver fichero

@@ -20,6 +20,11 @@ export default class NativeCommandsSender {
20 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 28
   showModal(layout) {
24 29
     this.nativeCommandsModule.showModal(layout);
25 30
     return Promise.resolve(layout);

+ 7
- 0
src/adapters/NativeCommandsSender.test.js Ver fichero

@@ -9,6 +9,7 @@ describe('NativeCommandsSender', () => {
9 9
       setRoot: jest.fn(),
10 10
       push: jest.fn(),
11 11
       pop: jest.fn(),
12
+      popTo: jest.fn(),
12 13
       showModal: jest.fn(),
13 14
       dismissModal: jest.fn(),
14 15
       dismissAllModals: jest.fn()
@@ -40,6 +41,12 @@ describe('NativeCommandsSender', () => {
40 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 50
   it('showModal sends to native', async () => {
44 51
     const result = await uut.showModal({});
45 52
     expect(mockNativeModule.showModal).toHaveBeenCalledTimes(1);

+ 4
- 0
src/commands/ContainerCommands.js Ver fichero

@@ -18,4 +18,8 @@ export default class ContainerCommands {
18 18
   pop() {
19 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 Ver fichero

@@ -58,4 +58,18 @@ describe('ContainerCommands', () => {
58 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
 });