mirror of
https://github.com/sudoxnym/habitica.git
synced 2026-08-01 15:31:16 +00:00
todos.casper.coffee
This commit is contained in:
parent
b9c9586696
commit
8dd0b4eeb2
2 changed files with 52 additions and 38 deletions
|
|
@ -14,55 +14,50 @@ module.exports = ->
|
|||
|
||||
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.repeat 5, ->
|
||||
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
|
||||
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)
|
||||
|
||||
runCron: ->
|
||||
casper.evaluate -> window.DERBY.model.set('_user.lastCron', new Date('01/25/2013'))
|
||||
casper.reload()
|
||||
casper.then -> casper.reload()
|
||||
|
||||
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()
|
||||
|
||||
model = {before:@getModel()}
|
||||
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()
|
||||
|
||||
model.after = that.getModel()
|
||||
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"
|
||||
|
|
@ -83,4 +78,13 @@ module.exports = ->
|
|||
password: random
|
||||
, true
|
||||
|
||||
|
||||
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"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,17 +12,27 @@ casper.then ->
|
|||
|
||||
# Gained exp on +daily
|
||||
casper.then ->
|
||||
user = helper.userBeforeAfter (-> casper.click '.todos input[type="checkbox"]')
|
||||
@test.assertEquals user.before.stats.hp, user.after.stats.hp, '+todo =hp'
|
||||
@test.assert user.before.stats.exp < user.after.stats.exp, '+todo +exp'
|
||||
@test.assert user.before.stats.money < user.after.stats.money, '+todo +money'
|
||||
helper.modelBeforeAfter (-> casper.click '.todos input[type="checkbox"]'), (model) ->
|
||||
casper.test.assertEquals model.before._user.stats.hp, 50, 'todo:hp starts at 50'
|
||||
casper.test.assertEquals model.before._user.stats.hp, model.after._user.stats.hp, '+todo =hp'
|
||||
casper.test.assertEquals model.after._user.stats.exp, 1, '+todo exp=1'
|
||||
casper.test.assertEquals model.after._user.stats.money, 1, '+todo gp=1'
|
||||
|
||||
#FIXME before._user.stats not fully available until modified? Is this a Derby JIT caching mechanism?
|
||||
#casper.test.assert model.before._user.stats.exp < model.after._user.stats.exp, '+todo +exp'
|
||||
#casper.test.assert model.before._user.stats.money < model.after._user.stats.money, '+todo +money'
|
||||
|
||||
# -daily acts as undo
|
||||
casper.then ->
|
||||
user = helper.userBeforeAfter (-> casper.click '.todos input[type="checkbox"]')
|
||||
@test.assertEquals user.before.stats.hp, user.after.stats.hp, '-todo =hp'
|
||||
@test.assert user.before.stats.exp > user.after.stats.exp, '-todo -exp'
|
||||
@test.assert user.before.stats.money > user.after.stats.money, '-todo -money'
|
||||
helper.modelBeforeAfter (-> casper.click '.completeds input[type="checkbox"]'), (model) ->
|
||||
casper.test.assertEquals model.before._user.stats.hp, model.after._user.stats.hp, '-todo =hp'
|
||||
casper.test.assert model.before._user.stats.exp > model.after._user.stats.exp, '-todo -exp'
|
||||
casper.test.assert model.before._user.stats.money > model.after._user.stats.money, '-todo -money'
|
||||
utils.dump {before:model.before._user.stats, after:model.after._user.stats}
|
||||
|
||||
casper.then -> helper.deleteOne('todo')
|
||||
casper.then -> helper.deleteOne('completed')
|
||||
|
||||
|
||||
# ---------- Cron ------------
|
||||
casper.then ->
|
||||
|
|
|
|||
Loading…
Reference in a new issue