/* global $, angular, Chartist */
'use strict';

describe('libraries', function() {
    it('should load Chartist into the global namespace', function() {
        expect(Chartist).to.exist;
    });
});

describe('angular-chartist', function() {
    var scope, $sandbox, $compile;

    beforeEach(module('angular-chartist'));

    beforeEach(inject(function($injector) {
        scope = $injector.get('$rootScope');
        $compile = $injector.get('$compile');

        // scope = $rootScope.$new();

        $sandbox = $('<div id="sandbox"></div>').appendTo($('body'));
    }));

    afterEach(function() {
        $sandbox.remove();
        scope.$destroy();
    });

    var templates = {
        'default': {
            scope: {
                data: {
                    labels: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
                    series: [
                        [5, 4, 3, 7, 5, 10, 3, 4, 8, 10, 6, 8],
                        [3, 2, 9, 5, 4, 6, 4, 6, 7, 8, 7, 4]
                    ]
                },
                chartType: 'Bar'
            },
            element: '<chartist id="chartist" chartist-data="data" chartist-chart-type="{{chartType}}"></chartist>'
        }
    };

    function compileDirective(template) {
        template = template ? templates[template] : templates['default'];
        angular.extend(scope, template.scope || templates['default'].scope);

        var $element = $(template.element).appendTo($sandbox);

        $element = $compile($element)(scope);

        scope.$digest();

        return $element;
    }

    // it('should contain a single svg element at the root level', function() {
    //     var elm = compileDirective();
    //     console.log(elm);
    //     // expect(elm.children()).to.have.length(1);
    // });
});

@@ -56,14 +56,17 @@
 be('
-librar
+Dependenc
 ies'
@@ -76,24 +76,25 @@
 unction() %7B%0A
+%0A
     it('shou
@@ -100,12 +100,15 @@
 uld 
-load
+include
  Cha
@@ -116,34 +116,98 @@
 tist
- into the global namespace
+', function() %7B%0A        expect(Chartist).to.exist;%0A    %7D);%0A%0A    it('should include angular
 ', f
@@ -229,32 +229,31 @@
      expect(
-Chartist
+angular
 ).to.exist;%0A
@@ -319,32 +319,51 @@
 var 
-scope, $sandbox, $compil
+$rootScope;%0A    var $compile;%0A    var $scop
 e;%0A%0A
@@ -455,25 +455,30 @@
 ) %7B%0A        
-s
+$rootS
 cope = $inje
@@ -551,213 +551,14 @@
 ');%0A
-%0A        // scope = $rootScope.$new();%0A%0A        $sandbox = $('%3Cdiv id=%22sandbox%22%3E%3C/div%3E').appendTo($('body'));%0A    %7D));%0A%0A    afterEach(function() %7B%0A        $sandbox.remove();%0A        scope.$destroy();%0A
     %7D
+)
 );%0A%0A
@@ -1175,24 +1175,61 @@
 template) %7B%0A
+        $scope = $rootScope.$new();%0A%0A
         temp
@@ -1290,16 +1290,17 @@
 ault'%5D;%0A
+%0A
         
@@ -1314,16 +1314,17 @@
 .extend(
+$
 scope, t
@@ -1394,16 +1394,23 @@
 ment = $
+compile
 (templat
@@ -1423,26 +1423,46 @@
 ent)
-.appendTo($sandbox
+($scope);%0A%0A        $rootScope.$digest(
 );%0A%0A
@@ -1469,24 +1469,31 @@
         
+return 
 $element
  = $comp
@@ -1488,36 +1488,155 @@
 ment
- = $compile($element)(
+;%0A    %7D%0A%0A    it('should contain data and chartType', function() %7B%0A        compileDirective();%0A        var defaultScope = templates%5B'default'%5D.
 scope
-)
 ;%0A%0A 
@@ -1646,64 +1646,163 @@
     
-scope.$digest();%0A%0A        return $element
+expect($scope.data).to.exist.and.to.equal(defaultScope.data);%0A%0A        expect($scope.chartType).to.exist.and.to.equal(defaultScope.chartType)
 ;%0A    %7D
+);
 %0A%0A   
- //
  it(
@@ -1815,52 +1815,38 @@
 d co
-ntain a single svg element at the root level
+rrectly handle updates to data
 ', f
@@ -1865,24 +1865,11 @@
     
-//
    
-  var elm =
  com
@@ -1889,58 +1889,195 @@
 ();%0A
+%0A
     
-//
     
- console.log(elm
+$scope.data = %7B%0A            labels: %5B%5D,%0A            series: %5B%5D%0A        %7D;%0A%0A        expect($scope.data).to.exist.and.to.not.equal(templates%5B'default'%5D.scope.data
 );%0A    
-//
    
-  //
  expect(
 elm.
@@ -2076,22 +2076,80 @@
 ect(
-elm.children()
+$scope.data.labels).to.have.length(0);%0A        expect($scope.data.series
 ).to
@@ -2165,18 +2165,15 @@
 gth(
-1
+0
 );%0A   
- //
  %7D);

Add more tests