2013-01-20 18:32:24 +00:00
|
|
|
url = 'http://localhost:3000/?play=1'
|
2012-10-12 13:58:42 +00:00
|
|
|
utils = require('utils')
|
2013-01-20 18:32:24 +00:00
|
|
|
casper = require("casper").create
|
|
|
|
|
clientScripts: 'test/includes/lodash.min.js'
|
2012-10-12 13:58:42 +00:00
|
|
|
|
2013-01-20 20:39:34 +00:00
|
|
|
# ---------- Util Functions ------------
|
2013-01-22 01:16:47 +00:00
|
|
|
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 = {}
|
|
|
|
|
user.before = getUser()
|
|
|
|
|
callback()
|
|
|
|
|
user.after = getUser()
|
|
|
|
|
user
|
|
|
|
|
|
|
|
|
|
runCron = ->
|
|
|
|
|
casper.evaluate -> window.DERBY.model.set('_user.lastCron', new Date('01/10/2013'))
|
|
|
|
|
casper.reload()
|
2013-01-20 20:39:34 +00:00
|
|
|
|
2013-01-20 18:32:24 +00:00
|
|
|
# ---------- Init ------------
|
2012-10-12 13:58:42 +00:00
|
|
|
|
|
|
|
|
casper.start url, ->
|
2013-01-20 18:32:24 +00:00
|
|
|
@test.assertTitle "HabitRPG | Gamify Your Life", "[√] Page Title"
|
2012-10-12 13:58:42 +00:00
|
|
|
|
2013-01-21 22:16:21 +00:00
|
|
|
# ---------- Register ------------
|
2013-01-22 01:16:47 +00:00
|
|
|
#casper.then ->
|
|
|
|
|
# @fill 'form#derby-auth-register',
|
|
|
|
|
# username: 'lefnire'
|
|
|
|
|
# email: 'x@x.com'
|
|
|
|
|
# 'email-confirmation': 'x@x.com'
|
|
|
|
|
# password: 'habitrpg123'
|
|
|
|
|
# , true
|
2013-01-21 22:16:21 +00:00
|
|
|
|
2013-01-20 22:49:30 +00:00
|
|
|
|
2013-01-22 01:16:47 +00:00
|
|
|
# ---------- Habits ------------
|
2012-10-12 13:58:42 +00:00
|
|
|
casper.then ->
|
2013-01-22 01:16:47 +00:00
|
|
|
reset()
|
|
|
|
|
addTasks()
|
2012-10-12 13:58:42 +00:00
|
|
|
|
2013-01-20 20:39:34 +00:00
|
|
|
casper.then ->
|
2013-01-22 01:16:47 +00:00
|
|
|
user = userBeforeAfter (-> casper.click '.habits a[data-direction="down"]')
|
|
|
|
|
@test.assert user.before.stats.hp > user.after.stats.hp, '-habit -hp'
|
|
|
|
|
@test.assert user.before.stats.exp == user.after.stats.exp, '-habit =exp'
|
2013-01-20 20:39:34 +00:00
|
|
|
|
|
|
|
|
@then ->
|
2013-01-22 01:16:47 +00:00
|
|
|
user = userBeforeAfter (-> casper.click '.habits a[data-direction="up"]')
|
|
|
|
|
@test.assert user.before.stats.exp < user.after.stats.exp, '+habit +exp'
|
|
|
|
|
@test.assertEquals user.before.stats.hp, user.after.stats.hp, '+habit =hp'
|
2013-01-20 20:39:34 +00:00
|
|
|
|
|
|
|
|
# Test Death
|
|
|
|
|
casper.then ->
|
2013-01-22 01:16:47 +00:00
|
|
|
@repeat 50, (-> casper.click '.habits a[data-direction="down"]')
|
2013-01-20 20:39:34 +00:00
|
|
|
@then ->
|
2013-01-22 01:16:47 +00:00
|
|
|
user = getUser()
|
|
|
|
|
@test.assertEquals user.stats.hp, 0, 'hp==0 (death by habits)'
|
|
|
|
|
@test.assertEquals user.stats.lvl, 0, 'lvl==0 (death by habits)'
|
2013-01-20 20:39:34 +00:00
|
|
|
@test.assert(@visible('#dead-modal'), 'Revive Modal Visible')
|
|
|
|
|
|
2013-01-22 01:16:47 +00:00
|
|
|
# ---------- Daily ------------
|
|
|
|
|
casper.then ->
|
|
|
|
|
reset()
|
|
|
|
|
addTasks()
|
|
|
|
|
|
|
|
|
|
# Gained exp on +daily
|
|
|
|
|
casper.then ->
|
|
|
|
|
user = userBeforeAfter (-> casper.click '.dailys input[type="checkbox"]')
|
|
|
|
|
@test.assertEquals user.before.stats.hp, user.after.stats.hp, '+daily =hp'
|
|
|
|
|
@test.assert user.before.stats.exp < user.after.stats.exp, '+daily +exp'
|
|
|
|
|
@test.assert user.before.stats.money < user.after.stats.money, '+daily +money'
|
|
|
|
|
|
|
|
|
|
# -daily acts as undo
|
|
|
|
|
casper.then ->
|
|
|
|
|
user = userBeforeAfter (-> casper.click '.dailys input[type="checkbox"]')
|
|
|
|
|
@test.assertEquals user.before.stats.hp, user.after.stats.hp, '-daily =hp'
|
|
|
|
|
@test.assert user.before.stats.exp > user.after.stats.exp, '-daily -exp'
|
|
|
|
|
@test.assert user.before.stats.money > user.after.stats.money, '-daily -money'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# ---------- Todos ------------
|
|
|
|
|
casper.then ->
|
|
|
|
|
reset()
|
|
|
|
|
addTasks()
|
|
|
|
|
|
|
|
|
|
# Gained exp on +daily
|
|
|
|
|
casper.then ->
|
|
|
|
|
user = userBeforeAfter (-> casper.click '.todos input[type="checkbox"]')
|
|
|
|
|
@test.assertEquals user.before.stats.hp, user.after.stats.hp, '+daily =hp'
|
|
|
|
|
@test.assert user.before.stats.exp < user.after.stats.exp, '+daily +exp'
|
|
|
|
|
@test.assert user.before.stats.money < user.after.stats.money, '+daily +money'
|
|
|
|
|
|
|
|
|
|
# -daily acts as undo
|
2012-10-12 13:58:42 +00:00
|
|
|
casper.then ->
|
2013-01-22 01:16:47 +00:00
|
|
|
user = userBeforeAfter (-> casper.click '.todos input[type="checkbox"]')
|
|
|
|
|
@test.assertEquals user.before.stats.hp, user.after.stats.hp, '-daily =hp'
|
|
|
|
|
@test.assert user.before.stats.exp > user.after.stats.exp, '-daily -exp'
|
|
|
|
|
@test.assert user.before.stats.money > user.after.stats.money, '-daily -money'
|
|
|
|
|
|
|
|
|
|
# ---------- Rewards ------------
|
|
|
|
|
#TODO
|
|
|
|
|
|
|
|
|
|
# ---------- Cron ------------
|
2013-01-20 18:32:24 +00:00
|
|
|
|
2013-01-22 01:16:47 +00:00
|
|
|
casper.then ->
|
|
|
|
|
reset()
|
|
|
|
|
addTasks()
|
2013-01-20 18:32:24 +00:00
|
|
|
|
2013-01-22 01:16:47 +00:00
|
|
|
casper.then ->
|
|
|
|
|
user = {before:getUser()}
|
|
|
|
|
tasks =
|
|
|
|
|
before:
|
|
|
|
|
daily: @evaluate -> window.DERBY.app.model.get('_dailyList')
|
|
|
|
|
todo: @evaluate -> window.DERBY.app.model.get('_todoList')
|
|
|
|
|
runCron()
|
2012-10-12 13:58:42 +00:00
|
|
|
|
|
|
|
|
@then ->
|
2013-01-22 01:16:47 +00:00
|
|
|
@wait 1050, -> # user's hp is updated after 1s for animation
|
|
|
|
|
user.after = getUser()
|
|
|
|
|
tasks =
|
|
|
|
|
after:
|
|
|
|
|
daily: @evaluate -> window.DERBY.app.model.get('_dailyList')
|
|
|
|
|
todo: @evaluate -> window.DERBY.app.model.get('_todoList')
|
|
|
|
|
|
|
|
|
|
@test.assertEqual user.before.tasks.length, user.after.tasks.length, "Didn't lose anything on cron"
|
|
|
|
|
|
|
|
|
|
#TODO make sure true for all todos
|
|
|
|
|
todoId = tasks.before.todos[0].id
|
|
|
|
|
@test.assert user.before.tasks[todoId].value < user.before.tasks[todoId].value, "todo gained value on cron"
|
|
|
|
|
@test.assert user.before.stats.hp < user.after.stats.hp, 'user lost HP on cron'
|
2013-01-21 04:21:50 +00:00
|
|
|
|
2013-01-22 01:16:47 +00:00
|
|
|
# ---------- Reset ------------
|
|
|
|
|
# @then ->
|
|
|
|
|
# utils.dump @evaluate -> window.DERBY.app.model.get('_user.auth')
|
|
|
|
|
# @click '#reset-modal button:contains(Reset)'
|
2012-10-12 13:58:42 +00:00
|
|
|
|
2013-01-22 01:16:47 +00:00
|
|
|
# Clear tasks
|
|
|
|
|
casper.then ->
|
|
|
|
|
#TODO test after stats have been modified
|
|
|
|
|
casper.repeat 5, -> @click '.habits a[data-direction="down"]'
|
|
|
|
|
casper.repeat 5, -> @click '.habits a[data-direction="up"]'
|
|
|
|
|
userObj = @evaluate ->
|
|
|
|
|
window.DERBY.app.reset()
|
|
|
|
|
return window.DERBY.app.model.get('_user')
|
|
|
|
|
|
|
|
|
|
@test.assertEqual userObj.tasks.length, 0
|
|
|
|
|
@test.assertEqual userObj.stats.hp, 50
|
2013-01-20 20:39:34 +00:00
|
|
|
|
2012-10-12 13:58:42 +00:00
|
|
|
# ---------- Misc Pages ------------
|
|
|
|
|
|
|
|
|
|
casper.thenOpen "#{url}/terms", ->
|
|
|
|
|
@test.assertTitle "Terms Of Use", "terms page works"
|
|
|
|
|
|
|
|
|
|
casper.thenOpen "#{url}/privacy", ->
|
|
|
|
|
@test.assertTitle "Privacy Policy", "privacy page works"
|
|
|
|
|
|
|
|
|
|
# ---------- Run ------------
|
|
|
|
|
|
|
|
|
|
casper.run ->
|
|
|
|
|
@test.renderResults true
|