habitica/test/casper/todos.casper.coffee

59 lines
2.3 KiB
CoffeeScript
Raw Normal View History

helpers = new require('./test/casper/helpers')()
casper = helpers.casper
utils = helpers.utils
url = helpers.playUrl
2013-01-28 22:43:50 +00:00
casper.start url
2013-01-28 22:43:50 +00:00
2013-01-26 19:57:47 +00:00
# ---------- Todos ------------
casper.then ->
helpers.reset()
helpers.addTasks(['todo'])
2013-01-26 19:57:47 +00:00
# Completing todo gives exp and gp
2013-01-26 19:57:47 +00:00
casper.then ->
helpers.modelBeforeAfter (-> casper.click '.todos .uncompleted input[type="checkbox"]'), (model) ->
2013-01-30 17:11:15 +00:00
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.gp, 1, '+todo gp=1'
2013-01-30 17:11:15 +00:00
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'
2013-01-26 19:57:47 +00:00
# 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
2013-01-26 19:57:47 +00:00
casper.then ->
casper.click '.todos .uncompleted input[type="checkbox"]'
helpers.modelBeforeAfter (-> casper.click '.todos .completed input[type="checkbox"]'), (model) ->
2013-01-30 17:11:15 +00:00
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.gp > model.after._user.stats.gp, '-todo -gp'
2013-01-30 17:11:15 +00:00
2013-01-28 23:09:04 +00:00
# ---------- Cron ------------
casper.then ->
helpers.reset()
helpers.addTasks(['todo'])
2013-01-28 23:09:04 +00:00
casper.then ->
helpers.cronBeforeAfter (model) ->
2013-01-28 23:09:04 +00:00
casper.then ->
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"
2013-01-28 23:09:04 +00:00
2013-01-28 22:43:50 +00:00
# ---------- Run ------------
casper.run ->
casper.test.renderResults true