<commit_before>'use strict';

var chai = require('chai');
var chaiAsPromised = require('chai-as-promised');

chai.use(chaiAsPromised);
var expect = chai.expect;

var util = require('./util');

var uuid = require('node-uuid');

var LoginForm = function(){
  this.typeInField = function(field,value){
    return element(by.css('.login-form input[name='+field+']')).sendKeys(value);
  };
  this.submit = function(){
    return element(by.css('button')).submit();
  };
  this.isShowingInvalidLogin = function(){
    return element(by.css('.bad-login')).isDisplayed();
  };
  this.isShowingNotFound = function(){
    return element(by.css('.not-found')).isDisplayed();
  };
  this.isShowingRegistrationLink = function(){
    return element(by.css('[wd-can-register]')).isDisplayed();
  };
  this.hasFacebookButton = function(){
    return element(by.css('.btn-facebook')).isPresent();
  };
  this.hasGoogleButton = function(){
    return element(by.css('.btn-google')).isPresent();
  };
  this.isShowingSocialArea = function(){
    return element(by.css('.social-area')).isDisplayed();
  };
  this.isShowingUsernameField = function(){
    return element(by.css('.login-form input[name=username]')).isDisplayed();
  };
  this.hasSocialArea = function(){
    return browser.isElementPresent(by.css('.social-area'));
  };
  this.isPresent = function(){
    return element(by.css('.login-view')).isDisplayed();
  };
  this.waitForForm = function(){
    var self = this;
    return browser.driver.wait(function(){
      return self.isPresent();
    },10000);
  };
  this.login = function(account){
    this.typeInField('username',account.email);
    this.typeInField('password',account.password);
    this.submit();
  };
  this.submitWithValidCredentials = function submitWithValidCredentials(){
    this.typeInField('username','<EMAIL>');
    this.typeInField('password','<EMAIL>');
    this.submit();
  };
  this.submitWithInvalidCredentials = function submitWithInvalidCredentials(){
    this.typeInField('username','<EMAIL>');
    this.typeInField('password','1');
    this.submit();
  };
  this.submitWithUnknownCredentials = function submitWithUnknownCredentials(){
    this.typeInField('username',uuid());
    this.typeInField('password',uuid());
    this.submit();
  };
};

var LoginApp = require('./page-objects/login-app');

