<commit_before>import { Simulate } from 'react-addons-test-utils';
import { stub } from 'sinon';
import { Map } from 'immutable';
import Auth0Lock from '../../src/index';
import webApi from '../../src/core/web_api';
import * as gravatarProvider from '../../src/avatar/gravatar_provider';
import * as ClientSettings from '../../src/core/client/settings';
import clientSettings from './client_settings';
import * as SSOData from '../../src/core/sso/data';
import ssoData from './sso_data';

// stub, mock and spy

export const stubWebApis = () => {
  stub(webApi, "logIn").returns(undefined);
  stub(gravatarProvider, "displayName", (email, cb) => {
    cb(null, "someone");
  });
  stub(gravatarProvider, "url", (email, cb) => {
    cb(null, "https://www.gravatar.com/avatar/35b47dce0e2c9ced8b500dca20e1a657.png?size=160");
  });
  stub(ClientSettings, "fetchClientSettings", (...args) => {
    args[args.length - 1](null, clientSettings);
  });
  stub(SSOData, "fetchSSOData", (id, withAD, cb) => {
    cb(null, withAD ? { connection: {}, ...ssoData } : ssoData);
  });
}

export const restoreWebApis = () => {
  webApi.logIn.restore();
  gravatarProvider.displayName.restore();
  gravatarProvider.url.restore();
  ClientSettings.fetchClientSettings.restore();
  SSOData.fetchSSOData.restore();
}

// api call checks

export const wasLoginAttemptedWith = params => {
  const lastCall = webApi.logIn.lastCall;
  if (!lastCall) return false;
  const paramsFromLastCall = lastCall.args[1];
  return Map(params).reduce(
    (r, v, k) => r && paramsFromLastCall[k] === v,
    true
  );
};

// rendering

export const displayLock = (name, opts = {}, done = () => {}) => {
  switch(name) {
  case "enterprise and corporate":
    opts.allowedConnections = ["auth0.com", "rolodato.com"];
    break;
  case "single database":
    opts.allowedConnections = ["db"];
    break;
  case "single enterprise":
    opts.allowedConnections = ["auth0.com"];
    break;
  case "multiple enterprise":
    opts.allowedConnections = ["auth0.com", "auth10.com"];
    break;
  case "single corporate":
    opts.allowedConnections = ["rolodato.com"];
    break;
  case "multiple corporate, one without domain":
    opts.allowedConnections = ["rolodato.com", "corporate-no-domain"];
    break;
  case "multiple social":
    opts.allowedConnections = ["facebook", "twitter", "github"];
    break;
  case "kerberos":
    opts.allowedConnections = ["rolodato.com"];
    break;
  }

  const lock = new Auth0Lock("cid", "domain", opts);
  setTimeout(() => lock.show(), 70);
  setTimeout(done, 75);
  return lock;
};


// queries

const q = (lock, query, all = false) => {
  query = `#auth0-lock-container-${lock.id} ${query}`;
  const method = all ? "querySelectorAll" : "querySelector";
  return global.document[method](query);
};

const qView = (lock, query, all = false) => {
  // NOTE: When an animation is running, two views will be in the
  // DOM. Both are siblings, and the one that is entering (that is,
  // the one that will remain visible) is always the first sibling.
  const view = q(lock, ".auth0-lock-view-content");
  const method = all ? "querySelectorAll" : "querySelector";
  return view ? view[method](query) : null;
};

export function qInput(lock, name, ensure = false) {
  const input = qView(lock, `.auth0-lock-input-${name} input`);
  if (ensure && !input) {
    throw new Error(`Unable to query the '${name}' input value: can't find the input`);
  }
  return input;
}
<commit_msg>Increase delays in test for travis<commit_after>import { Simulate } from 'react-addons-test-utils';
import { stub } from 'sinon';
import { Map } from 'immutable';
import Auth0Lock from '../../src/index';
import webApi from '../../src/core/web_api';
import * as gravatarProvider from '../../src/avatar/gravatar_provider';
import * as ClientSettings from '../../src/core/client/settings';
import clientSettings from './client_settings';
import * as SSOData from '../../src/core/sso/data';
import ssoData from './sso_data';

// stub, mock and spy

export const stubWebApis = () => {
  stub(webApi, "logIn").returns(undefined);
  stub(gravatarProvider, "displayName", (email, cb) => {
    cb(null, "someone");
  });
  stub(gravatarProvider, "url", (email, cb) => {
    cb(null, "https://www.gravatar.com/avatar/35b47dce0e2c9ced8b500dca20e1a657.png?size=160");
  });
  stub(ClientSettings, "fetchClientSettings", (...args) => {
    args[args.length - 1](null, clientSettings);
  });
  stub(SSOData, "fetchSSOData", (id, withAD, cb) => {
    cb(null, withAD ? { connection: {}, ...ssoData } : ssoData);
  });
}

export const restoreWebApis = () => {
  webApi.logIn.restore();
  gravatarProvider.displayName.restore();
  gravatarProvider.url.restore();
  ClientSettings.fetchClientSettings.restore();
  SSOData.fetchSSOData.restore();
}

// api call checks

export const wasLoginAttemptedWith = params => {
  const lastCall = webApi.logIn.lastCall;
  if (!lastCall) return false;
  const paramsFromLastCall = lastCall.args[1];
  return Map(params).reduce(
    (r, v, k) => r && paramsFromLastCall[k] === v,
    true
  );
};

// rendering

export const displayLock = (name, opts = {}, done = () => {}) => {
  switch(name) {
  case "enterprise and corporate":
    opts.allowedConnections = ["auth0.com", "rolodato.com"];
    break;
  case "single database":
    opts.allowedConnections = ["db"];
    break;
  case "single enterprise":
    opts.allowedConnections = ["auth0.com"];
    break;
  case "multiple enterprise":
    opts.allowedConnections = ["auth0.com", "auth10.com"];
    break;
  case "single corporate":
    opts.allowedConnections = ["rolodato.com"];
    break;
  case "multiple corporate, one without domain":
    opts.allowedConnections = ["rolodato.com", "corporate-no-domain"];
    break;
  case "multiple social":
    opts.allowedConnections = ["facebook", "twitter", "github"];
    break;
  case "kerberos":
    opts.allowedConnections = ["rolodato.com"];
    break;
  }

  const lock = new Auth0Lock("cid", "domain", opts);
  setTimeout(() => lock.show(), 100);
  setTimeout(done, 105);
  return lock;
};


// queries

const q = (lock, query, all = false) => {
  query = `#auth0-lock-container-${lock.id} ${query}`;
  const method = all ? "querySelectorAll" : "querySelector";
  return global.document[method](query);
};

const qView = (lock, query, all = false) => {
  // NOTE: When an animation is running, two views will be in the
  // DOM. Both are siblings, and the one that is entering (that is,
  // the one that will remain visible) is always the first sibling.
  const view = q(lock, ".auth0-lock-view-content");
  const method = all ? "querySelectorAll" : "querySelector";
  return view ? view[method](query) : null;
};

export function qInput(lock, name, ensure = false) {
  const input = qView(lock, `.auth0-lock-input-${name} input`);
  if (ensure && !input) {
    throw new Error(`Unable to query the '${name}' input value: can't find the input`);
  }
  return input;
}

{'fraction_non_alphanumeric': 0.16812508965715106, 'fraction_numerical': 0.010615406684837183, 'mean_word_length': 3.841666666666667, 'pattern_counts': {'":': 16, '<': 3, '<?xml version=': 0, '>': 29, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '5586011', 'n_tokens_mistral': 2284, 'n_tokens_neox': 2279, 'n_words': 587}