<commit_before>import Ember from 'ember';
import { moduleForComponent, test } from 'ember-qunit';
import hbs from 'htmlbars-inline-precompile';
const { $, run } = Ember;

moduleForComponent('ember-flatpickr', 'Integration | Component | ember flatpickr', {
  integration: true,
  afterEach() {
    $('.flatpickr-wrapper').remove();
  }
});

function closeFlatpickr() {
  document.dispatchEvent(new Event('click'));
}

test('onChangeAction fired', function(assert) {
  let expected = '2016-12-27T16:16:22.585Z';
  this.on('onChange', (actual) => {
    assert.equal(actual.toISOString(), expected, 'onChangeAction was executed');
  });

  this.set('maxDate', '2016-12-31T16:16:22.585Z');
  this.set('minDate', '2016-12-01T16:16:22.585Z');

  this.render(
    hbs`{{ember-flatpickr
      appendDataInput=true
      defaultDate='2016-12-27T16:16:22.585Z'
      enableTime=true
      maxDate=maxDate
      minDate=minDate
      onChangeAction="onChange"
      placeholder="Pick date"
      value=(mut dateValue)
      }}`);

  run(function() {
    expected = '2016-12-01T16:16:00.000Z';
    this.$('.flatpickr-input')[0].dispatchEvent(new Event('focus'));
    this.$('.flatpickr-days .slot').first().click();
  });
});

test('onCloseAction fired', function(assert) {
  this.on('onClose', () => {
    assert.ok(true, 'onCloseAction was executed');
  });

  this.set('maxDate', '2016-12-31T16:16:22.585Z');
  this.set('minDate', '2016-12-01T16:16:22.585Z');

  this.render(
    hbs`{{ember-flatpickr
      appendDataInput=true
      defaultDate='2016-12-27T16:16:22.585Z'
      enableTime=true
      maxDate=maxDate
      minDate=minDate
      onCloseAction="onClose"
      placeholder="Pick date"
      value=(mut dateValue)
      }}`);

  run(function() {
    this.$('.flatpickr-input')[0].dispatchEvent(new Event('focus'));
    closeFlatpickr();
  });
});

test('maxDateUpdated and minDateUpdated fired', function(assert) {
  this.render(
    hbs`{{ember-flatpickr
      appendDataInput=true
      defaultDate='2016-12-27T16:16:22.585Z'
      enableTime=true
      maxDate=maxDate
      minDate=minDate
      onCloseAction="onClose"
      placeholder="Pick date"
      value=(mut dateValue)
      }}`);

  this.set('maxDate', '2016-12-25T16:16:22.585Z');
  this.set('minDate', '2016-12-24T16:16:22.585Z');

  run(function() {
    this.$('.flatpickr-input')[0].dispatchEvent(new Event('focus'));
    run.scheduleOnce('afterRender', this, function() {
      let enabledDays = this.$('.flatpickr-days .slot');
      assert.equal(enabledDays.length, 2);
      assert.equal(enabledDays.text(), '2425');
    });
  });
});
<commit_msg>Fix tests<commit_after>import Ember from 'ember';
import { moduleForComponent, test } from 'ember-qunit';
import hbs from 'htmlbars-inline-precompile';
const { $, run } = Ember;

moduleForComponent('ember-flatpickr', 'Integration | Component | ember flatpickr', {
  integration: true,
  afterEach() {
    $('.flatpickr-wrapper').remove();
  }
});

function closeFlatpickr() {
  document.dispatchEvent(new Event('click'));
}

test('onChange action fired', function(assert) {
  let expected = '2016-12-27T16:16:22.585Z';
  this.on('onChange', (actual) => {
    assert.equal(actual.toISOString(), expected, 'onChange action was executed');
  });

  this.set('maxDate', '2016-12-31T16:16:22.585Z');
  this.set('minDate', '2016-12-01T16:16:22.585Z');

  this.render(
    hbs`{{ember-flatpickr
      appendDataInput=true
      defaultDate='2016-12-27T16:16:22.585Z'
      enableTime=true
      maxDate=maxDate
      minDate=minDate
      onChange="onChange"
      placeholder="Pick date"
      value=(mut dateValue)
      }}`);

  run(function() {
    expected = '2016-12-01T16:16:00.000Z';
    this.$('.flatpickr-input')[0].dispatchEvent(new Event('focus'));
    this.$('.flatpickr-days .slot').first().click();
  });
});

test('onClose action fired', function(assert) {
  this.on('onClose', () => {
    assert.ok(true, 'onClose action was executed');
  });

  this.set('maxDate', '2016-12-31T16:16:22.585Z');
  this.set('minDate', '2016-12-01T16:16:22.585Z');

  this.render(
    hbs`{{ember-flatpickr
      appendDataInput=true
      defaultDate='2016-12-27T16:16:22.585Z'
      enableTime=true
      maxDate=maxDate
      minDate=minDate
      onChange=null
      onClose="onClose"
      placeholder="Pick date"
      value=(mut dateValue)
      }}`);

  run(function() {
    this.$('.flatpickr-input')[0].dispatchEvent(new Event('focus'));
    closeFlatpickr();
  });
});

test('maxDateUpdated and minDateUpdated fired', function(assert) {
  this.render(
    hbs`{{ember-flatpickr
      appendDataInput=true
      defaultDate='2016-12-27T16:16:22.585Z'
      enableTime=true
      maxDate=maxDate
      minDate=minDate
      onChange=null
      onClose="onClose"
      placeholder="Pick date"
      value=(mut dateValue)
      }}`);

  this.set('maxDate', '2016-12-25T16:16:22.585Z');
  this.set('minDate', '2016-12-24T16:16:22.585Z');

  run(function() {
    this.$('.flatpickr-input')[0].dispatchEvent(new Event('focus'));
    run.scheduleOnce('afterRender', this, function() {
      let enabledDays = this.$('.flatpickr-days .slot');
      assert.equal(enabledDays.length, 2);
      assert.equal(enabledDays.text(), '2425');
    });
  });
});

{'fraction_non_alphanumeric': 0.17957479119210326, 'fraction_numerical': 0.07403189066059225, 'mean_word_length': 3.696078431372549, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '367797', 'n_tokens_mistral': 2071, 'n_tokens_neox': 1826, 'n_words': 263}