Browse Source

full coverage at last

Daniel Zlotin 7 years ago
parent
commit
1400010231

lib/src/Navigation.js → lib/src/Navigation.ts View File

@@ -1,30 +1,32 @@
1
-const NativeCommandsSender = require('./adapters/NativeCommandsSender');
2
-const NativeEventsReceiver = require('./adapters/NativeEventsReceiver');
3
-const UniqueIdProvider = require('./adapters/UniqueIdProvider');
4
-const Store = require('./components/Store');
5
-const ComponentRegistry = require('./components/ComponentRegistry');
6
-const Commands = require('./commands/Commands');
7
-const LayoutTreeParser = require('./commands/LayoutTreeParser');
8
-const LayoutTreeCrawler = require('./commands/LayoutTreeCrawler');
9
-const PrivateEventsListener = require('./events/PrivateEventsListener');
10
-const PublicEventsRegistry = require('./events/PublicEventsRegistry');
11
-
1
+import { NativeCommandsSender } from './adapters/NativeCommandsSender';
2
+import { NativeEventsReceiver } from './adapters/NativeEventsReceiver';
3
+import { UniqueIdProvider } from './adapters/UniqueIdProvider';
4
+import { Store } from './components/Store';
5
+import { ComponentRegistry } from './components/ComponentRegistry';
6
+import { Commands } from './commands/Commands';
7
+import { LayoutTreeParser } from './commands/LayoutTreeParser';
8
+import { LayoutTreeCrawler } from './commands/LayoutTreeCrawler';
9
+import { PrivateEventsListener } from './events/PrivateEventsListener';
10
+import { PublicEventsRegistry } from './events/PublicEventsRegistry';
11
+import { ComponentProvider } from 'react-native';
12 12
 import { Element } from './adapters/Element';
13 13
 
14 14
 class Navigation {
15
+  public readonly Element = Element;
16
+
17
+  private readonly store = new Store();
18
+  private readonly nativeEventsReceiver = new NativeEventsReceiver();
19
+  private readonly uniqueIdProvider = new UniqueIdProvider();
20
+  private readonly componentRegistry = new ComponentRegistry(this.store);
21
+  private readonly layoutTreeParser = new LayoutTreeParser();
22
+  private readonly layoutTreeCrawler = new LayoutTreeCrawler(this.uniqueIdProvider, this.store);
23
+  private readonly nativeCommandsSender = new NativeCommandsSender();
24
+  private readonly commands = new Commands(this.nativeCommandsSender, this.layoutTreeParser, this.layoutTreeCrawler);
25
+  private readonly publicEventsRegistry = new PublicEventsRegistry(this.nativeEventsReceiver);
26
+  private readonly privateEventsListener = new PrivateEventsListener(this.nativeEventsReceiver, this.store);
27
+
15 28
   constructor() {
16
-    this.store = new Store();
17
-    this.nativeEventsReceiver = new NativeEventsReceiver();
18
-    this.uniqueIdProvider = new UniqueIdProvider();
19
-    this.componentRegistry = new ComponentRegistry(this.store);
20
-    this.layoutTreeParser = new LayoutTreeParser();
21
-    this.layoutTreeCrawler = new LayoutTreeCrawler(this.uniqueIdProvider, this.store);
22
-    this.nativeCommandsSender = new NativeCommandsSender();
23
-    this.commands = new Commands(this.nativeCommandsSender, this.layoutTreeParser, this.layoutTreeCrawler);
24
-    this.publicEventsRegistry = new PublicEventsRegistry(this.nativeEventsReceiver);
25
-    this.privateEventsListener = new PrivateEventsListener(this.nativeEventsReceiver, this.store);
26 29
     this.privateEventsListener.listenAndHandlePrivateEvents();
27
-    this.Element = Element;
28 30
   }
29 31
 
30 32
   /**
@@ -32,7 +34,7 @@ class Navigation {
32 34
    * @param {string} componentName Unique component name
33 35
    * @param {function} getComponentClassFunc generator function, typically `() => require('./myComponent')`
34 36
    */
35
-  registerComponent(componentName, getComponentClassFunc) {
37
+  registerComponent(componentName: string, getComponentClassFunc: ComponentProvider) {
36 38
     this.componentRegistry.registerComponent(componentName, getComponentClassFunc);
37 39
   }
38 40
 

+ 21
- 3
lib/src/commands/LayoutTreeCrawler.test.ts View File

@@ -1,7 +1,6 @@
1
-import { LayoutType } from './values/LayoutType';
2
-import { LayoutTreeCrawler } from './LayoutTreeCrawler';
1
+import { LayoutType } from './LayoutType';
2
+import { LayoutTreeCrawler, LayoutNode } from './LayoutTreeCrawler';
3 3
 import { UniqueIdProvider } from '../adapters/UniqueIdProvider.mock';
4
-import { LayoutNode } from './values/LayoutNode';
5 4
 import { Store } from '../components/Store';
6 5
 
7 6
 describe('LayoutTreeCrawler', () => {
@@ -208,4 +207,23 @@ describe('LayoutTreeCrawler', () => {
208 207
       expect(node.data.options.innerObj.innerMostObj.anotherColor).toEqual(0xffffff00);
209 208
     });
210 209
   });
210
+
211
+  describe('LayoutNode', () => {
212
+    it('convertable from same data structure', () => {
213
+      const x = {
214
+        id: 'theId',
215
+        type: LayoutType.Component,
216
+        data: {},
217
+        children: []
218
+      };
219
+
220
+      let got;
221
+      function expectingLayoutNode(param: LayoutNode) {
222
+        got = param;
223
+      }
224
+      expectingLayoutNode(x);
225
+
226
+      expect(got).toBe(x);
227
+    });
228
+  });
211 229
 });

