Skip to content

Instantly share code, notes, and snippets.

@benlieb
Last active August 29, 2015 14:19
Show Gist options
  • Save benlieb/cd4e6d7ac3e4794bdf58 to your computer and use it in GitHub Desktop.
Save benlieb/cd4e6d7ac3e4794bdf58 to your computer and use it in GitHub Desktop.
import Ember from 'ember';
import FactoryGuy from 'ember-data-factory-guy';
import FactoryGuyTestHelper from 'ember-data-factory-guy/factory-guy-test-helper';
import startApp from '../../helpers/start-app';
import { module, test } from 'qunit';
var App;
module('Acceptance: Registration New', {
beforeEach: function() {
Ember.run(function() {
App = startApp();
FactoryGuyTestHelper.setup();
});
},
afterEach: function() {
Ember.run(function() {
FactoryGuyTestHelper.teardown();
App.destroy();
});
},
});
test('fields exist and are empty initally', function(assert) {
visit('/registration/new');
andThen(function() {
assert.ok(find('#registration').html());
assert.equal(find('input#email_address').val(), '');
assert.equal(find('input#first_name').val(), '');
assert.equal(find('input#last_name').val(), '');
assert.equal(find('input#password').val(), '');
assert.equal(find('input#password_verify').val(), '');
assert.equal(find('input#receive_emails').attr('type'), 'checkbox');
assert.equal(find('input#receive_emails').prop('checked'), false);
});
});
test('registration succeeds with good data', function(assert) {
var registration = FactoryGuy.make('registration');
visit('/registration/new');
andThen(function() {
//user fills in good data
fillIn('input#email_address', registration.get('email_address'));
fillIn('input#first_name', registration.get('first_name'));
fillIn('input#last_name', registration.get('last_name'));
fillIn('input#password', registration.get('password'));
fillIn('input#password_verify', registration.get('password_verify'));
});
andThen(function() {
//confirm data is set
assert.equal(find('input#email_address').val(), registration.get('email_address'));
assert.equal(find('input#first_name').val(), registration.get('first_name'));
assert.equal(find('input#last_name').val(), registration.get('last_name'));
assert.equal(find('input#password').val(), registration.get('password'));
assert.equal(find('input#password_verify').val(), registration.get('password_verify'));
FactoryGuyTestHelper.handleCreate('registration');
//user submits data
click("#registration_form button[type=submit]");
});
andThen(function() {
//we progess to the welcome page
assert.equal(currentPath(), "registration.welcome");
//the user's name is used in a greeting
assert.ok(find("h2").text().indexOf(registration.get('first_name')));
});
});
test('registration fails with bad data, and appropriate errors are displayed', function(assert) {
var registration = FactoryGuy.make('registration');
var bad_msg = 'bad email address';
andThen(function() {
registration.set('email_address', bad_msg);
visit('/registration/new');
});
andThen(function() {
//user fills in only one peice data
//this is only one, because NED only returns one peice of data at a time
//TODO: test for every possible error?
fillIn('input#email_address', registration.get('email_address'));
fillIn('input#first_name', registration.get('first_name'));
fillIn('input#last_name', registration.get('last_name'));
fillIn('input#password', registration.get('password'));
fillIn('input#password_verify', registration.get('password_verify'));
});
andThen(function() {
assert.equal(find('input#email_address').val(), registration.get('email_address'));
FactoryGuyTestHelper.handleCreate('registration').andFail({status: 422, response: {errors: {email_address: [bad_msg]}}});
//match({match: {email_address: registration.get('email_address')}}).
//user submits data
click("#registration_form button[type=submit]");
});
//we don't progess to the welcome page
andThen(function() {
assert.equal(currentPath(), "registration.new");
//indicators of errors be present
assert.ok(find('.has-error').text());
assert.ok(find('.field-errors li').text());
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment