<commit_before>import CodeMirror from 'codemirror';
import Ember from 'ember';
import { moduleForComponent, test } from 'ember-qunit';

moduleForComponent('ivy-codemirror', {
  unit: true
});

test('should update value property when CodeMirror changes', function(assert) {
  var component = this.subject();
  this.render();

  var codeMirror = component.get('codeMirror');

  Ember.run(function() {
    codeMirror.setValue('1 + 1');
    CodeMirror.signal(codeMirror, 'change', codeMirror);
  });

  assert.equal(component.get('value'), '1 + 1', 'value is updated');
});

test('should update CodeMirror value when value property is changed', function(assert) {
  var component = this.subject();
  this.render();

  var codeMirror = component.get('codeMirror');
  assert.equal(codeMirror.getValue(), '', 'precond - value is empty');

  Ember.run(function() {
    component.set('value', '1 + 1');
  });

  assert.equal(codeMirror.getValue(), '1 + 1', 'value is updated');
});

function optionTest(key, beforeValue, afterValue) {
  test('should update CodeMirror ' + key + ' option when ' + key + ' property changes', function(assert) {
    var component = this.subject();
    this.render();

    var codeMirror = component.get('codeMirror');
    assert.equal(
      codeMirror.getOption(key), beforeValue,
      'precond - initial value of ' + key + ' option is correct');

    Ember.run(function() {
      component.set(key, afterValue);
    });

    assert.equal(
      codeMirror.getOption(key), afterValue,
      key + ' option is updated after ' + key + ' property is changed');
  });

  test('should update CodeMirror ' + key + ' option when bound to a property whose dependencies change', function(assert) {
    var context = Ember.Object.createWithMixins({
      actualValue: beforeValue,
      computedValue: Ember.computed.readOnly('actualValue')
    });

    var componentOptions = { foo: context };
    componentOptions[key + 'Binding'] = 'foo.computedValue';
    var component = this.subject(componentOptions);
    this.render();

    var codeMirror = component.get('codeMirror');
    assert.equal(
      codeMirror.getOption(key), beforeValue,
      'precond - initial value of ' + key + ' option is correct');

    Ember.run(function() {
      context.set('actualValue', afterValue);
    });

    assert.equal(
      codeMirror.getOption(key), afterValue,
      key + ' option is updated after ' + key + ' property is changed');
  });
}

optionTest('autofocus', false, true);
optionTest('coverGutterNextToScrollbar', false, true);
optionTest('electricChars', true, false);
optionTest('extraKeys', null, 'basic');
optionTest('firstLineNumber', 1, 2);
optionTest('fixedGutter', true, false);
optionTest('historyEventDelay', 1250, 500);
optionTest('indentUnit', 2, 4);
optionTest('indentWithTabs', false, true);<commit_msg>Remove use of (deprecated) Ember.Object.createWithMixins.<commit_after>import CodeMirror from 'codemirror';
import Ember from 'ember';
import { moduleForComponent, test } from 'ember-qunit';

moduleForComponent('ivy-codemirror', {
  unit: true
});

test('should update value property when CodeMirror changes', function(assert) {
  var component = this.subject();
  this.render();

  var codeMirror = component.get('codeMirror');

  Ember.run(function() {
    codeMirror.setValue('1 + 1');
    CodeMirror.signal(codeMirror, 'change', codeMirror);
  });

  assert.equal(component.get('value'), '1 + 1', 'value is updated');
});

test('should update CodeMirror value when value property is changed', function(assert) {
  var component = this.subject();
  this.render();

  var codeMirror = component.get('codeMirror');
  assert.equal(codeMirror.getValue(), '', 'precond - value is empty');

  Ember.run(function() {
    component.set('value', '1 + 1');
  });

  assert.equal(codeMirror.getValue(), '1 + 1', 'value is updated');
});

function optionTest(key, beforeValue, afterValue) {
  test('should update CodeMirror ' + key + ' option when ' + key + ' property changes', function(assert) {
    var component = this.subject();
    this.render();

    var codeMirror = component.get('codeMirror');
    assert.equal(
      codeMirror.getOption(key), beforeValue,
      'precond - initial value of ' + key + ' option is correct');

    Ember.run(function() {
      component.set(key, afterValue);
    });

    assert.equal(
      codeMirror.getOption(key), afterValue,
      key + ' option is updated after ' + key + ' property is changed');
  });

  test('should update CodeMirror ' + key + ' option when bound to a property whose dependencies change', function(assert) {
    var context = Ember.Object.extend({
      computedValue: Ember.computed.readOnly('actualValue')
    }).create({
      actualValue: beforeValue
    });

    var componentOptions = { foo: context };
    componentOptions[key + 'Binding'] = 'foo.computedValue';
    var component = this.subject(componentOptions);
    this.render();

    var codeMirror = component.get('codeMirror');
    assert.equal(
      codeMirror.getOption(key), beforeValue,
      'precond - initial value of ' + key + ' option is correct');

    Ember.run(function() {
      context.set('actualValue', afterValue);
    });

    assert.equal(
      codeMirror.getOption(key), afterValue,
      key + ' option is updated after ' + key + ' property is changed');
  });
}

optionTest('autofocus', false, true);
optionTest('coverGutterNextToScrollbar', false, true);
optionTest('electricChars', true, false);
optionTest('extraKeys', null, 'basic');
optionTest('firstLineNumber', 1, 2);
optionTest('fixedGutter', true, false);
optionTest('historyEventDelay', 1250, 500);
optionTest('indentUnit', 2, 4);
optionTest('indentWithTabs', false, true);
{'fraction_non_alphanumeric': 0.14930859443374758, 'fraction_numerical': 0.006651496586732014, 'mean_word_length': 4.204007285974499, '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': '2880612', 'n_tokens_mistral': 1744, 'n_tokens_neox': 1642, 'n_words': 424}