'use strict';

describe('Directive: annotationEditor', function() {

    var element = null;
    var scope = null;
    var annotationEditorData = null;
    var $compile, $httpBackend;

    beforeEach(inject(function( $rootScope, _$compile_, _AnnotationEditorData_ , _$httpBackend_ ) {

        scope = $rootScope.$new();
        annotationEditorData = _AnnotationEditorData_;
        $httpBackend = _$httpBackend_;
        $compile = _$compile_;

        scope.review = annotationEditorData.review;
        scope.selectedText = annotationEditorData.selectedText;

        $httpBackend.whenGET('views/directives/annotation-editor.html').respond(200, '<div></div>');
        var el = angular.element('<annotation-editor origin="\'text\'" class="annotation-editor"  review="review" review-html="review.review.html" selected-text="selectedText"></annotation-editor>');
        element = $compile(el)(scope);
        scope.$digest();
    }));

    it('calculateAnnotationBySelectionAndOriginalText() should work fine annotation-editor', function() {

        var selectedText,
            text;

        var result;

        var isolatedScope;
        
        isolatedScope = element.isolateScope();
        console.log( isolatedScope );

        selectedText = 'It is very easy to use';
        text = 'It is very easy to use. I liked it because it can be used in shower also!!';

        result = isolatedScope.calculateAnnotationBySelectionAndOriginalText(selectedText, text);


        console.log(result);
        expect(result).to.eql({
            start: 0,
            text: selectedText,
            offset: selectedText.length,
            origin: 'text'
        });
    });

});
