diff --git a/test/test2/casper/stats.coffee b/test/test2/casper/stats.coffee index 82f3e01c99..5e352a8cfc 100644 --- a/test/test2/casper/stats.coffee +++ b/test/test2/casper/stats.coffee @@ -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 \ No newline at end of file diff --git a/test/test2/lib/helpers.coffee b/test/test2/lib/helpers.coffee index 7798d40f80..090064e857 100644 --- a/test/test2/lib/helpers.coffee +++ b/test/test2/lib/helpers.coffee @@ -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 })() diff --git a/test/test2/readme.md b/test/test2/readme.md index ef54936ffe..a0567235cb 100644 --- a/test/test2/readme.md +++ b/test/test2/readme.md @@ -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 \ No newline at end of file