'use strict';
/* globals  describe, beforeEach, it, expect, browser */


var utils = require('../lib/utils'),
	User = require('../lib/user');



xdescribe('Quality Check', function() {
	var browser1;
	var user1;
	var user1Waiting, user2Waiting;


	beforeEach(function() {
		browser1 = browser;
		user1Waiting = 5;
		user2Waiting = 5;
	});
	beforeEach(function() {
		// utils.login(null, null, browser1);
		browser1.get(utils.getEndPoint() + '/#/quality-check');
		// console.log('Waiting 5 secs.');
		browser1.sleep(5 * 1000);
		return browser.waitForAngular();
	});
	beforeEach(function() {
		user1 = new User({
			browser: browser1
		});
	});



	describe('Page Load', function() {
		it('when user is on /quality-check, then the right data are visualized', function() {
			expect(user1.readRawTextReviewItems()).toContain({
				index: '1',
				fieldName: 'pubDate',
				type: 'has "null" as value',
				numberOfReviews: '1'
			});
			expect(user1.readRawTextReviewItems()).toContain({
				index: '2',
				fieldName: 'country',
				type: 'has "null" as value',
				numberOfReviews: '365'
			});
			expect(user1.readRawTextReviewItems()).toContain({
				index: '3',
				fieldName: 'channel',
				type: 'has "null" as value',
				numberOfReviews: '1'
			});
			expect(user1.readRawTextReviewItems()).toContain({
				index: '4',
				fieldName: 'title',
				type: 'has "null" as value',
				numberOfReviews: '1'
			});
			expect(user1.readRawTextReviewItems()).toContain({
				index: '5',
				fieldName: 'subtitle',
				type: 'has "null" as value',
				numberOfReviews: '1'
			});
			expect(user1.readRawTextReviewItems()).toContain({
				index: '6',
				fieldName: 'authorName',
				type: 'is longer than 113',
				numberOfReviews: '1'
			});
			expect(user1.readRawTextReviewItems()).toContain({
				index: '7',
				fieldName: 'pubDate',
				// type: 'greater than ISODate(\'2015-10-02T07:00:00.000Z\')',
				type: 'greater than ISODate(\'' + new Date(new Date().getFullYear(), new Date().getMonth(), new Date().getDate(), 8, 0).toISOString() + '\')',
				numberOfReviews: '1'
			});
			expect(user1.readRawTextReviewItems()).toContain({
				index: '8',
				fieldName: 'pubDate',
				type: 'is less than ISODate(\'1995-02-01T08:00:00.000Z\')',
				numberOfReviews: '1'
			});
			expect(user1.readRawTextReviewItems()).toContain({
				index: '9',
				fieldName: 'pubDate',
				type: 'has wrong type',
				numberOfReviews: '1'
			});

		});
		it('when user is on /quality-check, then the right data about analyzed reviews are visualized', function() {
			expect(user1.readTextReviewItems()).toContain({
				index: '1',
				type: 'has "null" as value',
				fieldName: 'review.pubDate',
				numberOfReviews: '105'
			});
			expect(user1.readTextReviewItems()).toContain({
				index: '2',
				type: 'has "null" as value',
				fieldName: 'review.country',
				numberOfReviews: '3'
			});
			expect(user1.readTextReviewItems()).toContain({
				index: '3',
				type: 'has "null" as value',
				fieldName: 'review.channel',
				numberOfReviews: '3'
			});
			expect(user1.readTextReviewItems()).toContain({
				index: '4',
				type: 'has "null" as value',
				fieldName: 'review.title',
				numberOfReviews: '3'
			});
			expect(user1.readTextReviewItems()).toContain({
				index: '5',
				type: 'has "null" as value',
				fieldName: 'review.subtitle',
				numberOfReviews: '3'
			});
			expect(user1.readTextReviewItems()).toContain({
				index: '6',
				type: 'is longer than 113',
				fieldName: 'review.authorName',
				numberOfReviews: '1'
			});
			expect(user1.readTextReviewItems()).toContain({
				index: '7',
				// type: 'greater than ISODate(\'2015-10-02T07:00:00.000Z\')',
				type: 'greater than ISODate(\'' + new Date(new Date().getFullYear(), new Date().getMonth(), new Date().getDate(), 8, 0).toISOString() + '\')',
				fieldName: 'review.pubDate',
				numberOfReviews: '1'
			});
			expect(user1.readTextReviewItems()).toContain({
				index: '8',
				type: 'is less than ISODate(\'1995-02-01T08:00:00.000Z\')',
				fieldName: 'review.pubDate',
				numberOfReviews: '1'
			});
			expect(user1.readTextReviewItems()).toContain({
				index: '9',
				type: 'has wrong type',
				fieldName: 'review.pubDate',
				numberOfReviews: '1'
			});

		});
	});

	describe('Filter by product', function() {
		it('when user filters by "Philips - AT620/16", then the list of issues are filtered consequently', function() {
			var productName = 'Philips - AT620/14';

			user1.clickToOpenProductFilterUiComponent();
			user1.clickOnProductInProductFilterUiComponentByProductName(productName);

			expect(user1.readRawTextReviewItems()).toContain({
				index: '1',
				fieldName: 'country',
				type: 'has "null" as value',
				numberOfReviews: '364'
			});
			expect(user1.readTextReviewItems().length).toBeUndefined([]);


		});
	});



});