Browse Source

fixed tests, remove Lifecycle object

Daniel Zlotin 7 years ago
parent
commit
e7bcbdd96d

+ 5
- 5
lib/src/commands/Commands.test.ts View File

46
       const passProps = {
46
       const passProps = {
47
         fn: () => 'Hello'
47
         fn: () => 'Hello'
48
       };
48
       };
49
-      expect(store.getPropsForComponentId('Component+UNIQUE_ID')).toEqual({});
49
+      expect(store.getPropsForId('Component+UNIQUE_ID')).toEqual({});
50
       uut.setRoot({ component: { name: 'asd', passProps } });
50
       uut.setRoot({ component: { name: 'asd', passProps } });
51
-      expect(store.getPropsForComponentId('Component+UNIQUE_ID')).toEqual(passProps);
52
-      expect(store.getPropsForComponentId('Component+UNIQUE_ID').fn()).toEqual('Hello');
51
+      expect(store.getPropsForId('Component+UNIQUE_ID')).toEqual(passProps);
52
+      expect(store.getPropsForId('Component+UNIQUE_ID').fn()).toEqual('Hello');
53
     });
53
     });
54
 
54
 
55
     it('returns a promise with the resolved layout', async () => {
55
     it('returns a promise with the resolved layout', async () => {
108
 
108
 
109
     it('passProps into components', () => {
109
     it('passProps into components', () => {
110
       const passProps = {};
110
       const passProps = {};
111
-      expect(store.getPropsForComponentId('Component+UNIQUE_ID')).toEqual({});
111
+      expect(store.getPropsForId('Component+UNIQUE_ID')).toEqual({});
112
       uut.showModal({
112
       uut.showModal({
113
         component: {
113
         component: {
114
           name: 'com.example.MyScreen',
114
           name: 'com.example.MyScreen',
115
           passProps
115
           passProps
116
         }
116
         }
117
       });
117
       });
118
-      expect(store.getPropsForComponentId('Component+UNIQUE_ID')).toEqual(passProps);
118
+      expect(store.getPropsForId('Component+UNIQUE_ID')).toEqual(passProps);
119
     });
119
     });
120
 
120
 
121
     it('returns a promise with the resolved layout', async () => {
121
     it('returns a promise with the resolved layout', async () => {

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

48
       type: LayoutType.BottomTabs, children: [
48
       type: LayoutType.BottomTabs, children: [
49
         { type: LayoutType.Component, data: { name: 'the name', passProps: { myProp: 123 } } }]
49
         { type: LayoutType.Component, data: { name: 'the name', passProps: { myProp: 123 } } }]
50
     };
50
     };
51
-    expect(store.getPropsForComponentId('Component+UNIQUE_ID')).toEqual({});
51
+    expect(store.getPropsForId('Component+UNIQUE_ID')).toEqual({});
52
     uut.crawl(node);
52
     uut.crawl(node);
53
-    expect(store.getPropsForComponentId('Component+UNIQUE_ID')).toEqual({ myProp: 123 });
53
+    expect(store.getPropsForId('Component+UNIQUE_ID')).toEqual({ myProp: 123 });
54
   });
54
   });
55
 
55
 
56
   it('Components: injects options from original component class static property', () => {
56
   it('Components: injects options from original component class static property', () => {

+ 1
- 1
lib/src/commands/LayoutTreeCrawler.ts View File

40
   }
40
   }
41
 
41
 
42
   _savePropsToStore(node) {
42
   _savePropsToStore(node) {
43
-    this.store.setPropsForComponentId(node.id, node.data.passProps);
43
+    this.store.setPropsForId(node.id, node.data.passProps);
44
   }
44
   }
45
 
45
 
46
   _applyStaticOptions(node) {
46
   _applyStaticOptions(node) {

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

106
 
106
 
107
     OptionsProcessor.processOptions({ o: options }, store);
107
     OptionsProcessor.processOptions({ o: options }, store);
108
 
108
 
109
-    expect(store.setPropsForComponentId).toBeCalledWith('1', passProps);
109
+    expect(store.setPropsForId).toBeCalledWith('1', passProps);
110
   });
110
   });
111
 
111
 
112
   it('processes Options object', () => {
112
   it('processes Options object', () => {

+ 6
- 6
lib/src/components/ComponentWrapper.test.tsx View File

78
   });
78
   });
79
 
79
 
80
   it('pulls props from the store and injects them into the inner component', () => {
80
   it('pulls props from the store and injects them into the inner component', () => {
81
-    store.setPropsForComponentId('component123', { numberProp: 1, stringProp: 'hello', objectProp: { a: 2 } });
81
+    store.setPropsForId('component123', { numberProp: 1, stringProp: 'hello', objectProp: { a: 2 } });
82
     const NavigationComponent = ComponentWrapper.wrap(componentName, MyComponent, store);
82
     const NavigationComponent = ComponentWrapper.wrap(componentName, MyComponent, store);
83
     const tree = renderer.create(<NavigationComponent componentId={'component123'} />);
83
     const tree = renderer.create(<NavigationComponent componentId={'component123'} />);
84
     const originalComponentProps = tree.getInstance()!.originalComponentRef.props;
84
     const originalComponentProps = tree.getInstance()!.originalComponentRef.props;
88
   it('updates props from store into inner component', () => {
88
   it('updates props from store into inner component', () => {
89
     const NavigationComponent = ComponentWrapper.wrap(componentName, MyComponent, store);
89
     const NavigationComponent = ComponentWrapper.wrap(componentName, MyComponent, store);
90
     const tree = renderer.create(<TestParent ChildClass={NavigationComponent} />);
90
     const tree = renderer.create(<TestParent ChildClass={NavigationComponent} />);
91
-    store.setPropsForComponentId('component1', { myProp: 'hello' });
91
+    store.setPropsForId('component1', { myProp: 'hello' });
92
     expect(childRef.originalComponentRef.props.foo).toEqual(undefined);
92
     expect(childRef.originalComponentRef.props.foo).toEqual(undefined);
93
     expect(childRef.originalComponentRef.props.myProp).toEqual(undefined);
93
     expect(childRef.originalComponentRef.props.myProp).toEqual(undefined);
94
     tree.getInstance()!.setState({ propsFromState: { foo: 'yo' } });
94
     tree.getInstance()!.setState({ propsFromState: { foo: 'yo' } });
114
   it('saves self ref into store', () => {
114
   it('saves self ref into store', () => {
115
     const NavigationComponent = ComponentWrapper.wrap(componentName, MyComponent, store);
115
     const NavigationComponent = ComponentWrapper.wrap(componentName, MyComponent, store);
116
     const tree = renderer.create(<NavigationComponent componentId={'component1'} />);
116
     const tree = renderer.create(<NavigationComponent componentId={'component1'} />);
117
-    expect(store.getRefForComponentId('component1')).toBeDefined();
118
-    expect(store.getRefForComponentId('component1')).toBe(tree.getInstance());
117
+    expect(store.getRefForId('component1')).toBeDefined();
118
+    expect(store.getRefForId('component1')).toBe(tree.getInstance());
119
   });
119
   });
120
 
120
 
121
   it('cleans ref from store on unMount', () => {
121
   it('cleans ref from store on unMount', () => {
122
     const NavigationComponent = ComponentWrapper.wrap(componentName, MyComponent, store);
122
     const NavigationComponent = ComponentWrapper.wrap(componentName, MyComponent, store);
123
     const tree = renderer.create(<NavigationComponent componentId={'component1'} />);
123
     const tree = renderer.create(<NavigationComponent componentId={'component1'} />);
124
-    expect(store.getRefForComponentId('component1')).toBeDefined();
124
+    expect(store.getRefForId('component1')).toBeDefined();
125
     tree.unmount();
125
     tree.unmount();
126
-    expect(store.getRefForComponentId('component1')).toBeUndefined();
126
+    expect(store.getRefForId('component1')).toBeUndefined();
127
   });
127
   });
128
 
128
 
129
   it('holds ref to OriginalComponent', () => {
129
   it('holds ref to OriginalComponent', () => {

+ 0
- 28
lib/src/components/Lifecycle.ts View File

1
-export class Lifecycle {
2
-  constructor(private readonly store) {
3
-    this.componentDidAppear = this.componentDidAppear.bind(this);
4
-    this.componentDidDisappear = this.componentDidDisappear.bind(this);
5
-    this.onNavigationButtonPressed = this.onNavigationButtonPressed.bind(this);
6
-  }
7
-
8
-  private componentDidAppear(id) {
9
-    const ref = this.store.getRefForComponentId(id);
10
-    if (ref && ref.didAppear) {
11
-      ref.didAppear();
12
-    }
13
-  }
14
-
15
-  private componentDidDisappear(id) {
16
-    const ref = this.store.getRefForComponentId(id);
17
-    if (ref && ref.didDisappear) {
18
-      ref.didDisappear();
19
-    }
20
-  }
21
-
22
-  private onNavigationButtonPressed(params) {
23
-    const ref = this.store.getRefForComponentId(params.componentId);
24
-    if (ref && ref.onNavigationButtonPressed) {
25
-      ref.onNavigationButtonPressed(params.buttonId);
26
-    }
27
-  }
28
-}