<commit_before>'use strict';

// Selector grabbed from https://coderwall.com/p/tjx5zg
function selectOption(selector, item){
    var selectList, desiredOption;

    selectList = this.findElement(selector);
    selectList.click();

    selectList.findElements(protractor.By.tagName('option'))
        .then(function findMatchingOption(options){
            options.some(function(option){
                option.getText().then(function doesOptionMatch(text){
                    if (item === text){
                        desiredOption = option;
                        return true;
                    }
                });
            });
        })
        .then(function clickOption(){
            if (desiredOption){
                desiredOption.click();
            }
        });
}

var SfUserPage = function() {
	// Get MyProfile->My Account tab
	this.getMyAccount = function() {
		this.baseUrl        = browser.baseUrl;
		this.userProfileURL = '/app/userprofile';

		browser.driver.get(this.baseUrl + this.userProfileURL);
	}
	
	// Get MyProfile->About Me tab
	this.getAboutMe = function() {
		this.getMyAccount();
		browser.driver.findElement(By.id("AboutMeTab")).click();
	}
};

describe('E2E testing: User Profile page', function() {
	var sfUserPage = new SfUserPage();
	
	var LoginPage = require('../../../pages/loginPage'); 
	var loginPage = new LoginPage();
	loginPage.loginAsUser();
	
	it('should update and store "My Account" settings', function() {
		sfUserPage.getMyAccount();

		var newColor         = 'Blue';
		var newShape         = 'Elephant';
		var newMemberEmail   = '<EMAIL>';
		var contactButtonID  = 'BothButton'; // Choose from [EmailButton, SMSButton, BothButton]
		var avatarURL        = 'http://jamaicanpsalms.scriptureforge.local/images/shared/avatar/DodgerBlue-elephant-128x128.png';
		var avatar           = element(by.id('avatarRef'));
		var emailInput       = element(by.model('user.email'));
		// Jamaican mobile phone number will move to Project scope, so intentionally not tested here
		var mobilePhoneInput = element(by.model('user.mobile_phone'));
		var communicate_via  = element(By.id(contactButtonID));
		
		browser.selectOption = selectOption.bind(browser);
		browser.selectOption(protractor.By.model('user.avatar_color'), newColor);
		browser.selectOption(protractor.By.model('user.avatar_shape'), newShape);
		
		// Modify email address
		emailInput.click();
		emailInput.clear();
		emailInput.sendKeys(newMemberEmail);
		
		// Modify contact preference
		communicate_via.click();
		
		// Change Password tested in changepassword e2e
		
		// Submit updated profile<commit_msg>Update user profile test to rely on base URL<commit_after>'use strict';

// Selector grabbed from https://coderwall.com/p/tjx5zg
function selectOption(selector, item){
    var selectList, desiredOption;

    selectList = this.findElement(selector);
    selectList.click();

    selectList.findElements(protractor.By.tagName('option'))
        .then(function findMatchingOption(options){
            options.some(function(option){
                option.getText().then(function doesOptionMatch(text){
                    if (item === text){
                        desiredOption = option;
                        return true;
                    }
                });
            });
        })
        .then(function clickOption(){
            if (desiredOption){
                desiredOption.click();
            }
        });
}

var SfUserPage = function() {
	// Get MyProfile->My Account tab
	this.getMyAccount = function() {
		this.baseUrl        = browser.baseUrl;
		this.userProfileURL = '/app/userprofile';

		browser.driver.get(this.baseUrl + this.userProfileURL);
	}
	
	// Get MyProfile->About Me tab
	this.getAboutMe = function() {
		this.getMyAccount();
		browser.driver.findElement(By.id("AboutMeTab")).click();
	}
};

describe('E2E testing: User Profile page', function() {
	var sfUserPage = new SfUserPage();
	
	var LoginPage = require('../../../pages/loginPage'); 
	var loginPage = new LoginPage();
	loginPage.loginAsUser();
	
	it('should update and store "My Account" settings', function() {
		sfUserPage.getMyAccount();

		var newColor         = 'Blue';
		var newShape         = 'Elephant';
		var newMemberEmail   = '<EMAIL>';
		var contactButtonID  = 'BothButton'; // Choose from [EmailButton, SMSButton, BothButton]
		var avatarURL        = sfUserPage.baseUrl + '/images/shared/avatar/DodgerBlue-elephant-128x128.png';
		var avatar           = element(by.id('avatarRef'));
		var emailInput       = element(by.model('user.email'));
		// Jamaican mobile phone number will move to Project scope, so intentionally not tested here
		var mobilePhoneInput = element(by.model('user.mobile_phone'));
		var communicate_via  = element(By.id(contactButtonID));
		
		browser.selectOption = selectOption.bind(browser);
		browser.selectOption(protractor.By.model('user.avatar_color'), newColor);
		browser.selectOption(protractor.By.model('user.avatar_shape'), newShape);
		
		// Modify email address
		emailInput.click();
		emailInput.clear();
		emailInput.sendKeys(newMemberEmail);
		
		// Modify contact preference
		communicate_via.click();
		
		// Change Password tested in changepassword e2e
		
		// Submit updated profile
{'fraction_non_alphanumeric': 0.1269025875190259, 'fraction_numerical': 0.003424657534246575, 'mean_word_length': 2.899851632047478, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7581975', 'n_tokens_mistral': 1626, 'n_tokens_neox': 1476, 'n_words': 316}