import {InterpolationBindingExpression} from '../src/binding-language';

describe('interpolation binding', () => {  
  describe('interpolate', () => {
    var observerLocator, targetProperty, accessScope, parts, myViewModel;

    class ObserverLocator{
        getObserver(target, targetPropert){};
    }

    class AccessScope{
      constructor(name){
        this.name = name;
      };

      evaluate(){}   
    }

    class FooProperty{
      setValue(value){
        this.value = value;
      }
    }

    class MyViewModel{
      constructor(){
        this.fooCount;
      }
    }

    beforeEach(() => {
      observerLocator = new ObserverLocator();
      targetProperty = new FooProperty();   
      myViewModel = new MyViewModel    
      accessScope = new AccessScope('fooCount');
      parts = ['', accessScope];

      spyOn(observerLocator, 'getObserver').and.returnValue(targetProperty);      
    });

    it('interpolates undefined to empty string', ()=> {         

      myViewModel.fooCount = undefined;  

      spyOn(accessScope, 'evaluate').and.returnValue(myViewModel.fooCount);

      var interpolationBindingExpression = new InterpolationBindingExpression(observerLocator, targetProperty, parts);
      var interpolationBinding = interpolationBindingExpression.createBinding();
      interpolationBinding.bind(myViewModel);

      expect(targetProperty.value).toBe('');
    });

    it('interpolates null to empty string', ()=> {         

      myViewModel.fooCount = null;  

      spyOn(accessScope, 'evaluate').and.returnValue(myViewModel.fooCount);

      var interpolationBindingExpression = new InterpolationBindingExpression(observerLocator, targetProperty, parts);
      var interpolationBinding = interpolationBindingExpression.createBinding();
      interpolationBinding.bind(myViewModel);

      expect(targetProperty.value).toBe('');
    }); 

    it('interpolates number 0 to string', ()=> {         

      myViewModel.fooCount = 0;  

      spyOn(accessScope, 'evaluate').and.returnValue(myViewModel.fooCount);

      var interpolationBindingExpression = new InterpolationBindingExpression(observerLocator, targetProperty, parts);
      var interpolationBinding = interpolationBindingExpression.createBinding();
      interpolationBinding.bind(myViewModel);

      expect(targetProperty.value).toBe('0');
    });

    it('can interpolate string to string', ()=> {         

      myViewModel.fooCount = "Martin";  

      spyOn(accessScope, 'evaluate').and.returnValue(myViewModel.fooCount);

      var interpolationBindingExpression = new InterpolationBindingExpression(observerLocator, targetProperty, parts);
      var interpolationBinding = interpolationBindingExpression.createBinding();
      interpolationBinding.bind(myViewModel);

      expect(targetProperty.value).toBe('Martin');
    });
  });
});
@@ -107,18 +107,16 @@
  () =%3E %7B
-  
 %0A  descr
@@ -399,19 +399,16 @@
 uate()%7B%7D
-   
 %0A    %7D%0A%0A
@@ -574,24 +574,188 @@
    %7D%0A    %7D%0A%0A
+    function createTarget()%7B%0A      var h = document.createElement('div');%0A      var t = document.createTextNode('');%0A      h.appendChild(t);%0A      return t;%0A    %7D%0A%0A
     beforeEa
@@ -853,19 +853,16 @@
 perty();
-   
 %0A      m
@@ -889,20 +889,16 @@
 iewModel
-    
 %0A      a
@@ -1049,22 +1049,16 @@
 operty);
-      
 %0A    %7D);
@@ -1110,33 +1110,24 @@
 ing', ()=%3E %7B
-         
 %0A%0A      myVi
@@ -1155,18 +1155,16 @@
 defined;
-  
 %0A%0A      
@@ -1423,32 +1423,46 @@
 n.createBinding(
+createTarget()
 );%0A      interpo
@@ -1595,33 +1595,24 @@
 ing', ()=%3E %7B
-         
 %0A%0A      myVi
@@ -1635,18 +1635,16 @@
  = null;
-  
 %0A%0A      
@@ -1903,32 +1903,46 @@
 n.createBinding(
+createTarget()
 );%0A      interpo
@@ -2027,17 +2027,16 @@
 %0A    %7D);
- 
 %0A%0A    it
@@ -2073,33 +2073,24 @@
 ing', ()=%3E %7B
-         
 %0A%0A      myVi
@@ -2110,18 +2110,16 @@
 unt = 0;
-  
 %0A%0A      
@@ -2378,32 +2378,46 @@
 n.createBinding(
+createTarget()
 );%0A      interpo
@@ -2558,17 +2558,8 @@
 =%3E %7B
-         
 %0A%0A  
@@ -2594,18 +2594,16 @@
 Martin%22;
-  
 %0A%0A      
@@ -2870,16 +2870,30 @@
 Binding(
+createTarget()
 );%0A     
@@ -3002,8 +3002,9 @@
  %7D);%0A%7D);
+%0A

add targets for interpolation