<commit_before>import Ember from 'ember';
import connect from 'ember-redux/components/connect';
import hbs from 'htmlbars-inline-precompile';
import { moduleForComponent, test } from 'ember-qunit';

moduleForComponent('count-list', 'integration: connect test', {
  integration: true,
  setup() {
    this.inject.service('redux');
  }
});

test('should render parent component with one state and child component with another', function(assert) {
  this.render(hbs`{{count-list}}`);
  let $parent = this.$('.parent-state');
  let $child = this.$('.child-state');
  assert.equal($parent.text(), 0);
  assert.equal($child.text(), 9);
  Ember.run(() => {
    this.$('.btn-up').trigger('click');
  });
  assert.equal($parent.text(), 1);
  assert.equal($child.text(), 9);
  Ember.run(() => {
    this.$('.btn-up').trigger('click');
  });
  assert.equal($parent.text(), 2);
  assert.equal($child.text(), 9);
  Ember.run(() => {
    this.$('.btn-down').trigger('click');
  });
  assert.equal($parent.text(), 2);
  assert.equal($child.text(), 8);
  Ember.run(() => {
    this.$('.btn-down').trigger('click');
  });
  assert.equal($parent.text(), 2);
  assert.equal($child.text(), 7);
});

test('should render attrs', function(assert) {
  assert.expect(2);
  this.set('myName', 'Dustin');
  this.render(hbs`{{count-list name=myName}}`);

  assert.equal(this.$('.greeting').text(), 'Welcome back, Dustin!', 'should render attrs provided to component');

  this.set('myName', 'Toran');

  assert.equal(this.$('.greeting').text(), 'Welcome back, Toran!', 'should rerender component if attrs change');
});

test('stateToComputed will provide `this` context that is the component instance (when not using [phat]Arrow function)', function(assert) {
  assert.expect(1);

  this.render(hbs`{{count-list}}`);

  assert.equal(this.$('.serviced').text(), 'true', 'should render the prop provided by component instance');
});

test('stateToComputed can be used with component level CP if notifyPropertyChange invoked during didUpdateAttrs', function(assert) {
  assert.expect(2);

  this.set('dynoNameValue', 'Toran');
  this.render(hbs`{{count-list dynoNameValue=dynoNameValue}}`);

  assert.equal(this.$('.dyno').text(), 'name: Toran', 'should render the local component value');

  this.set('dynoNameValue', 'Tom');

  assert.equal(this.$('.dyno').text(), 'name: Tom', 'should render new value when local component CP changed and notifyPropertyChange invoked');
});

test('the component should truly be extended meaning actions map over as you would expect', function(assert) {
  this.render(hbs`{{count-list}}`);
  let $random = this.$('.random-state');
  assert.equal($random.text(), '');
  Ember.run(() => {
    this.$('.btn-random').trigger('click');
  });
  assert.equal($random.text(), 'blue');
});

test('each computed is truly readonly', function(assert) {
  assert.expect(1);
  this.render(hbs`{{count-list}}`);
  try {
    this.$('.btn-alter').trigger('click');
  } catch (e) {
    assert.ok(e.message.indexOf('Cannot set read-only property') > -1);
  }
});

test('lifecycle hooks are still invoked', function(assert) {
  assert.expect(3);<commit_msg>[TESTS]: fixed readOnly assertion for ember 2.11.3<commit_after>import Ember from 'ember';
import connect from 'ember-redux/components/connect';
import hbs from 'htmlbars-inline-precompile';
import { moduleForComponent, test } from 'ember-qunit';

moduleForComponent('count-list', 'integration: connect test', {
  integration: true,
  setup() {
    this.inject.service('redux');
  }
});

test('should render parent component with one state and child component with another', function(assert) {
  this.render(hbs`{{count-list}}`);
  let $parent = this.$('.parent-state');
  let $child = this.$('.child-state');
  assert.equal($parent.text(), 0);
  assert.equal($child.text(), 9);
  Ember.run(() => {
    this.$('.btn-up').trigger('click');
  });
  assert.equal($parent.text(), 1);
  assert.equal($child.text(), 9);
  Ember.run(() => {
    this.$('.btn-up').trigger('click');
  });
  assert.equal($parent.text(), 2);
  assert.equal($child.text(), 9);
  Ember.run(() => {
    this.$('.btn-down').trigger('click');
  });
  assert.equal($parent.text(), 2);
  assert.equal($child.text(), 8);
  Ember.run(() => {
    this.$('.btn-down').trigger('click');
  });
  assert.equal($parent.text(), 2);
  assert.equal($child.text(), 7);
});

test('should render attrs', function(assert) {
  assert.expect(2);
  this.set('myName', 'Dustin');
  this.render(hbs`{{count-list name=myName}}`);

  assert.equal(this.$('.greeting').text(), 'Welcome back, Dustin!', 'should render attrs provided to component');

  this.set('myName', 'Toran');

  assert.equal(this.$('.greeting').text(), 'Welcome back, Toran!', 'should rerender component if attrs change');
});

test('stateToComputed will provide `this` context that is the component instance (when not using [phat]Arrow function)', function(assert) {
  assert.expect(1);

  this.render(hbs`{{count-list}}`);

  assert.equal(this.$('.serviced').text(), 'true', 'should render the prop provided by component instance');
});

test('stateToComputed can be used with component level CP if notifyPropertyChange invoked during didUpdateAttrs', function(assert) {
  assert.expect(2);

  this.set('dynoNameValue', 'Toran');
  this.render(hbs`{{count-list dynoNameValue=dynoNameValue}}`);

  assert.equal(this.$('.dyno').text(), 'name: Toran', 'should render the local component value');

  this.set('dynoNameValue', 'Tom');

  assert.equal(this.$('.dyno').text(), 'name: Tom', 'should render new value when local component CP changed and notifyPropertyChange invoked');
});

test('the component should truly be extended meaning actions map over as you would expect', function(assert) {
  this.render(hbs`{{count-list}}`);
  let $random = this.$('.random-state');
  assert.equal($random.text(), '');
  Ember.run(() => {
    this.$('.btn-random').trigger('click');
  });
  assert.equal($random.text(), 'blue');
});

test('each computed is truly readonly', function(assert) {
  assert.expect(1);
  this.render(hbs`{{count-list}}`);
  Ember.run(() => {
    assert.throws(() => {
      this.$('.btn-alter').trigger('click');
    }, (e) => {
      return e.message.indexOf('Cannot set read-only property') > -1;
    });
  });
});

test('lifecycle hooks are still invoked', function(assert) {
  assert.expect(3);
{'fraction_non_alphanumeric': 0.20810428773362652, 'fraction_numerical': 0.005654154232762682, 'mean_word_length': 4.789090909090909, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 18, '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': '6254850', 'n_tokens_mistral': 2042, 'n_tokens_neox': 2013, 'n_words': 456}