Browse Source

removed unnecessary duct tape tests

Daniel Zlotin 7 years ago
parent
commit
a73c1e7c42

+ 0
- 111
lib/src/Navigation.test.js View File

@@ -1,111 +0,0 @@
1
-describe('Navigation', () => {
2
-  let Navigation;
3
-
4
-  beforeEach(() => {
5
-    //TODO don't mock here, just create the actual object and assert on basic behavior
6
-    jest.mock('./adapters/UniqueIdProvider');
7
-    jest.mock('./adapters/NativeCommandsSender');
8
-    jest.mock('./adapters/NativeEventsReceiver');
9
-
10
-    jest.mock('./containers/ContainerRegistry');
11
-    jest.mock('./commands/Commands');
12
-
13
-    Navigation = require('./Navigation').default;
14
-  });
15
-
16
-  it('registerContainer delegates to ContainerRegistry', () => {
17
-    expect(Navigation.containerRegistry.registerContainer).not.toHaveBeenCalled();
18
-    const fn = jest.fn();
19
-    Navigation.registerContainer('name', fn);
20
-    expect(Navigation.containerRegistry.registerContainer).toHaveBeenCalledTimes(1);
21
-    expect(Navigation.containerRegistry.registerContainer).toHaveBeenCalledWith('name', fn);
22
-  });
23
-
24
-  it('setRoot delegates to Commands', async () => {
25
-    Navigation.commands.setRoot.mockReturnValue(Promise.resolve('result'));
26
-    const params = {};
27
-    const result = await Navigation.setRoot(params);
28
-    expect(result).toEqual('result');
29
-    expect(Navigation.commands.setRoot).toHaveBeenCalledTimes(1);
30
-    expect(Navigation.commands.setRoot).toHaveBeenCalledWith(params);
31
-  });
32
-
33
-  it('setOptions delegates to Commands', async () => {
34
-    const theContainerId = "7";
35
-    const params = { title: "T" };
36
-    Navigation.setOptions(theContainerId, params);
37
-    expect(Navigation.commands.setOptions).toHaveBeenCalledTimes(1);
38
-    expect(Navigation.commands.setOptions).toHaveBeenCalledWith(theContainerId, params);
39
-  });
40
-
41
-  it('showModal delegates to Commands', async () => {
42
-    Navigation.commands.showModal.mockReturnValue(Promise.resolve('result'));
43
-    const params = {};
44
-    const result = await Navigation.showModal(params);
45
-    expect(result).toEqual('result');
46
-    expect(Navigation.commands.showModal).toHaveBeenCalledWith(params);
47
-    expect(Navigation.commands.showModal).toHaveBeenCalledTimes(1);
48
-  });
49
-
50
-  it('dismissModal delegates to Commands', async () => {
51
-    Navigation.commands.dismissModal.mockReturnValue(Promise.resolve('result'));
52
-    const params = {};
53
-    const result = await Navigation.dismissModal(params);
54
-    expect(result).toEqual('result');
55
-    expect(Navigation.commands.dismissModal).toHaveBeenCalledTimes(1);
56
-    expect(Navigation.commands.dismissModal).toHaveBeenCalledWith(params);
57
-  });
58
-
59
-  it('dismissAllModals', async () => {
60
-    Navigation.commands.dismissAllModals.mockReturnValue(Promise.resolve('result'));
61
-    const result = await Navigation.dismissAllModals();
62
-    expect(Navigation.commands.dismissAllModals).toHaveBeenCalledTimes(1);
63
-    expect(result).toEqual('result');
64
-  });
65
-
66
-  it('events return public events', () => {
67
-    const cb = jest.fn();
68
-    Navigation.events().onAppLaunched(cb);
69
-    expect(Navigation.nativeEventsReceiver.appLaunched).toHaveBeenCalledTimes(1);
70
-    expect(Navigation.nativeEventsReceiver.appLaunched).toHaveBeenCalledWith(cb);
71
-  });
72
-
73
-  it('starts listening and handles internal events', () => {
74
-    expect(Navigation.nativeEventsReceiver.containerStart).toHaveBeenCalledTimes(1);
75
-  });
76
-
77
-  it('push delegates to commands', async () => {
78
-    Navigation.commands.push.mockReturnValue(Promise.resolve('result'));
79
-    const params = {};
80
-    const result = await Navigation.push('theContainerId', params);
81
-    expect(result).toEqual('result');
82
-    expect(Navigation.commands.push).toHaveBeenCalledWith('theContainerId', params);
83
-    expect(Navigation.commands.push).toHaveBeenCalledTimes(1);
84
-  });
85
-
86
-  it('pop delegates to commands', async () => {
87
-    Navigation.commands.pop.mockReturnValue(Promise.resolve('result'));
88
-    const result = await Navigation.pop('theContainerId');
89
-    expect(result).toEqual('result');
90
-    expect(Navigation.commands.pop).toHaveBeenCalledWith('theContainerId');
91
-    expect(Navigation.commands.pop).toHaveBeenCalledTimes(1);
92
-  });
93
-
94
-  it('popTo delegates to commands', async () => {
95
-    Navigation.commands.popTo.mockReturnValue(Promise.resolve('result'));
96
-    const params = {};
97
-    const result = await Navigation.popTo('theContainerId');
98
-    expect(result).toEqual('result');
99
-    expect(Navigation.commands.popTo).toHaveBeenCalledWith('theContainerId');
100
-    expect(Navigation.commands.popTo).toHaveBeenCalledTimes(1);
101
-  });
102
-
103
-  it('popToRoot delegates to commands', async () => {
104
-    Navigation.commands.popToRoot.mockReturnValue(Promise.resolve('result'));
105
-    const params = {};
106
-    const result = await Navigation.popToRoot('theContainerId');
107
-    expect(result).toEqual('result');
108
-    expect(Navigation.commands.popToRoot).toHaveBeenCalledWith('theContainerId');
109
-    expect(Navigation.commands.popToRoot).toHaveBeenCalledTimes(1);
110
-  });
111
-});

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

