mirror of
https://github.com/sudoxnym/habitica.git
synced 2026-08-04 01:29:21 +00:00
Fixing the dailies and todos casper test (now even with working cron tests)
This commit is contained in:
parent
1a04414571
commit
68282f4cd3
3 changed files with 59 additions and 53 deletions
|
|
@ -8,7 +8,7 @@ casper.start url
|
|||
# ---------- Daily ------------
|
||||
casper.then ->
|
||||
helpers.reset()
|
||||
helpers.addTasks()
|
||||
helpers.addTasks(['daily'])
|
||||
|
||||
# Gained exp on +daily
|
||||
casper.then ->
|
||||
|
|
@ -27,15 +27,18 @@ casper.then ->
|
|||
# ---------- Cron ------------
|
||||
casper.then ->
|
||||
helpers.reset()
|
||||
helpers.addTasks()
|
||||
helpers.addTasks(['daily'])
|
||||
|
||||
casper.then ->
|
||||
helpers.cronBeforeAfter (model) ->
|
||||
casper.then ->
|
||||
#TODO make sure true for all dailies
|
||||
dailyId = model.before._user.dailyIds[0]
|
||||
casper.test.assert model.before._user.tasks[dailyId].value < model.after._user.tasks[dailyId].value, "daily:cron:daily gained value"
|
||||
casper.test.assert model.before._user.stats.hp < model.after._user.stats.hp, 'daily:cron:hp lost value'
|
||||
casper.test.assert model.before._user.stats.hp > model.after._user.stats.hp, 'daily:cron:hp lost value'
|
||||
|
||||
# Go through all the dailys, all of them are uncompleted, so should all get a negative value
|
||||
casper.echo "Testing all uncompleted dailys after cron"
|
||||
for id in model.before._user.dailyIds
|
||||
casper.test.assertEquals model.before._user.tasks[id].value, 0, "daily:cron:daily value before was 0"
|
||||
casper.test.assert model.after._user.tasks[id].value < 0, "daily:cron:daily value after is negative"
|
||||
|
||||
# ---------- Run ------------
|
||||
casper.run ->
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ utils = require('utils')
|
|||
|
||||
module.exports = ->
|
||||
|
||||
SYNC_WAIT_TIME = 20
|
||||
SYNC_WAIT_TIME = 40
|
||||
|
||||
baseUrl = 'http://localhost:3000'
|
||||
|
||||
|
|
@ -31,12 +31,13 @@ module.exports = ->
|
|||
|
||||
utils: utils
|
||||
|
||||
addTasks: ->
|
||||
['habit', 'daily', 'todo', 'reward'].forEach (type) ->
|
||||
# Add 15 of each task type
|
||||
num = 0
|
||||
casper.repeat 5, ->
|
||||
casper.fill "form#new-#{type}", {'new-task': "#{type}-#{num}"} # why can't I use true here?
|
||||
addTasks: (types = 'all', num = 5)->
|
||||
if types == 'all'
|
||||
types = ['habit', 'daily', 'todo', 'reward']
|
||||
types.forEach (type) ->
|
||||
i = 0
|
||||
casper.repeat num, ->
|
||||
casper.fill "form#new-#{type}", {'new-task': "#{type}-#{i}"} # why can't I use true here?
|
||||
casper.click "form#new-#{type} input[type=submit]"
|
||||
|
||||
reset: ->
|
||||
|
|
@ -58,7 +59,10 @@ module.exports = ->
|
|||
casper.then -> done_cb(model)
|
||||
|
||||
runCron: ->
|
||||
casper.evaluate -> window.DERBY.model.set('_user.lastCron', new Date('01/25/2013'))
|
||||
casper.evaluate ->
|
||||
yesterday = new Date()
|
||||
yesterday.setDate(yesterday.getDate() - 1);
|
||||
window.DERBY.app.model.set('_user.lastCron', yesterday)
|
||||
casper.then -> casper.reload()
|
||||
|
||||
cronBeforeAfter: (cb) ->
|
||||
|
|
@ -68,14 +72,13 @@ module.exports = ->
|
|||
model.before = before
|
||||
casper.then -> that.runCron()
|
||||
casper.then ->
|
||||
casper.wait 1050, -> # user's hp is updated after 1s for animation
|
||||
casper.wait 1100, -> # user's hp is updated after 1s for animation
|
||||
model.after = getModel()
|
||||
casper.then ->
|
||||
casper.test.assertEqual model.before._user.id, model.after._user.id, 'user id equal after cron'
|
||||
casper.test.assertEqual model.before._user.tasks.length, model.after._user.tasks.length, "Didn't lose anything on cron"
|
||||
cb(model)
|
||||
|
||||
|
||||
register: ->
|
||||
casper.fill 'form#derby-auth-register',
|
||||
username: random
|
||||
|
|
@ -90,13 +93,10 @@ module.exports = ->
|
|||
password: random
|
||||
, true
|
||||
|
||||
|
||||
deleteOne: (type) ->
|
||||
listType = if type == 'completed' then 'todo' else type
|
||||
selector = ".#{type}s a[data-original-title=\"Delete\"]"
|
||||
deleteOne: (list, typeSelector) ->
|
||||
selector = "#{typeSelector} 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"
|
||||
casper.test.assertEquals Object.keys(model.before._user.tasks).length - 1, Object.keys(model.after._user.tasks).length, "1 #{typeSelector} deleted from user.tasks"
|
||||
casper.test.assertEquals model.before._user["#{list}Ids"].length - 1, model.after._user["#{list}Ids"].length, "1 #{typeSelector} deleted from user._typeIds"
|
||||
casper.test.assertEquals model.before["_#{list}List"].length - 1, model.after["_#{list}List"].length, "1 #{typeSelector} deleted from _typeList"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,54 +1,57 @@
|
|||
helper = new require('./test/casper/helpers')()
|
||||
casper = helper.casper
|
||||
utils = helper.utils
|
||||
url = helper.url
|
||||
helpers = new require('./test/casper/helpers')()
|
||||
casper = helpers.casper
|
||||
utils = helpers.utils
|
||||
url = helpers.playUrl
|
||||
|
||||
casper.start url + '/?play=1'
|
||||
casper.start url
|
||||
|
||||
# ---------- Todos ------------
|
||||
casper.then ->
|
||||
helper.reset()
|
||||
helper.addTasks()
|
||||
helpers.reset()
|
||||
helpers.addTasks(['todo'])
|
||||
|
||||
# Gained exp on +daily
|
||||
# Completing todo gives exp and gp
|
||||
casper.then ->
|
||||
helper.modelBeforeAfter (-> casper.click '.todos input[type="checkbox"]'), (model) ->
|
||||
helpers.modelBeforeAfter (-> casper.click '.todos .uncompleted 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'
|
||||
casper.test.assertEquals model.after._user.stats.gp, 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'
|
||||
casper.test.assert model.before._user.stats.exp < model.after._user.stats.exp, '+todo +exp'
|
||||
casper.test.assert model.before._user.stats.gp < model.after._user.stats.gp, '+todo +gp'
|
||||
|
||||
# -daily acts as undo
|
||||
# Can delete completed
|
||||
casper.then -> helpers.deleteOne('todo', '.todos .completed')
|
||||
|
||||
# Can delete uncompleted
|
||||
casper.then -> helpers.deleteOne('todo', '.todos .uncompleted')
|
||||
|
||||
# Uncompleting subtracts exp and gp
|
||||
casper.then ->
|
||||
helper.modelBeforeAfter (-> casper.click '.completeds input[type="checkbox"]'), (model) ->
|
||||
casper.click '.todos .uncompleted input[type="checkbox"]'
|
||||
helpers.modelBeforeAfter (-> casper.click '.todos .completed 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.test.assert model.before._user.stats.gp > model.after._user.stats.gp, '-todo -gp'
|
||||
|
||||
casper.then -> helper.deleteOne('todo')
|
||||
casper.then -> helper.deleteOne('completed')
|
||||
|
||||
|
||||
# ---------- Cron ------------
|
||||
casper.then ->
|
||||
helper.reset()
|
||||
helper.addTasks()
|
||||
helpers.reset()
|
||||
helpers.addTasks(['todo'])
|
||||
|
||||
casper.then ->
|
||||
helper.cronBeforeAfter (beforeAfter) ->
|
||||
helpers.cronBeforeAfter (model) ->
|
||||
casper.then ->
|
||||
#TODO make sure true for all todos
|
||||
todoId = beforeAfter.before.tasks.todo[0].id
|
||||
# utils.dump
|
||||
# dailyBefore:user.before.tasks[dailyId].value
|
||||
# dailyAfter:user.before.tasks[dailyId].value
|
||||
casper.test.assert beforeAfter.before.user.tasks[todoId].value < beforeAfter.after.user.tasks[todoId].value, "todo:cron:todo gained value"
|
||||
casper.test.assertEqual beforeAfter.before.user.stats.hp, beforeAfter.after.user.stats.hp, 'todo:cron:hp no change'
|
||||
casper.test.assertEqual model.before._user.stats.hp, model.after._user.stats.hp, 'todo:cron:hp no change'
|
||||
|
||||
# Go through all the todos, all of them are uncompleted, so should all get a negative value
|
||||
casper.echo "Testing all uncompleted todos after cron"
|
||||
for id in model.before._user.todoIds
|
||||
casper.test.assertEquals model.before._user.tasks[id].value, 0, "todo:cron:todo value before was 0"
|
||||
casper.test.assert model.after._user.tasks[id].value < 0, "todo:cron:todo value after is negative"
|
||||
|
||||
|
||||
# ---------- Run ------------
|
||||
|
|
|
|||
Loading…
Reference in a new issue