<commit_before>/**
 * login.js
 * Test that a user can authenticate correctly.
 */


casper.test.begin('Tests login flow', 5, function suite(test) {
   casper.start(url, function() {
    test.assertTitle("DoSomething.org | Largest organization for teens and social cause", "Dosomething.org homepage title is the one expected");
    test.assertExists('#modal--login', 'login link is there');

   });

   // Let's try a fake address first.
   casper.thenOpen(url + '/user', function() {
     this.echo("Try a fake email/password combo.");
     this.fill('form[action="/user/login"]', {
       name: '<EMAIL>',
       pass: '<PASSWORD>'
     }, true);
   });

   casper.waitForSelector('.messages', function() {
     test.assertExists('div.error', 'Error message appears on screen');
     this.echo(this.fetchText('.messages'));
   })

   casper.login();

   casper.then(function() {
     test.assertExists('.profile--campaigns', 'Has a user profile');
     test.assertDoesntExist('#modal--login', '"Login" link is not found.');
   });

  casper.logout();

  casper.run(function() {
      test.done();
  });
});
<commit_msg>Modify login test to use the modal, rather than standalone page.<commit_after>/**
 * login.js
 * Test that a user can authenticate correctly.
 */

casper.test.begin('Test that a user can authenticate correctly.', 6, function suite(test) {
  casper.start(url, function() {
    test.assertTitle("DoSomething.org | Largest organization for teens and social cause", "Homepage has expected title");

    // We reference the login link's ID to avoid a crazy selector.
    test.assertExists("#link--login", "Login link exists on page for anonymous user");
  });

  casper.then(function() {
    // Click the login link in the header navigation menu.
    this.click("#link--login");

    // We should see a modal with the login form.
    this.waitUntilVisible(".modal-content", function() {
      test.assertExists(".modal-content form[action='/user/login']", "Clicking the login link shows modal login form");
    });
  });

  casper.then(function() {
    // Fill and submit bogus login credentials:
    this.fill('form[action="/user/login"]', {
      name: '<EMAIL>',
      pass: '<PASSWORD>'
    }, true);

    // We should get a specific error message.
    casper.waitForSelector('.messages', function() {
      test.assertSelectorHasText("div.error", "unrecognized username or password", "Error message appears after submitting invalid credentials");
    });
  });

  casper.thenOpen(url, function() {
    // Now let's go back home and login using the login modal.
    this.click("#link--login");
    
    // We should see a modal with the login form.
    this.waitUntilVisible(".modal-content", function() {
      this.fill('form[action="/user/login"]', {
        name: '<EMAIL>',
        pass: '<PASSWORD>'
      }, true);
    });

    this.waitUntilVisible("#link--logout", function() {
      test.assertExists("#link--logout", "Logout link is shown for logged in users");
    });
  });

  casper.thenOpen(url, function() {
    // Let's log out using the logout button.
    this.click("#link--logout");
    
    this.waitUntilVisible("#link--login", function() {
      test.assertExists("#link--login", "Login link is shown again after logging out");
    });
  });

  casper.run(function() {
    test.done();
  });
});

{'fraction_non_alphanumeric': 0.15992812219227315, 'fraction_numerical': 0.0005989817310572028, 'mean_word_length': 3.217171717171717, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, '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': '3471720', 'n_tokens_mistral': 987, 'n_tokens_neox': 958, 'n_words': 276}