describe('Login view', function() {
  var app = new LoginApp();
  var form = new LoginForm();
  var loginAccount;

  beforeEach(function(done){
    app.arriveWithFacebookAndGoogleIntegrations(function(account){
      loginAccount = account;
      done();
    });
  });

  describe('when loaded', function() {

    it('should have the correct page title', function() {
      expect(app.pageTitle()).to.eventually.equal('Login');
    });
    it('should show the logo image', function() {
      form.waitForForm();
      expect(app.logoImageUrl()).to.eventually.equal(browser.params.logoUrl);
    });
    it('should show the login form', function() {
      form.waitForForm();
      expect(form.isPresent()).to.eventually.equal(true);
    });
    it('should allow me to submit the form', function(){
      form.waitForForm();
      form.login(util.getLoginAccount());
      browser.driver.wait(function() {
        return browser.driver.getCurrentUrl().then(function(url) {
          return url.indexOf(browser.params.callbackUri) > -1;
        });
      }, 10000);
      expect(browser.driver.getCurrentUrl()).to.eventually.contain(browser.params.callbackUri);
    });
  });

  // describe('when loaded with sso config 1 (fb and google)', function() {
  //   var form;

  //   before(function(){
  //     browser.get(
  //       browser.params.appUrl + '#' + util.fakeAuthParams('1')
  //     );
  //     form = new LoginForm();
  //   });
  //   it('should be showing both social buttons', function() {
  //     expect(form.isShowingSocialArea()).to.eventually.equal(true);<commit_msg>more login tests<commit_after>'use strict';

var chai = require('chai');
var chaiAsPromised = require('chai-as-promised');

chai.use(chaiAsPromised);
var expect = chai.expect;

var util = require('./util');

var uuid = require('node-uuid');

var LoginForm = function(){
  this.typeInField = function(field,value){
    return element(by.css('.login-form input[name='+field+']')).sendKeys(value);
  };
  this.submit = function(){
    return element(by.css('button')).submit();
  };
  this.isShowingInvalidLogin = function(){
    return element(by.css('.bad-login')).isDisplayed();
  };
  this.isShowingNotFound = function(){
    return element(by.css('.not-found')).isDisplayed();
  };
  this.isShowingRegistrationLink = function(){
    return element(by.css('[wd-can-register]')).isDisplayed();
  };
  this.hasFacebookButton = function(){
    return element(by.css('.btn-facebook')).isPresent();
  };
  this.hasGoogleButton = function(){
    return element(by.css('.btn-google')).isPresent();
  };
  this.isShowingSocialArea = function(){
    return element(by.css('.social-area')).isDisplayed();
  };
  this.isShowingUsernameField = function(){
    return element(by.css('.login-form input[name=username]')).isDisplayed();
  };
  this.hasSocialArea = function(){
    return browser.isElementPresent(by.css('.social-area'));
  };
  this.isPresent = function(){
    return element(by.css('.login-view')).isDisplayed();
  };
  this.submitIsDisabled = function() {
    return element(by.css('.login-view button[type=submit]')).getAttribute('disabled');
  };
  this.waitForForm = function(){
    /*
      TODO - implenet something in the stormpath.js client
      which keeps track of the "is waiting for a network request"
      state.  then, we can get rid of these wait functions and have
      a common "wait for client" function.
     */
    var self = this;
    return browser.driver.wait(function(){
      return self.isPresent();
    },10000);
  };
  this.waitForLoginAttempt = function(){
    var self = this;
    browser.driver.wait(function(){
      return self.submitIsDisabled().then(function(value) {
        return value === null;
      });
    },10000);
  };
  this.login = function(account){
    this.typeInField('username',account.email);
    this.typeInField('password',account.password);
    this.submit();
  };
  this.submitWithValidCredentials = function submitWithValidCredentials(){
    this.typeInField('username','<EMAIL>');
    this.typeInField('password','<EMAIL>');
    this.submit();
  };
  this.submitWithInvalidCredentials = function submitWithInvalidCredentials(){
    this.typeInField('username','<EMAIL>');
    this.typeInField('password','1');
    this.submit();
  };
  this.submitWithUnknownCredentials = function submitWithUnknownCredentials(){
    this.typeInField('username',uuid());
    this.typeInField('password',uuid());
    this.submit();
  };
};

var LoginApp = require('./page-objects/login-app');

describe('Login view', function() {
  var app = new LoginApp();
  var form = new LoginForm();
  var loginAccount;

  beforeEach(function(done){
    app.arriveWithFacebookAndGoogleIntegrations(function(account){
      loginAccount = account;
      form.waitForForm();
      done();
    });
  });

  describe('when loaded', function() {

    it('should have the correct page title', function() {
      expect(app.pageTitle()).to.eventually.equal('Login');
    });

    it('should show the logo image', function() {
      expect(app.logoImageUrl()).to.eventually.equal(browser.params.logoUrl);
    });

    it('should show the login form', function() {
      expect(form.isPresent()).to.eventually.equal(true);
    });

    it('should allow me to submit the form', function(){
      form.login(util.getLoginAccount());
      browser.driver.wait(function() {
        return browser.driver.getCurrentUrl().then(function(url) {
          return url.indexOf(browser.params.callbackUri) > -1;
        });
      }, 10000);
      expect(browser.driver.getCurrentUrl()).to.eventually.contain(browser.params.callbackUri);
    });

    it('should disable the form while submitting',function(){
      form.login({email:'<EMAIL>',password:'b'});
      // assert that it becomes disabled
      expect(form.submitIsDisabled()).to.eventually.equal('true');
      // then wait for, and assert, that it becomes enabled
      // after the network request is complete
      form.waitForLoginAttempt();
      expect(form.submitIsDisabled()).to.eventually.equal(null);
    });

    it('should show me an error if I enter invalid credentials',function(){
      form.login({email:'<EMAIL>',password:'b'});
      form.waitForLoginAttempt();
      expect(form.isShowingInvalidLogin()).to.eventually.equal(true);
    });
  });

  // describe('when loaded with sso config 1 (fb and google)', function() {
  //   var form;

  //   before(function(){
  //     browser.get(
  //       browser.params.appUrl + '#' + util.fakeAuthParams('1')
  //     );
  //     form = new LoginForm();
  //   });
  //   it('should be showing both social buttons', function() {
  //     expect(form.isShowingSocialArea()).to.eventually.equal(true);
{'fraction_non_alphanumeric': 0.17121697800375815, 'fraction_numerical': 0.0036476179949154414, 'mean_word_length': 3.719874804381847, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3067775', 'n_tokens_mistral': 2705, 'n_tokens_neox': 2692, 'n_words': 481}