<commit_before>import Ember from 'ember';
import startApp from '../helpers/start-app';

var App;

module('Acceptance: Demos', {
  setup: function() {
    App = startApp();
  },
  teardown: function() {
    Ember.run(App, 'destroy');
  }
});

test('visit every link in sidebar', function() {
  var lastRouteName = 'transitions.primitives.index';
  expect(1);

  function navigateForward() {
    var forward = find('.nav-link.forward a');
    if (forward.length > 0) {
      click('.nav-link.forward a');
      andThen(navigateForward);
    } else {
      equal(currentRouteName(), lastRouteName);
    }
  }

  visit('/');
  andThen(navigateForward);
});

test('liquid outlet demo', function() {
  visit('/helpers/liquid-outlet');
  andThen(function(){
    equal(currentRouteName(), 'helpers-documentation.liquid-outlet.index');
    equal(find('.demo-container a').text(), 'Click me!');
  });
  click('.demo-container a');
  andThen(function(){
    equal(currentRouteName(), 'helpers-documentation.liquid-outlet.other');
    equal(find('.demo-container a').text(), 'Go back!');
  });
  click('.demo-container a');
  andThen(function(){
    equal(currentRouteName(), 'helpers-documentation.liquid-outlet.index');
    equal(find('.demo-container a').text(), 'Click me!');
  });
});

test('liquid with demo', function() {
  visit('/helpers/liquid-with');
  andThen(function(){
    equal(currentRouteName(), 'helpers-documentation.liquid-with.page');
    ok(/\b1\b/.test(find('.demo-container').text()), 'Has 1');
  });
  click('.demo-container button');
  andThen(function(){
    equal(currentRouteName(), 'helpers-documentation.liquid-with.page');
    ok(/\b2\b/.test(find('.demo-container').text()), 'Has 2');
  });
});

test('liquid bind demo', function() {
  var first, second;
  function clock() {
    var m = /(\d\d)\s*:\s*(\d\d)\s*:\s*(\d\d)/.exec($('#liquid-bind-demo').text());
    ok(m, "Read the clock");
    return parseInt(m[3]);
  }

  visit('/helpers/liquid-bind');
  andThen(function(){
    equal(currentRouteName(), 'helpers-documentation.liquid-bind');
    first = clock();
    Ember.run(function(){
      Ember.run.later(function(){
        second = clock();
        notEqual(first, second, "clock readings differ, " + first + ", " + second);
      }, 2000);
    });
  });
});<commit_msg>finish demo acceptance tests<commit_after>import Ember from 'ember';
import startApp from '../helpers/start-app';

var App;

module('Acceptance: Demos', {
  setup: function() {
    App = startApp();
  },
  teardown: function() {
    Ember.run(App, 'destroy');
  }
});

function classFound(name) {
  equal(find('.'+name).length, 1, 'found ' + name);
}

function clickWithoutWaiting(selector, text) {
  find(selector).filter(function() {
    return $(this).text() === text;
  }).click();
}

test('visit every link in sidebar', function() {
  var lastRouteName = 'transitions.primitives.index';
  expect(1);

  function navigateForward() {
    var forward = find('.nav-link.forward a');
    if (forward.length > 0) {
      click('.nav-link.forward a');
      andThen(navigateForward);
    } else {
      equal(currentRouteName(), lastRouteName);
    }
  }

  visit('/');
  andThen(navigateForward);
});

test('liquid outlet demo', function() {
  visit('/helpers/liquid-outlet');
  andThen(function(){
    equal(currentRouteName(), 'helpers-documentation.liquid-outlet.index');
    equal(find('.demo-container a').text(), 'Click me!');
  });
  click('.demo-container a');
  andThen(function(){
    equal(currentRouteName(), 'helpers-documentation.liquid-outlet.other');
    equal(find('.demo-container a').text(), 'Go back!');
  });
  click('.demo-container a');
  andThen(function(){
    equal(currentRouteName(), 'helpers-documentation.liquid-outlet.index');
    equal(find('.demo-container a').text(), 'Click me!');
  });
});

test('liquid with demo', function() {
  visit('/helpers/liquid-with');
  andThen(function(){
    ok(/\b1\b/.test(find('.demo-container').text()), 'Has 1');
  });
  click('.demo-container button');
  andThen(function(){
    ok(/\b2\b/.test(find('.demo-container').text()), 'Has 2');
  });
});

test('liquid bind demo', function() {
  var first, second;
  function clock() {
    var m = /(\d\d)\s*:\s*(\d\d)\s*:\s*(\d\d)/.exec($('#liquid-bind-demo').text());
    ok(m, "Read the clock");
    return parseInt(m[3]);
  }

  visit('/helpers/liquid-bind');
  andThen(function(){
    first = clock();
    Ember.run.later(function(){
      second = clock();
      notEqual(first, second, "clock readings differ, " + first + ", " + second);
    }, 2000);
  });
});

test('liquid if demo', function() {
  visit('/helpers/liquid-if');
  andThen(function(){
    equal(find('#liquid-box-demo input[type=checkbox]').length, 1, "found checkbox");
    equal(find('#liquid-box-demo input[type=text]').length, 0, "no text input");
    find('select').val('car').trigger('change');
  });
  andThen(function(){
    equal(find('#liquid-box-demo input[type=checkbox]').length, 0, "no more checkbox");
    equal(find('#liquid-box-demo input[type=text]').length, 1, "has text input");
  });
});


test('interruption demo, normal transition', function() {
  visit('/transitions/primitives');
  andThen(function(){
    classFound('one');
    clickWithoutWaiting('#interrupted-fade-demo a', 'Two');
  });
  andThen(function(){
    classFound('two');
  });
});

test('interruption demo, early interruption', function() {
  visit('/transitions/primitives');
  andThen(function(){
    classFound('one');
    clickWithoutWaiting('#interrupted-fade-demo a', 'Two');
    Ember.run.later(function(){
      clickWithoutWaiting('#interrupted-fade-demo a', 'Three');
    }, 300);
  });
  andThen(function(){
    classFound('three');
  });
});

test('interruption demo, late interruption', function() {
  visit('/transitions/primitives');
  andThen(function(){
    classFound('one');
    clickWithoutWaiting('#interrupted-fade-demo a', 'Two');
    Ember.run.later(function(){
      classFound('two');
      clickWithoutWaiting('#interrupted-fade-demo a', 'Three');
    }, 1800);
  });
  andThen(function(){
    classFound('three');
  });
});
{'fraction_non_alphanumeric': 0.2132137030995106, 'fraction_numerical': 0.005546492659053833, 'mean_word_length': 3.992671009771987, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '2338651', 'n_tokens_mistral': 2063, 'n_tokens_neox': 1958, 'n_words': 355}