"use strict";

describe("snSkrollrProvider", function () {

    var serviceProvider, $window, $document, spy, scope, rootScope, snSkrollr, refresh, skrollrInstance;

    beforeEach(function () {

        // Initialize the service provider by injecting it to a fake module"s config block
        angular.module("testApp", function () {})
            .config(function (snSkrollrProvider) {
                snSkrollrProvider.config = { smoothScrolling: true };
                serviceProvider = snSkrollrProvider
            });

        module("sn.skrollr", "testApp");

        inject(function ($rootScope, $injector) {
            scope = $rootScope.$new();
            rootScope = $rootScope;

            snSkrollr = $injector.get("snSkrollr");

            $window = $injector.get("$window");
            $window.skrollr = {
                init: function() {
                    return {
                        refresh: function(){}
                    };
                }
            }
            spy = spyOn($window.skrollr, "init");
            spy.and.callThrough();

            $document = $injector.get("$document");
            $document.ready = function(fn){ fn.call(this); }

        });

    });

    it("should configure snSkrollr with options", function () {
        expect(serviceProvider.config).toEqual({ smoothScrolling: true });
    });

    it("should call skrollr init", function () {

        snSkrollr.init();
        expect(spy).toHaveBeenCalled();
    });

});

describe("directive: snSkrollr", function() {
    var element, scope, isolatedScope, snSkrollr, spy;

    beforeEach(module("sn.skrollr"));

    beforeEach(inject(function ($rootScope, $compile, $injector) {
        scope = $rootScope.$new();

        snSkrollr = $injector.get("snSkrollr");
        snSkrollr.skrollr = {
            refresh: function() { return }
        }
        spy = spyOn(snSkrollr, "refresh");

        element =
            "<sn-skrollr>" +
                "<div id=\"elem1\"></div>" +
            "</sn-skrollr>";

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

    }));

    it("should refresh skrollr", function (){
        expect(spy).toHaveBeenCalled();
    });

});


@@ -102,16 +102,25 @@
 nt, spy,
+ destroy,
  scope, 
@@ -167,16 +167,16 @@
 stance;%0A
-
 %0A    bef
@@ -972,32 +972,72 @@
                %7D
+,%0A                destroy: function() %7B%7D
 %0A            %7D%0A 
@@ -1117,24 +1117,121 @@
 Through();%0A%0A
+            destroy = spyOn($window.skrollr, %22destroy%22);%0A            destroy.and.callThrough();%0A%0A
             
@@ -1574,24 +1574,24 @@
 llr.init();%0A
-
         expe
@@ -1610,32 +1610,650 @@
 veBeenCalled();%0A
+        expect(serviceProvider.hasBeenInitialised).toEqual(true);%0A    %7D);%0A%0A    it(%22should call skrollr destroy%22, function () %7B%0A%0A        serviceProvider.hasBeenInitialised = true;%0A        snSkrollr.destroy();%0A        expect(destroy).toHaveBeenCalled();%0A        expect(serviceProvider.hasBeenInitialised).toEqual(false);%0A%0A    %7D);%0A%0A    it(%22should not call skrollr destroy if skrollr hasn't been initialised%22, function () %7B%0A%0A        serviceProvider.hasBeenInitialised = false;%0A        snSkrollr.destroy();%0A        expect(destroy).not.toHaveBeenCalled();%0A        expect(serviceProvider.hasBeenInitialised).toEqual(false);%0A%0A
     %7D);%0A%0A%7D);%0A%0Ade

add tests for snSkrollr.destroy()