+ 8
- 2
lib/src/commands/LayoutTreeCrawler.ts View File

@@ -1,7 +1,13 @@
1 1
 import * as _ from 'lodash';
2 2
 import { OptionsProcessor } from './OptionsProcessor';
3
-import { LayoutType, isLayoutType } from './values/LayoutType';
4
-import { LayoutNode } from './values/LayoutNode';
3
+import { LayoutType, isLayoutType } from './LayoutType';
4
+
5
+export interface LayoutNode {
6
+  id?: string;
7
+  type: LayoutType;
8
+  data: object;
9
+  children: Array<LayoutNode>;
10
+}
5 11
 
6 12
 interface IdProvider {
7 13
   generate: (str: string) => string;

+ 1
- 1
lib/src/commands/LayoutTreeParser.test.ts View File

@@ -1,6 +1,6 @@
1 1
 import * as  _ from 'lodash';
2 2
 import { LayoutTreeParser } from './LayoutTreeParser';
3
-import { LayoutType } from './values/LayoutType';
3
+import { LayoutType } from './LayoutType';
4 4
 
5 5
 describe('LayoutTreeParser', () => {
6 6
   let uut;

+ 2
- 2
lib/src/commands/LayoutTreeParser.ts View File

@@ -1,6 +1,6 @@
1 1
 import * as _ from 'lodash';
2
-import { LayoutType } from './values/LayoutType';
3
-import { LayoutNode } from './values/LayoutNode';
2
+import { LayoutType } from './LayoutType';
3
+import { LayoutNode } from './LayoutTreeCrawler';
4 4
 
5 5
 export class LayoutTreeParser {
6 6
   constructor() {

lib/src/commands/values/LayoutType.test.ts → lib/src/commands/LayoutType.test.ts View File


lib/src/commands/values/LayoutType.ts → lib/src/commands/LayoutType.ts View File


+ 0
- 21
lib/src/commands/values/LayoutNode.test.ts View File

@@ -1,21 +0,0 @@
1
-import { LayoutNode } from './LayoutNode';
2
-import { LayoutType } from './LayoutType';
3
-
4
-describe('LayoutNode', () => {
5
-  it('convertable from same data structure', () => {
6
-    const x = {
7
-      id: 'theId',
8
-      type: LayoutType.Component,
9
-      data: {},
10
-      children: []
11
-    };
12
-
13
-    let got;
14
-    function expectingLayoutNode(param: LayoutNode) {
15
-      got = param;
16
-    }
17
-    expectingLayoutNode(x);
18
-
19
-    expect(got).toBe(x);
20
-  });
21
-});

+ 0
- 9
lib/src/commands/values/LayoutNode.ts View File

@@ -1,9 +0,0 @@
1
-import { LayoutType } from "./LayoutType";
2
-
3
-export interface LayoutNode {
4
-  id?: string;
5
-  type: LayoutType;
6
-  data: object;
7
-  children: Array<LayoutNode>;
8
-}
9
-

+ 0
- 6
lib/src/commands/values/Options.test.ts View File

@@ -1,6 +0,0 @@
1
-import { Options } from "./Options";
2
-
3
-describe('Options', () => {
4
-  it('valueType', () => {
5
-  });
6
-});

+ 0
- 3
lib/src/commands/values/Options.ts View File

@@ -1,3 +0,0 @@
1
-export interface Options {
2
-
3
-}