@@ -1,80 +0,0 @@
1
-import { NativeModules } from 'react-native';
2
-import NativeCommandsSender from './NativeCommandsSender';
3
-
4
-describe('NativeCommandsSender', () => {
5
-  let uut, mockNativeModule;
6
-
7
-  beforeEach(() => {
8
-    mockNativeModule = {
9
-      setRoot: jest.fn(),
10
-      setOptions: jest.fn(),
11
-      push: jest.fn(),
12
-      pop: jest.fn(),
13
-      popTo: jest.fn(),
14
-      popToRoot: jest.fn(),
15
-      showModal: jest.fn(),
16
-      dismissModal: jest.fn(),
17
-      dismissAllModals: jest.fn()
18
-    };
19
-    NativeModules.RNNBridgeModule = mockNativeModule;
20
-    uut = new NativeCommandsSender();
21
-  });
22
-
23
-  it('delegates to native', () => {
24
-    uut.setRoot();
25
-    expect(mockNativeModule.setRoot).toHaveBeenCalledTimes(1);
26
-  });
27
-
28
-  it('returns promise with resolved layout', async () => {
29
-    const result = await uut.setRoot({});
30
-    expect(result).toBeDefined();
31
-  });
32
-
33
-  it('setOptions sends to native with containerId and params', () => {
34
-    uut.setOptions('theContainerId', { title: "Title" });
35
-    expect(mockNativeModule.setOptions).toHaveBeenCalledTimes(1);
36
-  });
37
-
38
-  it('push sends to native and resolves with promise', async () => {
39
-    const theNewContainer = {};
40
-    const result = await uut.push('theContainerId', theNewContainer);
41
-    expect(mockNativeModule.push).toHaveBeenCalledTimes(1);
42
-    expect(result).toBeDefined();
43
-  });
44
-
45
-  it('pop sends to native with containerId', async () => {
46
-    const result = await uut.pop('theContainerId');
47
-    expect(mockNativeModule.pop).toHaveBeenCalledTimes(1);
48
-    expect(result).toBeDefined();
49
-  });
50
-
51
-  it('popTo sends to native with containerId and targetId', async () => {
52
-    const result = await uut.popTo('theContainerId', 'targetId');
53
-    expect(mockNativeModule.popTo).toHaveBeenCalledTimes(1);
54
-    expect(result).toBeDefined();
55
-  });
56
-
57
-  it('popToRoot', async () => {
58
-    const result = await uut.popToRoot('theContainerId');
59
-    expect(mockNativeModule.popToRoot).toHaveBeenCalledTimes(1);
60
-    expect(result).toBeDefined();
61
-  });
62
-
63
-  it('showModal sends to native', async () => {
64
-    const result = await uut.showModal({});
65
-    expect(mockNativeModule.showModal).toHaveBeenCalledTimes(1);
66
-    expect(result).toBeDefined();
67
-  });
68
-
69
-  it('dismissModal', async () => {
70
-    const result = await uut.dismissModal('id');
71
-    expect(mockNativeModule.dismissModal).toHaveBeenCalledTimes(1);
72
-    expect(result).toEqual('id');
73
-  });
74
-
75
-  it('dismissAllModals', async () => {
76
-    const result = await uut.dismissAllModals();
77
-    expect(mockNativeModule.dismissAllModals).toHaveBeenCalledTimes(1);
78
-    expect(result).toBe(true);
79
-  });
80
-});

