Skip to content

Commit

Permalink
getting all the test to pass and refactoring the test
Browse files Browse the repository at this point in the history
  • Loading branch information
jcblw committed Feb 16, 2014
1 parent a03c2a8 commit dce5461
Show file tree
Hide file tree
Showing 12 changed files with 238 additions and 137 deletions.
39 changes: 19 additions & 20 deletions app/javascripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ if ( "_options" in window ) {
app.gotoView( view );
};



function gotoStep( template, payload ) {
var _html = __tmp[ template ]( payload );
app.$el.html( _html );
Expand Down Expand Up @@ -86,7 +84,22 @@ if ( "_options" in window ) {
function formHandler( ) {
form.handler.apply( form, arguments );
}

// checks for view creates a message if view is present
if ( _options.view ) {
switch ( _options.view ) {
case 'createevent' :
_options.message = "Once you signup or login you" +
" will be taken to the create event page.";
break;
case 'donate' :
_options.message = "Please create an account to donate" +
" and you are a beautiful person.";
break;
default :
// just remove for now to avoid issues
_options.view = null;
}
}

if ( supportSessions ) {
try {
Expand All @@ -106,26 +119,12 @@ if ( "_options" in window ) {
};
app.user = user;
app.plans = plans;
io.setUser( user );
if ( app.plans ) done();
} else {
gotoStep('signup', _options || {});
}
}
if ( _options.view ) {
switch ( _options.view ) {
case 'createevent' :
_options.message = "Once you signup or login you" +
" will be taken to the create event page.";
break;
case 'donate' :
_options.message = "Please create an account to donate" +
" and you are a beautiful person.";
break;
default :
// just remove for now to avoid issues
_options.view = null;
}
}
gotoStep('signup', _options || {});


app.gotoStep = gotoStep;
app.gotoView = gotoView;
Expand Down
3 changes: 3 additions & 0 deletions app/javascripts/sdk.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@
},
setUrl : function ( url ) {
apiUrl = url;
},
setUser : function ( _user ) {
user = _user;
}

}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"private": true,
"scripts": {
"start": "node app",
"test": "dalek test/*.js"
"test": "dalek test/main.js"
},
"dependencies": {
"express": "3.0.2",
Expand Down
38 changes: 38 additions & 0 deletions test/auth.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
require('dotenv').load();

var _timeout = 50000,
testUser = process.env.TEST_USER,
testPassword = process.env.TEST_PASSWORD;

module.exports = {
'login' : function ( test ) {
test
.open('http://127.0.0.1:3030')
.wait(2000)
.click('.login-switch')
.type('#email', testUser )
.type('#password', testPassword )
.click('[type="submit"]')
.waitForElement('#io-dashboard > h2', _timeout)
.assert.text('#io-dashboard > h2').is('Hello.')
.done();
},
persistant : function ( test ) {
test
.open('http://127.0.0.1:3030')
.waitForElement('#io-dashboard > h2', _timeout)
.wait(2000)
.assert.text('#io-dashboard > h2').is('Hello.')
.done();
},
logout : function ( test ) {
test
.open('http://127.0.0.1:3030')
.waitForElement('#io-dashboard > h2', _timeout)
.wait(2000)
.click('[data-view="login"]')
.waitForElement('#password')
.assert.text('.main > h2').is('Login')
.done();
}
}
129 changes: 13 additions & 116 deletions test/main.js
Original file line number Diff line number Diff line change
@@ -1,118 +1,15 @@
var _timeout = 50000;

var _timeout = 50000,
auth = require('./auth');

module.exports = {
'signup flow works': function ( test ) {

// good for now but there also should
// be a cleanup script
// and also test for errors in between
test
.open('http://127.0.0.1:3030')
.waitForElement('#password')
.wait(2000)
.type('#email', 'temp' + ( Math.random() * 100000 ) + '@gmail.com')
.type('#password', '123456')
.click('[type="submit"]')
.waitForElement('.pure-button.alert.submit-plan')
.assert.visible('.pure-button.alert.submit-plan')
.click('.plan-list > li >input[type="radio"]')
.click('.submit-plan')
.waitForElement('input[type="submit"]')
.type('#card_number', '4242424242424242')
.type('#cvc', '123')
.type('#card_exp_month', '02')
.type('#card_exp_year', '20')
.click('input[type="submit"]')
.waitForElement('.message', _timeout)
.assert.text('.message')
.is('Thanks for joining!', 'Successfully created new member account')
.waitForElement('[data-view="login"]')
.click('[data-view="login"]')
.waitForElement('#password')
.done();
},
'dashboard is working': function ( test ) {

test
.open('http://127.0.0.1:3030')
.wait(2000)
// login
.click('.login-switch')
.type('#email', '[email protected]')
.type('#password', '123456')
.click('[type="submit"]')
.waitForElement('#io-dashboard > h2', _timeout)
.assert.text('#io-dashboard > h2')
.is('Hello.', 'Login Successfull')
// donate
.click('[data-view="donate"]')
.waitForElement('#amount')
.type('#amount', '1.00')
.type('#card_number', '4242424242424242')
.type('#cvc', '123')
.type('#card_exp_month', '02')
.type('#card_exp_year', '20')
.click('[type="submit"]')
.waitForElement('.message', _timeout)
.assert.text('.message')
.is('Thanks! You have been charged $1.00')
// create a event
.click('[data-view="createevent"]')
.waitForElement('#date')
.click('#date')
.waitForElement('.pika-single')
.assert.visible('.pika-single', 'Calendar opened')
//random number of clicks / 12
.click('.pika-next')
.click('.pika-next')
.click('.pika-next')
// random day / 28
.click('[data-day="15"] > button')
.type('#title', 'Hello World')
.type('#description', 'Woot woot!')
.click('[type="submit"]')
.waitForElement('.message', _timeout)
.assert.text('.message')
.is('Your Event \'Hello World\' has been created!' +
' We will email you if there are any issues with the event.')
// make a payment
.click('[data-view="payment"]')
.waitForElement('#amount')
.type('#amount', '1.00')
.type('#card_number', '4242424242424242')
.type('#cvc', '123')
.type('#card_exp_month', '02')
.type('#card_exp_year', '20')
.click('[type="submit"]')
.waitForElement('.message', _timeout)
.assert.text('.message')
.is('Thanks! You have been charged $1.00')
// update plan
.click('[data-view="updateplan"]')
.waitForElement('.pure-button.alert.submit-plan')
.click('.plan-list > li >input[type="radio"]')
.click('.submit-plan')
.waitForElement('.message', _timeout)
.assert.text('.message')
.is('Your plan has been updated.')
// update card
.click('[data-view="updatepayment"]')
.waitForElement('#card_number')
.type('#card_number', '4242424242424242')
.type('#cvc', '123')
.type('#card_exp_month', '02')
.type('#card_exp_year', '20')
.click('[type="submit"]')
.waitForElement('.message', _timeout)
.assert.text('.message')
.is('Payment Successfully Updated')
//cancel plan
.click('[data-view="cancelplan"]')
.waitForElement('.yes-plan')
.click('.yes-plan')
.waitForElement('.message', _timeout)
.assert.text('.message')
.is('Sorry to see you go')
.done();
}
'signup flow': require('./views/signup'),
'signup user logout' : auth.logout,
'login' : auth.login,
'login is persistant' : auth.persistant,
'donating' : require('./views/donate'),
'creating an event' : require('./views/createevent'),
'making a payment' : require('./views/payment'),
'updating plan' : require('./views/updateplan'),
'canceling plan' : require('./views/cancelplan'),
'logout' : auth.logout
};
15 changes: 15 additions & 0 deletions test/views/cancelplan.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
var _timeout = 50000;

module.exports = function ( test ) {
test
.open('http://127.0.0.1:3030')
.waitForElement('#io-dashboard > h2')
.wait(2000)
.click('[data-view="cancelplan"]')
.waitForElement('.yes-plan')
.click('.yes-plan')
.waitForElement('.message', _timeout)
.assert.text('.message')
.is('Sorry to see you go')
.done()
}
46 changes: 46 additions & 0 deletions test/views/createevent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
var _timeout = 50000,
// starts on current month
// + 1 to alway go forawrd at least once
// 9 to limit range to ( 9 + 1 ) 10 so we dont hit
// the current month next year "only some dates are avail"
month = Math.round( (Math.random() * 9) + 1 ),
day = Math.round( (Math.random() * 27) + 1 );

function randomDate ( test ) {
test.randomDate = function ( ) {
var _test = this;
for( var i = 0; i <= month; i += 1 ){
_test = _test.click('.pika-next');
}
return _test.click('[data-day="' + day + '"] > button');
}
}

module.exports = function ( test ) {
// extend test object
randomDate( test );

test
.open('http://127.0.0.1:3030')
.waitForElement('#io-dashboard > h2')
.wait(2000)
.click('[data-view="createevent"]')
.waitForElement('#date')
//random number of clicks / 12
.type('#start','7:00 AM')
.type('#end','8:00 AM')
.type('#title', 'Hello World')
.type('#description', 'Woot woot!')
.click('#date')
.waitForElement('.pika-single')
.assert.visible('.pika-single', 'Calendar opened')
.randomDate()
// .click('body')
.click('[type="submit"]')
.waitForElement('.message', _timeout)
.assert.text('.message')
.is('Your Event \'Hello World\' has been created!' +
' We will email you if there are any issues with the event.',
'Correct Message Shown')
.done()
}
20 changes: 20 additions & 0 deletions test/views/donate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
var _timeout = 50000;

module.exports = function ( test ) {
test
.open('http://127.0.0.1:3030')
.waitForElement('#io-dashboard > h2')
.wait(2000)
.click('[data-view="donate"]')
.waitForElement('#amount')
.type('#amount', '1.00')
.type('#card_number', '4242424242424242')
.type('#cvc', '123')
.type('#card_exp_month', '02')
.type('#card_exp_year', '20')
.click('[type="submit"]')
.waitForElement('.message', _timeout)
.assert.text('.message')
.is('Thanks! You have been charged $1.00')
.done()
}
20 changes: 20 additions & 0 deletions test/views/payment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
var _timeout = 50000;

module.exports = function ( test ) {
test
.open('http://127.0.0.1:3030')
.waitForElement('#io-dashboard > h2')
.wait(2000)
.click('[data-view="payment"]')
.waitForElement('#amount')
.type('#amount', '1.00')
.type('#card_number', '4242424242424242')
.type('#cvc', '123')
.type('#card_exp_month', '02')
.type('#card_exp_year', '20')
.click('[type="submit"]')
.waitForElement('.message', _timeout)
.assert.text('.message')
.is('Thanks! You have been charged $1.00')
.done()
}
28 changes: 28 additions & 0 deletions test/views/signup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
var _timeout = 50000;

module.exports = function ( test ) {
// good for now but there also should
// be a cleanup script
// and also test for errors in between
test
.open('http://127.0.0.1:3030')
.waitForElement('#password')
.wait(2000)
.type('#email', 'temp' + ( Math.random() * 100000 ) + '@gmail.com')
.type('#password', '123456')
.click('[type="submit"]')
.waitForElement('.pure-button.alert.submit-plan')
.assert.visible('.pure-button.alert.submit-plan')
.click('.plan-list > li >input[type="radio"]')
.click('.submit-plan')
.waitForElement('input[type="submit"]')
.type('#card_number', '4242424242424242')
.type('#cvc', '123')
.type('#card_exp_month', '02')
.type('#card_exp_year', '20')
.click('input[type="submit"]')
.waitForElement('.message', _timeout)
.assert.text('.message')
.is('Thanks for joining!', 'Successfully created new member account')
.done();
}
Loading

0 comments on commit dce5461

Please sign in to comment.