mirror of
https://github.com/sudoxnym/habitica.git
synced 2026-08-01 15:31:16 +00:00
using eval tests
This commit is contained in:
parent
2570e5e134
commit
c9112feaf7
3 changed files with 61 additions and 46 deletions
|
|
@ -12,59 +12,65 @@ casper.start helpers.playUrl, ->
|
|||
helpers.getModel (err, newModel) ->
|
||||
casper.test.assert(newModel.user.stats.exp > model.user.stats.exp, 'XP has increased after clicking habits "+"')
|
||||
casper.test.assert(newModel.user.stats.gp > model.user.stats.gp, 'GP has increased after clicking habits "+"')
|
||||
|
||||
#click .habits "-" and see if HP is going down
|
||||
casper.then ->
|
||||
helpers.getModel (err, model) ->
|
||||
casper.test.assertEquals(typeof model.user.stats.hp, "number", 'HP is number')
|
||||
casper.test.assertEquals(model.user.stats.hp, 50, 'HP == 50')
|
||||
casper.click '.habits a[data-direction="down"]'
|
||||
helpers.getModel (err, newModel) ->
|
||||
casper.test.assert(newModel.user.stats.hp < model.user.stats.hp, 'HP has decreased after clicking habits "-"')
|
||||
|
||||
#click .todo.uncompleted and see if GP and XP are going up.
|
||||
casper.then ->
|
||||
helpers.getModel (err, model) ->
|
||||
casper.click '.task.todo.uncompleted input[type=checkbox]'
|
||||
helpers.getModel (err, newModel) ->
|
||||
casper.test.assert(newModel.user.stats.exp > model.user.stats.exp, 'XP has increased after checking uncompleted todo')
|
||||
casper.test.assert(newModel.user.stats.gp > model.user.stats.gp, 'GP has increased after checking uncompleted todo')
|
||||
#
|
||||
##click .habits "-" and see if HP is going down
|
||||
#casper.then ->
|
||||
# helpers.getModel (err, model) ->
|
||||
# casper.test.assertEquals(typeof model.user.stats.hp, "number", 'HP is number')
|
||||
# casper.test.assertEquals(model.user.stats.hp, 50, 'HP == 50')
|
||||
# casper.click '.habits a[data-direction="down"]'
|
||||
# helpers.getModel (err, newModel) ->
|
||||
# casper.test.assert(newModel.user.stats.hp < model.user.stats.hp, 'HP has decreased after clicking habits "-"')
|
||||
#
|
||||
##click .todo.uncompleted and see if GP and XP are going up.
|
||||
#casper.then ->
|
||||
# helpers.getModel (err, model) ->
|
||||
# casper.click '.task.todo.uncompleted input[type=checkbox]'
|
||||
# helpers.getModel (err, newModel) ->
|
||||
# casper.test.assert(newModel.user.stats.exp > model.user.stats.exp,
|
||||
# 'XP has increased after checking uncompleted todo')
|
||||
# casper.test.assert(newModel.user.stats.gp > model.user.stats.gp,
|
||||
# 'GP has increased after checking uncompleted todo')
|
||||
#
|
||||
#
|
||||
##click .todo.completed and see if GP and XP are going down.
|
||||
#casper.then ->
|
||||
# helpers.getModel (err, model) ->
|
||||
# casper.click '.task.todo.completed input[type=checkbox]'
|
||||
# helpers.getModel (err, newModel) ->
|
||||
# casper.test.assert(newModel.user.stats.exp < model.user.stats.exp,
|
||||
# 'XP has increased after unchecking completed todo')
|
||||
# casper.test.assert(newModel.user.stats.gp < model.user.stats.gp,
|
||||
# 'GP has increased after unchecking completed todo')
|
||||
#
|
||||
##click .daily.uncompleted and see if GP and XP are going up.
|
||||
#casper.then ->
|
||||
# helpers.getModel (err, model) ->
|
||||
# casper.click '.task.daily.uncompleted input[type=checkbox]'
|
||||
# helpers.getModel (err, newModel) ->
|
||||
# casper.test.assert(newModel.user.stats.exp > model.user.stats.exp,
|
||||
# 'XP has increased after checking uncompleted daliy')
|
||||
# casper.test.assert(newModel.user.stats.gp > model.user.stats.gp,
|
||||
# 'GP has increased after checking uncompleted daliy')
|
||||
|
||||
|
||||
#click .todo.completed and see if GP and XP are going down.
|
||||
casper.then ->
|
||||
helpers.getModel (err, model) ->
|
||||
casper.click '.task.todo.completed input[type=checkbox]'
|
||||
helpers.getModel (err, newModel) ->
|
||||
casper.test.assert(newModel.user.stats.exp < model.user.stats.exp, 'XP has increased after unchecking completed todo')
|
||||
casper.test.assert(newModel.user.stats.gp < model.user.stats.gp, 'GP has increased after unchecking completed todo')
|
||||
|
||||
#click .daily.uncompleted and see if GP and XP are going up.
|
||||
#click .daily.uncompleted and see if GP and EXP are going up.
|
||||
casper.then ->
|
||||
helpers.getModel (err, model) ->
|
||||
casper.click '.task.daily.uncompleted input[type=checkbox]'
|
||||
helpers.getModel (err, newModel) ->
|
||||
casper.test.assert(newModel.user.stats.exp > model.user.stats.exp, 'XP has increased after checking uncompleted daliy')
|
||||
casper.test.assert(newModel.user.stats.gp > model.user.stats.gp, 'GP has increased after checking uncompleted daliy')
|
||||
|
||||
|
||||
#click .daily.completed and see if GP and XP are going down.
|
||||
casper.then ->
|
||||
helpers.getModel (err, model) ->
|
||||
casper.click '.task.daily.completed input[type=checkbox]'
|
||||
helpers.getModel (err, newModel) ->
|
||||
casper.test.assert(newModel.user.stats.exp < model.user.stats.exp, 'XP has increased after unchecking completed daliy')
|
||||
casper.test.assert(newModel.user.stats.gp < model.user.stats.gp, 'GP has increased after unchecking completed daliy')
|
||||
|
||||
helpers.evalTest(
|
||||
-> #check function
|
||||
casper.evaluate ((exp)->
|
||||
console.log "Is: " + window.DERBY.app.model.get('_user.stats.exp') + " Was:" + exp
|
||||
(window.DERBY.app.model.get('_user.stats.exp') > exp)), model.user.stats.exp
|
||||
'EXP has increased after checking uncompleted daliy'
|
||||
)
|
||||
|
||||
# ---------- finish tests ------------
|
||||
casper.then ->
|
||||
casper.test.done()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# ---------- Run ------------
|
||||
casper.run ->
|
||||
casper.test.renderResults true
|
||||
|
|
@ -2,7 +2,7 @@ utils = require('utils')
|
|||
|
||||
#enable this to get remote console output, useful for debug.
|
||||
casper.on "remote.message", (msg)->
|
||||
casper.echo "Remote console: "+msg
|
||||
casper.echo "Remote console: " + msg
|
||||
|
||||
casper.helpers = (->
|
||||
baseUrl = 'http://localhost:3000'
|
||||
|
|
@ -12,10 +12,10 @@ casper.helpers = (->
|
|||
casper.evaluate ->
|
||||
user = window.DERBY.app.model.get('_user')
|
||||
#wait till all fields get ready
|
||||
check = (typeof user == "object" && typeof user.stats == "object" && typeof user.stats.exp == 'number')
|
||||
check = (user?.stats?.exp?)
|
||||
#assign to the window so we can access it later
|
||||
window.userCopy = userCopy =
|
||||
{}
|
||||
{}
|
||||
#dirty hack to get all fields in the object
|
||||
for k of user
|
||||
userCopy[k] = user[k]
|
||||
|
|
@ -25,6 +25,14 @@ casper.helpers = (->
|
|||
{user: window.userCopy}
|
||||
cb null, model
|
||||
)
|
||||
evalTest = (check, text) ->
|
||||
casper.waitFor(
|
||||
check
|
||||
-> #run this if check passed
|
||||
casper.test.assert(true, text)
|
||||
-> #run this if timeout
|
||||
casper.test.assert(false, text)
|
||||
)
|
||||
|
||||
{
|
||||
casper: casper
|
||||
|
|
@ -32,4 +40,5 @@ casper.helpers = (->
|
|||
playUrl: baseUrl + '/?play=1'
|
||||
getModel: getModel
|
||||
uid: Math.random().toString(36).substring(2) + Math.random().toString(36).substring(2)
|
||||
evalTest: evalTest
|
||||
})()
|
||||
|
|
|
|||
|
|
@ -5,5 +5,5 @@
|
|||
5) So far phantomJS is given new userID every time so app.reset,app.revive is not necessary. I'll add it later.
|
||||
|
||||
To run the tests run from terminal:
|
||||
cd test2
|
||||
cd test/test2
|
||||
casperjs test ./casper/ --includes=./lib/helpers.coffee
|
||||
Loading…
Reference in a new issue