Browse Source

popToRoot api

Daniel Zlotin 7 years ago
parent
commit
acbdc1b9eb

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

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

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

@@ -10,6 +10,7 @@ describe('NativeCommandsSender', () => {
10 10
       push: jest.fn(),
11 11
       pop: jest.fn(),
12 12
       popTo: jest.fn(),
13
+      popToRoot: jest.fn(),
13 14
       showModal: jest.fn(),
14 15
       dismissModal: jest.fn(),
15 16
       dismissAllModals: jest.fn()
@@ -47,6 +48,12 @@ describe('NativeCommandsSender', () => {
47 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 57
   it('showModal sends to native', async () => {
51 58
     const result = await uut.showModal({});
52 59
     expect(mockNativeModule.showModal).toHaveBeenCalledTimes(1);

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

@@ -22,4 +22,8 @@ export default class ContainerCommands {
22 22
   popTo(toContainerId) {
23 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,4 +72,18 @@ describe('ContainerCommands', () => {
72 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
 });