+ 0
- 37
lib/src/adapters/NativeEventsReceiver.test.js View File

@@ -1,37 +0,0 @@
1
-import { NativeModules } from 'react-native';
2
-import NativeEventsReceiver from './NativeEventsReceiver';
3
-
4
-describe('NativeEventsReceiver', () => {
5
-  let uut;
6
-  const eventEmitterMock = { addListener: jest.fn() };
7
-
8
-  beforeEach(() => {
9
-    NativeModules.RNNEventEmitter = {};
10
-    uut = new NativeEventsReceiver();
11
-    uut.emitter = eventEmitterMock;
12
-  });
13
-
14
-  it('register for appLaunched', () => {
15
-    const callback = jest.fn();
16
-    uut.appLaunched(callback);
17
-    expect(callback).not.toHaveBeenCalled();
18
-    expect(eventEmitterMock.addListener).toHaveBeenCalledTimes(1);
19
-    expect(eventEmitterMock.addListener).toHaveBeenCalledWith('RNN.appLaunched', callback);
20
-  });
21
-
22
-  it('containerStart', () => {
23
-    const callback = jest.fn();
24
-    uut.containerStart(callback);
25
-    expect(callback).not.toHaveBeenCalled();
26
-    expect(eventEmitterMock.addListener).toHaveBeenCalledTimes(1);
27
-    expect(eventEmitterMock.addListener).toHaveBeenCalledWith('RNN.containerStart', callback);
28
-  });
29
-
30
-  it('containerStop', () => {
31
-    const callback = jest.fn();
32
-    uut.containerStop(callback);
33
-    expect(callback).not.toHaveBeenCalled();
34
-    expect(eventEmitterMock.addListener).toHaveBeenCalledTimes(1);
35
-    expect(eventEmitterMock.addListener).toHaveBeenCalledWith('RNN.containerStop', callback);
36
-  });
37
-});

+ 0
- 21
lib/src/adapters/UniqueIdProvider.test.js View File

@@ -1,21 +0,0 @@
1
-import UniqueIdProvider from './UniqueIdProvider';
2
-
3
-describe('UniqueIdProvider', () => {
4
-  let uut;
5
-
6
-  beforeEach(() => {
7
-    uut = new UniqueIdProvider();
8
-  });
9
-
10
-  it('provides uniqueId with optional prefix', () => {
11
-    expect(uut.generate()).toEqual('1');
12
-    expect(uut.generate()).toEqual('2');
13
-    expect(uut.generate('prefix')).toEqual('prefix3');
14
-    expect(uut.generate('prefix')).toEqual('prefix4');
15
-    expect(uut.generate('other')).toEqual('other5');
16
-  });
17
-
18
-  it('id is unique across instances', () => {
19
-    expect(uut.generate()).not.toEqual('1');
20
-  });
21
-});

+ 0
- 16
lib/src/index.test.js View File

@@ -1,16 +0,0 @@
1
-jest.mock('./Navigation', () => ({ startApp: () => 'import' }));
2
-import Navigation from './index';
3
-
4
-describe('index', () => {
5
-  let uut;
6
-
7
-  beforeEach(() => {
8
-    jest.mock('./Navigation', () => ({ startApp: () => 'require' }));
9
-    uut = require('./index');
10
-  });
11
-
12
-  it('exposes Navigation', () => {
13
-    expect(uut.startApp()).toEqual('require');
14
-    expect(Navigation.startApp()).toEqual('import');
15
-  });
16
-});

+ 7
- 0
package.json View File

@@ -87,6 +87,13 @@
87 87
       "<rootDir>/lib/src/",
88 88
       "<rootDir>/integration/"
89 89
     ],
90
+    "collectCoverageFrom": [
91
+      "lib/src/**/*.js",
92
+      "integration/**/*.js",
93
+      "!lib/src/index.js",
94
+      "!lib/src/Navigation.js",
95
+      "!lib/src/adapters/**/*"
96
+    ],
90 97
     "resetMocks": true,
91 98
     "resetModules": true,
92 99
     "coverageThreshold": {