<commit_before>/*globals EMBER_APP_BEING_TESTED */

var Promise = Ember.RSVP.Promise,
    pendingAjaxRequests = 0;

function visit(url) {
  var promise = new Promise();
  Ember.run(EMBER_APP_BEING_TESTED, EMBER_APP_BEING_TESTED.handleURL, url);
  wait(promise, promise.resolve);
  return promise;
}

function click(selector) {
  var promise = new Promise();
  Ember.run(function() {
    Ember.$(selector).click();
  });
  wait(promise, promise.resolve);
  return promise;
}

function fillIn(selector, text) {
  var promise = new Promise();
  var $el = find(selector);
  Ember.run(function() {
    $el.val(text);
    $el.simulate('keyup', {keyCode: 13});
  });

  Ember.run(function() {
    $el.simulate('keyup', {keyCode: 13}); // hit enter
  });
  wait(promise, promise.resolve);
  return promise;
}

function find(selector) {
  return Ember.$('.ember-application').find(selector);
}

function wait(target, method) {
  if (!method) {
    method = target;
    target = null;
  }
  stop();
  var watcher = setInterval(function() {
    var routerIsLoading = EMBER_APP_BEING_TESTED.__container__.lookup('router:main').router.isLoading;
    if (routerIsLoading) { return; }
    if (pendingAjaxRequests) { return; }
    if (Ember.run.hasScheduledTimers() || Ember.run.currentRunLoop) { return; }
    clearInterval(watcher);
    start();
    Ember.run(target, method);
  }, 200);
}

Ember.Application.reopen({
  setupForTesting: function() {
    this.deferReadiness();

    this.Router.reopen({
      location: 'none'
    });

    window.EMBER_APP_BEING_TESTED = this;
  },

  injectTestHelpers: function() {
    Ember.$.ajaxStart = function() {
      pendingAjaxRequests++;
    };

    Ember.$.ajaxStop = function() {
      pendingAjaxRequests--;
    };

    window.visit = visit;
    window.click = click;
    window.fillIn = fillIn;
    window.find = find;
  }
});<commit_msg>Fix a couple issues<commit_after>/*globals EMBER_APP_BEING_TESTED */

var Promise = Ember.RSVP.Promise,
    pendingAjaxRequests = 0;

function visit(url) {
  var promise = new Promise();
  Ember.run(EMBER_APP_BEING_TESTED, EMBER_APP_BEING_TESTED.handleURL, url);
  wait(promise, promise.resolve);
  return promise;
}

function click(selector) {
  var promise = new Promise();
  Ember.run(function() {
    Ember.$(selector).click();
  });
  wait(promise, promise.resolve);
  return promise;
}

function fillIn(selector, text) {
  var promise = new Promise();
  var $el = find(selector);
  Ember.run(function() {
    $el.val(text);
  });

  wait(promise, promise.resolve);
  return promise;
}

function find(selector) {
  return Ember.$('.ember-application').find(selector);
}

function wait(target, method) {
  if (!method) {
    method = target;
    target = null;
  }
  stop();
  var watcher = setInterval(function() {
    var routerIsLoading = EMBER_APP_BEING_TESTED.__container__.lookup('router:main').router.isLoading;
    if (routerIsLoading) { return; }
    if (pendingAjaxRequests) { return; }
    if (Ember.run.hasScheduledTimers() || Ember.run.currentRunLoop) { return; }
    clearInterval(watcher);
    start();
    Ember.run(target, method);
  }, 200);
}

Ember.Application.reopen({
  setupForTesting: function() {
    this.deferReadiness();

    this.Router.reopen({
      location: 'none'
    });

    window.EMBER_APP_BEING_TESTED = this;
  },

  injectTestHelpers: function() {
    Ember.$.ajaxStart(function() {
      pendingAjaxRequests++;
    });

    Ember.$.ajaxStop(function() {
      pendingAjaxRequests--;
    });

    window.visit = visit;
    window.click = click;
    window.fillIn = fillIn;
    window.find = find;
  }
});
{'fraction_non_alphanumeric': 0.15019326339039205, 'fraction_numerical': 0.0033130866924351186, 'mean_word_length': 3.5918884664131814, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5756574', 'n_tokens_mistral': 1246, 'n_tokens_neox': 1237, 'n_words': 226}