'use strict';

var AnnotatingUser = new(require('./annotating.user.js'))();



var selectedText = 'It';


describe('PAGE: Annotation', function() {

    beforeEach(function() {
        return AnnotatingUser.goToAnnotationPage();
    });



    describe('USE CASE: Create an annotation', function() {

        beforeEach(function() {
            return AnnotatingUser.chooseProductToAnalyzeByIndex(0);
        });

        describe('When the user select a fragment of a review', function() {
            beforeEach(function() {
                var paragraph = element(by.css('.BVRRReviewTextFirstParagraph'));
                browser.actions().mouseMove(paragraph, {
                    x: 0,
                    y: 0
                }).doubleClick().perform();
            });
            it('then `tagDictionaryView` should be displayed and should visualize the selected text', function() {
                var tagDictionary = element(by.id('tag-dictionary'));
                expect(tagDictionary.isDisplayed()).toBe(true);
                expect(tagDictionary.element(by.css('.selected-text .w-selected-text-text')).getText()).toEqual(selectedText);
            });
        });

        describe('When the user selects a fragment of a review, and selects a tag, and selects the sentiment, and types a synonym and click on “Add synonym” button', function() {
            beforeEach(function() {
                return AnnotatingUser.createAnnotation();
            });
            it('then an annotation inside the text appears and it underlines the selected text', function() {
                expect(element.all(by.css('.annotation-highlight')).count()).toEqual(1);
                var newHighlight = element.all(by.css('.annotation-highlight'));
                newHighlight.then(function(elems) {
                    expect(elems[0].getCssValue('background-color')).toEqual('rgba(229, 243, 217, 1)');
                });
            });
            it('then an annotation in the sidebar appears', function() {
                AnnotatingUser.takeScreenshot(null, function() {
                    element.all(by.css('.annotation-list-item')).then(function(elems) {
                        expect(elems.length).toEqual(1);
                        expect(elems[0].isDisplayed()).toBe(true);
                        expect(elems[0].element(by.css('.panel-heading')).getCssValue('border-left-color')).toEqual('rgba(121, 201, 66, 1)');
                        expect(elems[0].element(by.css('.panel-title a div')).getText()).toEqual('Accessories');
                        expect(elems[0].element(by.css('.fa.user')).isDisplayed()).toEqual(true);

                    });
                });
            });
            it('then the annotations in the sidebar should have the css property top lower or higher than the annotation inside the text for no more than 20px', function() {
                element.all(by.css('.annotation-list-item')).then(function(elems) {
                    elems[0].getLocation().then(function(topValue) {
                        element.all(by.css('.annotation-highlight')).then(function(els) {
                            els[0].getLocation().then(function() {
                                expect(topValue).toBeLessThan(topValue + 20);
                            });
                        });
                    });
                });
            });
        });

    });

    xdescribe('USE CASE: Visualize automatic vs manual annotation', function() {


       describe('When analyst accesses an already automatically analyzed product', function() {
            beforeEach(function() {
                return AnnotatingUser.chooseProductToAnalyzeByIndex(1)
                    .then(function(){
                        return AnnotatingUser.wait(5);
                    })
                    .then(function(){
                        return AnnotatingUser.takeScreenshot('automatic-annotations');
                    });
            });

            it('then automatic and manual annotations are correctly visualized', function() {

                return AnnotatingUser.countAutomaticAnnotations()
                    .then(function(numberOfAutomaticAnnotations){
                        expect(numberOfAutomaticAnnotations).toBe(2);
                    });
                // select all automatic annotation //
                // select all manual annotation
                // verify that they contain the proper icon
            });
        });

    }).pend('FIX AS SOON AS POSSIBLE');


});