/* globals by */
/* jshint node:true */
'use strict';

var User = require('./user');

function Analyst(opts) {
	opts=opts||{};
	User.call(this, opts);
	// this.username = 'wisse@wonderflow.co';
	// this.password = 'wisse2015';
	this.username = 'chiara.lagana@wonderflow.co';
	this.password = 'chiara.lagana2014roma';
}
Analyst.prototype = new User();
Analyst.prototype.openListOfProductToAnalyze = function() {
	return this.browser.element(by.css('.w-toggle-product-list-to-analyze')).click();
};
Analyst.prototype.selectProductToAnalyzeByHumanIdentifier = function(humanIdentifier) {
	var cssClass = '.w-product-name-to-analyze';
	return this.browser.element(by.cssContainingText(cssClass, humanIdentifier)).click();
};
Analyst.prototype.openInsightsEditor = function() {
	return this.browser.element(by.css('.w-toggle-insights-editor')).click();
};
Analyst.prototype.clickOnAddNewInsightButton = function() {
	return this.clickByCssSelector('.w-add-new-insight');
};
Analyst.prototype.setTextOfInsight = function(textOfInsight) {
	return this.browser.element(by.css('.w-new-insight-text')).sendKeys(textOfInsight);
};
Analyst.prototype.saveInsight = function() {
	return this.browser.element(by.css('.w-save-new-insight')).click();
};

User.prototype.countInsights = function() {
  return this.browser.element.all(by.css('.w-insight-item')).count();
};
User.prototype.readStateOfLastInsight = function() {
  // return this.browser.element(by.css('.w-insight-item:last-of-type .w-insight-state')).getText();
  return this.browser.element.all(by.css('.w-insight-item')).last().element(by.css('.w-insight-state')).getText();
};
module.exports = Analyst;