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

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

    describe('TV Series E2E Tests:', function() {
        describe('Test for tv series', function() {
            it('Should not be able to find a tv serie, because the name of director is empty', function() {

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

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

                browser.get('http://localhost:3000/#!/tvSeries/tvSeriesByDirector');

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

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

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

                browser.get('http://localhost:3000/#!/tvSeries/tvSeriesByDirector');

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

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

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

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

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

                browser.get('http://localhost:3000/#!/tvSeries/tvSeriesByGenre');

                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 tv serie, because the name of protagonist is empty', function() {

                browser.get('http://localhost:3000/#!/tvSeries/tvSeriesByProtagonist');

                element(by.css('input[type=submit]')).click();
                element(by.binding('error')).getText().then(function(errorText) {
                    expect(errorText).toBe('El nombre del protagonista de la serie no puede ser nulo');
                });
            });

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

                browser.get('http://localhost:3000/#!/tvSeries/tvSeriesByProtagonist');

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

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

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

                browser.get('http://localhost:3000/#!/tvSeries/tvSeriesByProtagonist');

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

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

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

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

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

                browser.get('http://localhost:3000/#!/tvSeries/tvSeriesByRating');

                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 tv serie, because the title is empty', function() {

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

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

                browser.get('http://localhost:3000/#!/tvSeries/tvSeriesByTitle');

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

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

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

                browser.get('http://localhost:3000/#!/tvSeries/tvSeriesByTitle');

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

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

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

                browser.get('http://localhost:3000/#!/tvSeries/tvSeriesByYear');
                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 serie no puede ser nulo');
                });
            });

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

                browser.get('http://localhost:3000/#!/tvSeries/tvSeriesByYear');

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