mirror of
https://github.com/sudoxnym/habitica.git
synced 2026-08-04 09:39:23 +00:00
stats tests ok
tests splitted into files add.items tests fail
This commit is contained in:
parent
51f054e51c
commit
2570e5e134
5 changed files with 129 additions and 36 deletions
39
test/test2/casper/add.items.coffee
Normal file
39
test/test2/casper/add.items.coffee
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
helpers = casper.helpers
|
||||
uid = helpers.uid
|
||||
# test creation of Todos, Rewards, Habits, etc
|
||||
|
||||
casper.start helpers.playUrl, ->
|
||||
helpers.getModel (err, model) ->
|
||||
tasksCount=0
|
||||
for own key,value of model.user.tasks
|
||||
tasksCount++
|
||||
utils.dump model.user.tasks
|
||||
casper.fill "form[data-task-type='habit']", {
|
||||
'new-task': 'Habit' + uid
|
||||
}, true
|
||||
helpers.getModel (err, model) ->
|
||||
newTasksCount=0
|
||||
for own key,value of model.user.tasks
|
||||
newTasksCount++
|
||||
casper.echo "Tasks new: " + tasksCount
|
||||
casper.test.assert(newTasksCount>tasksCount,"Task list increases in length after new habit form submitted")
|
||||
|
||||
|
||||
#casper.then ->
|
||||
# helpers.getModel (err, model) ->
|
||||
# casper.test.assertEquals(typeof model.user.stats.exp, "number", 'XP is number')
|
||||
# casper.test.assertEquals(model.user.stats.exp, 0, 'XP == 0')
|
||||
# casper.click '.habits a[data-direction="up"]'
|
||||
# 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 "+"')
|
||||
|
||||
|
||||
# ---------- finish tests ------------
|
||||
casper.then ->
|
||||
casper.test.done()
|
||||
|
||||
|
||||
# ---------- Run ------------
|
||||
casper.run ->
|
||||
casper.test.renderResults true
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
helpers = new require('./lib/helpers')()
|
||||
casper = helpers.casper
|
||||
utils = helpers.utils
|
||||
url = helpers.playUrl
|
||||
|
||||
casper.on('remote.message'
|
||||
(msg) ->
|
||||
this.echo '[Console] : ' + msg
|
||||
)
|
||||
|
||||
# ---------- Basic Test ------------
|
||||
casper.start url, ->
|
||||
helpers.getModel (model) ->
|
||||
casper.test.assertEquals(typeof model.user.stats.exp, "number", 'exp is number')
|
||||
casper.test.assertEquals(model.user.stats.exp, 0, 'exp == 0')
|
||||
casper.echo 'Clicking...'
|
||||
casper.click '.habits a[data-direction="up"]'
|
||||
casper.echo '...clicked'
|
||||
helpers.getModel (model) ->
|
||||
casper.test.assertEquals(model.user.stats.exp, 7.5, 'exp == 7.5')
|
||||
|
||||
|
||||
# ---------- Run ------------
|
||||
casper.run ->
|
||||
casper.test.renderResults true
|
||||
70
test/test2/casper/stats.coffee
Normal file
70
test/test2/casper/stats.coffee
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
#helpers = new require('./lib/helpers')()
|
||||
#casper = helpers.casper
|
||||
helpers = casper.helpers
|
||||
# ---------- Checks if clicking on the buttons changes stats and in right direction ------------
|
||||
|
||||
#click .habits "+" and see if GP and XP are going up.
|
||||
casper.start helpers.playUrl, ->
|
||||
helpers.getModel (err, model) ->
|
||||
casper.test.assertEquals(typeof model.user.stats.exp, "number", 'XP is number')
|
||||
casper.test.assertEquals(model.user.stats.exp, 0, 'XP == 0')
|
||||
casper.click '.habits a[data-direction="up"]'
|
||||
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 .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 .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')
|
||||
|
||||
|
||||
# ---------- finish tests ------------
|
||||
casper.then ->
|
||||
casper.test.done()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# ---------- Run ------------
|
||||
casper.run ->
|
||||
casper.test.renderResults true
|
||||
|
|
@ -1,11 +1,12 @@
|
|||
utils = require('utils')
|
||||
|
||||
module.exports = ->
|
||||
#enable this to get remote console output, useful for debug.
|
||||
casper.on "remote.message", (msg)->
|
||||
casper.echo "Remote console: "+msg
|
||||
|
||||
casper.helpers = (->
|
||||
baseUrl = 'http://localhost:3000'
|
||||
casper = require("casper").create
|
||||
clientScripts: 'lib/lodash.min.js'
|
||||
getModel = (cb)->
|
||||
casper.echo 'Loading model...'
|
||||
casper.waitFor(
|
||||
-> #check function
|
||||
casper.evaluate ->
|
||||
|
|
@ -13,23 +14,22 @@ module.exports = ->
|
|||
#wait till all fields get ready
|
||||
check = (typeof user == "object" && typeof user.stats == "object" && typeof user.stats.exp == 'number')
|
||||
#assign to the window so we can access it later
|
||||
window.userCopy = userCopy = {}
|
||||
window.userCopy = userCopy =
|
||||
{}
|
||||
#dirty hack to get all fields in the object
|
||||
for k of user
|
||||
userCopy[k] = user[k]
|
||||
check
|
||||
-> #run this if check passed
|
||||
model = casper.evaluate ->
|
||||
{user: window.userCopy}
|
||||
casper.echo '...model loaded'
|
||||
utils.dump model.user.stats
|
||||
cb model
|
||||
{user: window.userCopy}
|
||||
cb null, model
|
||||
)
|
||||
|
||||
{
|
||||
casper: casper
|
||||
baseUrl: baseUrl
|
||||
playUrl: baseUrl + '/?play=1'
|
||||
utils: utils
|
||||
getModel: getModel
|
||||
}
|
||||
uid: Math.random().toString(36).substring(2) + Math.random().toString(36).substring(2)
|
||||
})()
|
||||
|
|
|
|||
9
test/test2/readme.md
Normal file
9
test/test2/readme.md
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
1) It is a bit verbose
|
||||
2) It needs to be refactored using "async" library. Somehow casper.then() is introducing bugs so I'm not going to use it until I figure out why exactly. Leave it as it is, I'll refactor as it grows.
|
||||
3) It does not use any timeouts along the way, which is a good thing.
|
||||
4) It runs consistently on my side (i.e. always passes).
|
||||
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
|
||||
casperjs test ./casper/ --includes=./lib/helpers.coffee
|
||||
Loading…
Reference in a new issue