2013-01-28 22:31:10 +00:00
utils = require ( ' utils ' )
2013-01-26 19:57:47 +00:00
module.exports = ->
2013-01-28 22:31:10 +00:00
random = Math . random ( ) . toString ( 36 ) . substring ( 7 )
2013-01-26 19:57:47 +00:00
2013-01-28 22:31:10 +00:00
casper = require ( " casper " ) . create
2013-01-26 19:57:47 +00:00
clientScripts: ' test/includes/lodash.min.js '
2013-01-28 22:31:10 +00:00
{
casper: casper
url: ' http://localhost:3000 '
utils: utils
addTasks: ->
[ ' habit ' , ' daily ' , ' todo ' , ' reward ' ] . forEach (type) ->
# Add 15 of each task type
num = 0
2013-01-30 17:11:15 +00:00
casper . repeat 5 , ->
2013-01-28 22:31:10 +00:00
casper . fill " form # new- #{ type } " , { ' new-task ' : " #{ type } - #{ num } " } # why can't I use true here?
casper . click " form # new- #{ type } input[type=submit] "
reset: ->
casper . evaluate -> window . DERBY . app . reset ( )
2013-01-30 17:11:15 +00:00
getModel: ->
casper . evaluate ->
model = window . DERBY . app . model
{
_userId: model . get ( ' _userId ' )
_user: model . get ( " _user " )
_todoList: model . get ( ' _todoList ' )
_dailyList: model . get ( ' _dailyList ' )
_rewardList: model . get ( ' _rewardList ' )
_habitList: model . get ( ' _habitList ' )
}
modelBeforeAfter: (between_cb, done_cb) ->
that = @
model = { before : @ getModel ( ) }
casper . then ->
between_cb ( )
casper . then ->
model.after = that . getModel ( )
#utils.dump model
casper . then -> done_cb ( model )
2013-01-28 22:31:10 +00:00
runCron: ->
casper . evaluate -> window . DERBY . model . set ( ' _user.lastCron ' , new Date ( ' 01/25/2013 ' ) )
2013-01-30 17:11:15 +00:00
casper . then -> casper . reload ( )
2013-01-28 22:31:10 +00:00
2013-01-28 23:09:04 +00:00
cronBeforeAfter: (cb) ->
that = @
2013-01-30 17:11:15 +00:00
model = { before : @ getModel ( ) }
2013-01-28 23:09:04 +00:00
casper . then -> that . runCron ( )
casper . then ->
casper . wait 1050 , -> # user's hp is updated after 1s for animation
2013-01-30 17:11:15 +00:00
model.after = that . getModel ( )
2013-01-28 23:09:04 +00:00
casper . then ->
casper . test . assertEqual beforeAfter . before . user . id , beforeAfter . after . user . id , ' user id equal after cron '
casper . test . assertEqual beforeAfter . before . user . tasks . length , beforeAfter . after . user . tasks . length , " Didn ' t lose anything on cron "
cb ( beforeAfter )
2013-01-28 22:31:10 +00:00
register: ->
casper . fill ' form # derby-auth-register ' ,
username: random
email: random + ' @gmail.com '
' email-confirmation ' : random + ' @gmail.com '
password: random
, true
login: ->
casper . fill ' form # derby-auth-login ' ,
username: random
password: random
, true
2013-01-30 17:11:15 +00:00
deleteOne: (type) ->
listType = if type == ' completed ' then ' todo ' else type
selector = " . #{ type } s a[data-original-title= \" Delete \" ] "
@ modelBeforeAfter ( -> casper . click selector ) , (model) ->
# utils.dump model
casper . test . assertEquals Object . keys ( model . before . _user . tasks ) . length - 1 , Object . keys ( model . after . _user . tasks ) . length , " 1 #{ type } deleted from user.tasks "
casper . test . assertEquals model . before . _user [ " #{ listType } Ids " ] . length - 1 , model . after . _user [ " #{ listType } Ids " ] . length , " 1 #{ type } deleted from user._typeIds "
casper . test . assertEquals model . before [ " _ #{ listType } List " ] . length - 1 , model . after [ " _ #{ listType } List " ] . length , " 1 #{ type } deleted from _typeList "
2013-01-28 22:31:10 +00:00
}