/**
 * Created by fran lopez on 9/11/15.
 */

    /**
     * CommonJS module to define a e2e test to check operations with
     * films using the views defined in path "/public/films/views".
     */

    describe('Films E2E Tests:', function() {
        describe('Test for films', function() {
            it('Should not be able to find a film, because the name of director is empty', function() {

                browser.get('http://localhost:3000/#!/films/filmsByDirector');
                element(by.css('input[type=submit]')).click();
                element(by.binding('error')).getText().then(function(errorText) {
                    expect(errorText).toBe('El nombre del director de la película no puede ser nulo');
                });
            });

            it("Should not be able to find films, because there aren't films with this name of director", function() {

                browser.get('http://localhost:3000/#!/films/filmsByDirector');

                var filmTitle = element(by.css('input[type=text]'));

                filmTitle.sendKeys('aaaaaaaaa');
                element(by.css('input[type=submit]')).click();
                element(by.css('label')).getText().then(function(errorText) {
                    expect(errorText).toBe('No existen películas que coincidan con el patrón introducido');
                });
            });

            it("Should be able to find films, because there are films with this name of director", function() {

                browser.get('http://localhost:3000/#!/films/filmsByDirector');

                var filmTitle = element(by.css('input[type=text]'));

                filmTitle.sendKeys('Peter Jackson');
                element(by.css('input[type=submit]')).click();
                expect(element(by.css('li a')).isPresent()).toBe(true);
            });

            it('Should not be able to find a film, because the name of genre is empty', function() {

                browser.get('http://localhost:3000/#!/films/filmsByGenre');
                element(by.css('input[type=submit]')).click();
                element(by.binding('error')).getText().then(function(errorText) {
                    expect(errorText).toBe('El género de la película no puede ser nulo');
                });
            });

            it("Should be able to find films, because there are films with this genre", function() {

                browser.get('http://localhost:3000/#!/films/filmsByGenre');

                element(by.binding('genre')).click();
                element(by.css('input[type=submit]')).click();
                expect(element(by.css('li a')).isPresent()).toBe(true);
            });

            it('Should not be able to find a film, because the name of protagonist is empty', function() {

                browser.get('http://localhost:3000/#!/films/filmsByProtagonist');
                element(by.css('input[type=submit]')).click();
                element(by.binding('error')).getText().then(function(errorText) {
                    expect(errorText).toBe('El nombre del protagonista de la película no puede ser nulo');
                });
            });

            it("Should not be able to find films, because there aren't films with this name of protagonist", function() {

                browser.get('http://localhost:3000/#!/films/filmsByProtagonist');

                var filmTitle = element(by.css('input[type=text]'));

                filmTitle.sendKeys('aaaaaaaaa');
                element(by.css('input[type=submit]')).click();
                element(by.css('label')).getText().then(function(errorText) {
                    expect(errorText).toBe('No existen películas que coincidan con el patrón introducido');
                });
            });

            it("Should be able to find films, because there are films with this name of protagonist", function() {

                browser.get('http://localhost:3000/#!/films/filmsByProtagonist');

                var filmTitle = element(by.css('input[type=text]'));

                filmTitle.sendKeys('Adrien Brody');
                element(by.css('input[type=submit]')).click();
                expect(element(by.css('li a')).isPresent()).toBe(true);
            });

            it('Should not be able to find a film, because the rating is empty', function() {

                browser.get('http://localhost:3000/#!/films/filmsByRating');
                element(by.css('input[type=submit]')).click();
                element(by.binding('error')).getText().then(function(errorText) {
                    expect(errorText).toBe('La valoración de la película no puede ser un valor nulo');
                });
            });

            it("Should be able to find films, because there are films with this rating", function() {

                browser.get('http://localhost:3000/#!/films/filmsByRating');

                element(by.binding('rating')).click();
                element(by.css('input[type=submit]')).click();
                expect(element(by.css('li a')).isPresent()).toBe(true);
            });

            it('Should not be able to find a film, because the title is empty', function() {

                browser.get('http://localhost:3000/#!/films/filmsByTitle');
                element(by.css('input[type=submit]')).click();
                element(by.binding('error')).getText().then(function(errorText) {
                    expect(errorText).toBe('El título de la película no puede ser nulo');
                });
            });

            it("Should not be able to find films, because there aren't films with this title", function() {

                browser.get('http://localhost:3000/#!/films/filmsByTitle');

                var filmTitle = element(by.css('input[type=text]'));

                filmTitle.sendKeys('aaaaaaaaa');
                element(by.css('input[type=submit]')).click();
                element(by.css('label')).getText().then(function(errorText) {
                    expect(errorText).toBe('No existen películas que coincidan con el patrón introducido');
                });
            });

            it("Should be able to find films, because there are films with this title", function() {

                browser.get('http://localhost:3000/#!/films/filmsByTitle');

                var filmTitle = element(by.css('input[type=text]'));

                filmTitle.sendKeys('Gladiator');
                element(by.css('input[type=submit]')).click();
                expect(element(by.css('li a')).isPresent()).toBe(true);
            });

            it('Should not be able to find a film, because the year is empty', function() {

                browser.get('http://localhost:3000/#!/films/filmsByYear');
                element(by.css('input[type=submit]')).click();
                element(by.binding('error')).getText().then(function(errorText) {
                    expect(errorText).toBe('El año de estreno de la película no puede ser nulo');
                });
            });

            it("Should be able to find films, because there are films with this year", function() {

                browser.get('http://localhost:3000/#!/films/filmsByYear');

                element(by.binding('year')).click();
                element(by.css('input[type=submit]')).click();
                expect(element(by.css('li a')).isPresent()).toBe(true);
            });
        });
    });