{"size": 3004, "ext": "js", "max_stars_repo_path": "tests/integration/components/create-comment-form-test.js", "max_stars_repo_name": "rossta/code-corps-ember", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tests/integration/components/create-comment-form-test.js", "max_issues_repo_name": "rossta/code-corps-ember", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tests/integration/components/create-comment-form-test.js", "max_forks_repo_name": "rossta/code-corps-ember", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 32.3010752688, "max_line_length": 123, "alphanum_fraction": 0.6910785619}
import { moduleForComponent, test } from 'ember-qunit';
import hbs from 'htmlbars-inline-precompile';
import Ember from 'ember';
import mockRouting from '../../helpers/mock-routing';
import stubService from 'code-corps-ember/tests/helpers/stub-service';

const {
  $,
  Object
} = Ember;

let mockSession = { isAuthenticated: true };

let pressCtrlEnter = $.Event('keydown', {
  keyCode: 13,
  which: 13,
  ctrlKey: true
});

moduleForComponent('create-comment-form', 'Integration | Component | create comment form', {
  integration: true,
  setup() {
    mockRouting(this);
  }
});

test('it renders', function(assert) {
  assert.expect(1);

  this.render(hbs`{{create-comment-form}}`);
  assert.equal(this.$('form.create-comment-form').length, 1, 'The component\'s element is rendered');
});

test('it yelds to content', function(assert) {
  assert.expect(1);

  stubService(this, 'session', mockSession);

  this.render(hbs`{{#create-comment-form}}Random content{{/create-comment-form}}`);
  let componentTextContent = this.$('form.create-comment-form').text().trim();
  assert.ok(componentTextContent.indexOf('Random content') > -1, 'The provided content is yielded to');
});

test('it renders the proper elements', function(assert) {
  assert.expect(2);

  stubService(this, 'session', mockSession);

  this.set('comment', {});

  this.render(hbs`{{create-comment-form comment=comment}}`);
  assert.equal(this.$('.create-comment-form [name=markdown]').length, 1, 'The markdown input is rendered');
  assert.equal(this.$('.create-comment-form [name=save]').length, 1, 'The save button is rendered');
});

test('it calls action when user clicks submit', function(assert) {
  assert.expect(1);

  stubService(this, 'session', mockSession);

  this.set('comment', Object.create({ markdown: 'Test markdown' }));
  this.on('saveComment', (comment) => {
    assert.equal(comment.markdown, 'Test markdown', 'Action was called with proper parameter');
  });

  this.render(hbs`{{create-comment-form comment=comment saveComment='saveComment'}}`);
  this.$('[name=save]').click();
});

test('it calls action when user hits ctrl+enter', function(assert) {
  assert.expect(1);

  stubService(this, 'session', mockSession);

  this.set('comment', Object.create({ markdown: 'Test markdown' }));
  this.on('saveComment', (comment) => {
    assert.equal(comment.markdown, 'Test markdown', 'Action was called with proper parameter');
  });

  this.render(hbs`{{create-comment-form comment=comment saveComment='saveComment'}}`);
  this.$('textarea').trigger(pressCtrlEnter);
});

test('it renders a sign up button and sign in link when not authenticated', function(assert) {
  assert.expect(3);

  this.render(hbs`{{create-comment-form}}`);

  assert.equal(this.$('.comment-signup p').text().trim(), 'Sign up for free to comment on this conversation, or sign in.');
  assert.equal(this.$('.comment-signup a:first').attr('href'), '/signup');
  assert.equal(this.$('.comment-signup a:last').attr('href'), '/login');
});
