habitica/test/casper/helpers.coffee

87 lines
2.3 KiB
CoffeeScript
Raw Normal View History

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
getUser: ->
casper.evaluate -> window.DERBY.app.model.get('_user')
addTasks: ->
['habit', 'daily', 'todo', 'reward'].forEach (type) ->
# Add 15 of each task type
num = 0
casper.repeat 15, ->
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()
userBeforeAfter: (callback) ->
user = {}
2013-01-28 22:37:36 +00:00
user.before = @getUser()
2013-01-28 22:31:10 +00:00
callback()
2013-01-28 22:37:36 +00:00
user.after = @getUser()
2013-01-28 22:31:10 +00:00
user
runCron: ->
casper.evaluate -> window.DERBY.model.set('_user.lastCron', new Date('01/25/2013'))
casper.reload()
2013-01-28 23:09:04 +00:00
cronBeforeAfter: (cb) ->
that = @
getLists = ->
{
habit: casper.evaluate -> window.DERBY.app.model.get('_habitList')
daily: casper.evaluate -> window.DERBY.app.model.get('_dailyList')
todo: casper.evaluate -> window.DERBY.app.model.get('_todoList')
reward: casper.evaluate -> window.DERBY.app.model.get('_rewardList')
}
beforeAfter =
before:
user: that.getUser()
tasks: getLists()
casper.then -> that.runCron()
casper.then ->
casper.wait 1050, -> # user's hp is updated after 1s for animation
beforeAfter.after =
user: that.getUser()
tasks: getLists()
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
}