소스 검색

try to make enum work

Daniel Zlotin 7 년 전
부모
커밋
ec56897109

lib/src/commands/LayoutTreeParser.test.js → lib/src/commands/LayoutTreeParser.test.ts 파일 보기

@@ -1,7 +1,7 @@
1
-const LayoutTreeParser = require('./LayoutTreeParser');
2
-const LayoutTypes = require('./LayoutTypes');
3
-const _ = require('lodash');
4
-const Examples = require('./LayoutExamples');
1
+import * as  _ from 'lodash';
2
+import { LayoutTreeParser } from './LayoutTreeParser';
3
+import { LayoutTypes } from './LayoutTypes';
4
+import { Examples } from './LayoutExamples';
5 5
 
6 6
 describe('LayoutTreeParser', () => {
7 7
   let uut;

lib/src/commands/LayoutTreeParser.js → lib/src/commands/LayoutTreeParser.ts 파일 보기

@@ -1,14 +1,13 @@
1
-import { LayoutTypes } from './LayoutTypes';
1
+import * as _ from 'lodash';
2
+import { LayoutTypes } from './values/LayoutTypes';
2 3
 
3
-const _ = require('lodash');
4
-
5
-class LayoutTreeParser {
4
+export class LayoutTreeParser {
6 5
   constructor() {
7 6
     this.parse = this.parse.bind(this);
8 7
   }
9 8
 
10 9
   /**
11
-   * returns correct layout tree of nodes which are { type, data, children }
10
+   * @returns correct layout tree of nodes which are { type, data, children }
12 11
    */
13 12
   parse(api) {
14 13
     if (api.topTabs) {
@@ -92,5 +91,3 @@ class LayoutTreeParser {
92 91
     };
93 92
   }
94 93
 }
95
-
96
-module.exports = LayoutTreeParser;

+ 6
- 0
lib/src/commands/OptionsProcessor.test.ts 파일 보기

@@ -9,8 +9,10 @@ describe('navigation options', () => {
9 9
 
10 10
   it('processes colors into numeric AARRGGBB', () => {
11 11
     options.someKeyColor = 'red';
12
+    options.color = 'blue';
12 13
     OptionsProcessor.processOptions(options);
13 14
     expect(options.someKeyColor).toEqual(0xffff0000);
15
+    expect(options.color).toEqual(0xff0000ff);
14 16
 
15 17
     options.someKeyColor = 'yellow';
16 18
     OptionsProcessor.processOptions(options);
@@ -78,6 +80,8 @@ describe('navigation options', () => {
78 80
 
79 81
   it('resolve image sources with name/ending with icon', () => {
80 82
     options.icon = 'require("https://wix.github.io/react-native-navigation/_images/logo.png");';
83
+    options.image = 'require("https://wix.github.io/react-native-navigation/_images/logo.png");';
84
+    options.myImage = 'require("https://wix.github.io/react-native-navigation/_images/logo.png");';
81 85
     options.topBar = {
82 86
       myIcon: 'require("https://wix.github.io/react-native-navigation/_images/logo.png");',
83 87
       myOtherValue: 'value'
@@ -89,6 +93,8 @@ describe('navigation options', () => {
89 93
     // and expect the value to be resovled, in this case it doesn't find anything and returns null
90 94
     expect(options.icon).toEqual(null);
91 95
     expect(options.topBar.myIcon).toEqual(null);
96
+    expect(options.image).toEqual(null);
97
+    expect(options.myImage).toEqual(null);
92 98
     expect(options.topBar.myOtherValue).toEqual('value');
93 99
   });
94 100
 

+ 10
- 10
lib/src/commands/OptionsProcessor.ts 파일 보기

@@ -5,16 +5,16 @@ import * as resolveAssetSource from 'react-native/Libraries/Image/resolveAssetSo
5 5
 export class OptionsProcessor {
6 6
   static processOptions(options: any) {
7 7
     _.forEach(options, (value, key) => {
8
-      if (value) {
9
-        if (_.endsWith(key, 'Color')) {
10
-          options[key] = processColor(value);
11
-        }
12
-        if (_.isEqual(key, 'icon') || _.endsWith(key, 'Icon') || _.endsWith(key, 'Image')) {
13
-          options[key] = resolveAssetSource(options[key]);
14
-        }
15
-        if (_.isObject(value) || _.isArray(value)) {
16
-          OptionsProcessor.processOptions(value);
17
-        }
8
+      if (!value) return
9
+
10
+      if (_.isEqual(key, 'color') || _.endsWith(key, 'Color')) {
11
+        options[key] = processColor(value);
12
+      }
13
+      if (_.isEqual(key, 'icon') || _.isEqual(key, 'image') || _.endsWith(key, 'Icon') || _.endsWith(key, 'Image')) {
14
+        options[key] = resolveAssetSource(options[key]);
15
+      }
16
+      if (_.isObject(value) || _.isArray(value)) {
17
+        OptionsProcessor.processOptions(value);
18 18
       }
19 19
     });
20 20
   }

+ 7
- 0
lib/src/commands/values/LayoutNode.test.ts 파일 보기

@@ -0,0 +1,7 @@
1
+import { LayoutNode } from './LayoutNode';
2
+
3
+describe('LayoutNode', () => {
4
+  it('value type', () => {
5
+    
6
+  });
7
+});

+ 5
- 0
lib/src/commands/values/LayoutNode.ts 파일 보기

@@ -0,0 +1,5 @@
1
+import { LayoutTypes } from "./LayoutTypes";
2
+
3
+export interface LayoutNode {
4
+  type: LayoutTypes
5
+}

+ 26
- 0
lib/src/commands/values/LayoutType.test.ts 파일 보기

@@ -0,0 +1,26 @@
1
+import { LayoutType } from './LayoutType';
2
+
3
+describe('LayoutType', () => {
4
+  it('is an enum', () => {
5
+    expect(LayoutType.Component).toEqual('Component');
6
+    expect(LayoutType.Stack).toEqual('Stack');
7
+  });
8
+
9
+  it('valueOf dynamic string value', () => {
10
+    const name = 'Stack';
11
+    expect(LayoutType[name]).toEqual(LayoutType.Stack);
12
+    expect(LayoutType['asdasd']).toEqual(undefined);
13
+    expect(LayoutType.isValid('asdasd')).toBe(false);
14
+    expect(LayoutType.isValid('TopTabs')).toBe(true);
15
+    expect(LayoutType.isValid('isValid')).toBe(false);
16
+  });
17
+});
18
+
19
+// Component: 'Component',
20
+// Stack: 'Stack',
21
+// BottomTabs: 'BottomTabs',
22
+// SideMenuRoot: 'SideMenuRoot',
23
+// SideMenuCenter: 'SideMenuCenter',
24
+// SideMenuLeft: 'SideMenuLeft',
25
+// SideMenuRight: 'SideMenuRight',
26
+// TopTabs: 'TopTabs',

lib/src/commands/LayoutTypes.ts → lib/src/commands/values/LayoutType.ts 파일 보기

@@ -1,4 +1,6 @@
1
-export const enum LayoutTypes {
1
+import * as _ from 'lodash';
2
+
3
+export const enum LayoutType {
2 4
   Component = 'Component',
3 5
   Stack = 'Stack',
4 6
   BottomTabs = 'BottomTabs',
@@ -8,3 +10,7 @@ export const enum LayoutTypes {
8 10
   SideMenuRight = 'SideMenuRight',
9 11
   TopTabs = 'TopTabs'
10 12
 };
13
+
14
+export function isValid(name: string) {
15
+  return _.keys(LayoutType);
16
+}

+ 11
- 0
lib/src/commands/values/LayoutTypes.test.ts 파일 보기

@@ -0,0 +1,11 @@
1
+import { LayoutTypes } from './LayoutTypes';
2
+
3
+describe('LayoutTypes', () => {
4
+  it('enum isValid', () => {
5
+    expect(LayoutTypes.isValid('')).toBe(false);
6
+    expect(LayoutTypes.isValid('unknown type')).toBe(false);
7
+    expect(LayoutTypes.isValid('Component')).toBe(true);
8
+    expect(LayoutTypes.isValid('Stack')).toBe(true);
9
+    expect(LayoutTypes.isValid('Stack ')).toBe(false);
10
+  });
11
+});

+ 15
- 0
lib/src/commands/values/LayoutTypes.ts 파일 보기

@@ -0,0 +1,15 @@
1
+export class LayoutTypes {
2
+  private static validTypes = [
3
+    'Component',
4
+    'Stack',
5
+    'BottomTabs',
6
+    'SideMenuRoot',
7
+    'SideMenuCenter',
8
+    'SideMenuLeft',
9
+    'SideMenuRight',
10
+    'TopTabs'];
11
+
12
+  public static isValid(type: string) {
13
+    return this.validTypes.includes(type);
14
+  }
15
+}

+ 6
- 0
lib/src/commands/values/Options.test.ts 파일 보기

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

+ 3
- 0
lib/src/commands/values/Options.ts 파일 보기

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