<commit_before>import { moduleForComponent, test } from 'ember-qunit';
import hbs from 'htmlbars-inline-precompile';
import emberVersionGTE from 'ember-test-helpers/has-ember-version';

moduleForComponent('x-toggle', 'Integration | Component | x toggle', {
  integration: true
});

test('it renders', function(assert) {
  this.render(hbs`{{x-toggle}}`);

  assert.equal(this.$().find('div.x-toggle-btn').length, 1);
});

test('changing disabled property disables component', function(assert) {
  this.set('disabled', true);
  this.render(hbs`{{x-toggle
    value='off'
    disabled=disabled
  }}`);
  assert.equal($('input.x-toggle').prop('disabled'), true);
});

test('clicking component triggers onToggle action', function(assert) {
  const done = assert.async();
  this.set('myValue', 'off');
  this.on('onToggle', hash => {
    assert.equal(hash.code, 'toggled', 'onToggle code is toggle');
    assert.equal(hash.oldValue, 'off', 'proper old value');
    assert.equal(hash.newValue, 'on', 'proper new value');

    this.set('completed', true);
    done();
  });
  this.render(hbs`{{x-toggle
    value=myValue
    onToggle=(action 'onToggle')
  }}`);
  this.$('div.x-toggle-btn').click();

  setTimeout(() => {
    if(!this.get('completed')) {
      assert.equal(true, false, 'timed out waiting for toggle event');
      done();
    }
  }, 1000);

});

if (emberVersionGTE(2,0)) {
  test('clicking component works with default on/off and mut helper', function(assert) {
    this.set('value', 'Off');
    this.render(hbs`{{x-toggle
      value=value
      onToggle=(mut value)
    }}`);
    assert.equal(this.get('value'), 'off');
    this.$('div.x-toggle-btn').click();
    assert.equal(this.get('value'), 'on');
  });

  test('component toggles when container changes value', function(assert) {
    this.set('value', 'off');<commit_msg>Fix typo in tests<commit_after>import { moduleForComponent, test } from 'ember-qunit';
import hbs from 'htmlbars-inline-precompile';
import emberVersionGTE from 'ember-test-helpers/has-ember-version';

moduleForComponent('x-toggle', 'Integration | Component | x toggle', {
  integration: true
});

test('it renders', function(assert) {
  this.render(hbs`{{x-toggle}}`);

  assert.equal(this.$().find('div.x-toggle-btn').length, 1);
});

test('changing disabled property disables component', function(assert) {
  this.set('disabled', true);
  this.render(hbs`{{x-toggle
    value='off'
    disabled=disabled
  }}`);
  assert.equal($('input.x-toggle').prop('disabled'), true);
});

test('clicking component triggers onToggle action', function(assert) {
  const done = assert.async();
  this.set('myValue', 'off');
  this.on('onToggle', hash => {
    assert.equal(hash.code, 'toggled', 'onToggle code is toggle');
    assert.equal(hash.oldValue, 'off', 'proper old value');
    assert.equal(hash.newValue, 'on', 'proper new value');

    this.set('completed', true);
    done();
  });
  this.render(hbs`{{x-toggle
    value=myValue
    onToggle=(action 'onToggle')
  }}`);
  this.$('div.x-toggle-btn').click();

  setTimeout(() => {
    if(!this.get('completed')) {
      assert.equal(true, false, 'timed out waiting for toggle event');
      done();
    }
  }, 1000);

});

if (emberVersionGTE(2,0)) {
  test('clicking component works with default on/off and mut helper', function(assert) {
    this.set('value', 'off');
    this.render(hbs`{{x-toggle
      value=value
      onToggle=(mut value)
    }}`);
    assert.equal(this.get('value'), 'off');
    this.$('div.x-toggle-btn').click();
    assert.equal(this.get('value'), 'on');
  });

  test('component toggles when container changes value', function(assert) {
    this.set('value', 'off');
{'fraction_non_alphanumeric': 0.19489685124864278, 'fraction_numerical': 0.003800217155266015, 'mean_word_length': 4.249287749287749, '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': '1560116', 'n_tokens_mistral': 1217, 'n_tokens_neox': 1200, 'n_words': 242}