{"size": 2238, "ext": "js", "max_stars_repo_path": "alien4cloud-ui/yo/test/e2e/authentication/authentication.js", "max_stars_repo_name": "igorng/alien4cloud", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "alien4cloud-ui/yo/test/e2e/authentication/authentication.js", "max_issues_repo_name": "igorng/alien4cloud", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "alien4cloud-ui/yo/test/e2e/authentication/authentication.js", "max_forks_repo_name": "igorng/alien4cloud", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 21.7281553398, "max_line_length": 83, "alphanum_fraction": 0.655049151}
/**
 * Module that exposes functions to login - logout and re-login with various users.
 */

/* global by, element */

'use strict';

//users
var users = {
  admin: {
    username: 'admin',
    password: 'admin',
    registered: true
  },
  componentManager: {
    username: 'componentManager',
    password: 'componentManager',
    registered: true
  },
  componentBrowser: {
    username: 'componentBrowser',
    password: 'componentBrowser',
    registered: true
  },
  architect: {
    username: 'architect',
    password: 'architect',
    registered: true
  },
  applicationManager: {
    username: 'applicationManager',
    password: 'applicationManager',
    registered: true
  },
  user: {
    username: 'user',
    password: 'user',
    registered: true
  },
  badUser: {
    username: 'toto',
    password: 'tata',
    registered: false
  },
  sauron: {
    username: 'sauron',
    password: 'sauron',
    firstName: 'Mairon',
    lastName: 'L\'admirable',
    email: 'mairon@aule.forge.nz',
    registered: false
  },
  bilbo: {
    username: 'bilbo',
    password: 'bilbo',
    firstName: 'Bilbo',
    lastName: 'Baggins',
    email: 'bilbo@baggins.nz',
    registered: false
  }
};

module.exports.users = users;

function logout() {
  // Right dropdown menu
  var navBarRightDrop = browser.element(by.id('navbar-rightdrop'));
  browser.actions().click(navBarRightDrop).perform();
  browser.waitForAngular().then(function wait() {
    // Logout action
    var btnLogout = browser.element(by.name('btn-logout'));
    browser.actions().click(btnLogout).perform();
//    browser.waitForAngular();
  });

}

function login(username) {
  var user = users[username];
  // Setting the model
  var userInput = element(by.model('login.username'));
  userInput.clear();
  userInput.sendKeys(user.username);
  var pwdInput = element(by.model('login.password'));
  pwdInput.clear();
  pwdInput.sendKeys(user.password);

  // Login click action
  var btnLogin = browser.element(by.name('btn-login'));
  browser.actions().click(btnLogin).perform();
  browser.waitForAngular();
}

function reLogin(username) {
  logout();
  login(username);
}

module.exports.login = login;
module.exports.logout = logout;
module.exports.reLogin = reLogin;
