2013-02-21 16:25:40 -05:00
|
|
|
/*global phantom:true */
|
|
|
|
|
2013-02-20 20:07:22 -05:00
|
|
|
console.log('Starting Smoke Test');
|
|
|
|
var system = require('system');
|
|
|
|
|
|
|
|
if(system.args.length !== 2) {
|
|
|
|
console.log("expecting phantomjs {smoke_test.js} {base_url}");
|
|
|
|
phantom.exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
var page = require('webpage').create();
|
|
|
|
|
2013-02-21 00:01:18 -05:00
|
|
|
page.waitFor = function(desc, fn, timeout, after) {
|
2013-02-20 20:07:22 -05:00
|
|
|
var check,start,promise;
|
|
|
|
|
|
|
|
start = +new Date();
|
|
|
|
promise = {};
|
|
|
|
check = function() {
|
|
|
|
var r;
|
|
|
|
|
|
|
|
try {
|
|
|
|
r = page.evaluate(fn);
|
2013-02-22 15:41:12 -05:00
|
|
|
}
|
2013-02-20 20:07:22 -05:00
|
|
|
catch(err) {
|
|
|
|
// next time
|
|
|
|
}
|
|
|
|
|
2013-02-21 00:01:18 -05:00
|
|
|
var diff = (+new Date()) - start;
|
|
|
|
|
2013-02-20 20:07:22 -05:00
|
|
|
if(r) {
|
2013-02-21 00:01:18 -05:00
|
|
|
console.log("PASSED: " + desc + " " + diff + "ms" );
|
|
|
|
after(true);
|
2013-02-20 20:07:22 -05:00
|
|
|
} else {
|
2013-02-21 00:01:18 -05:00
|
|
|
if(diff > timeout) {
|
|
|
|
console.log("FAILED: " + desc + " " + diff + "ms");
|
|
|
|
after(false);
|
2013-02-20 20:07:22 -05:00
|
|
|
} else {
|
|
|
|
setTimeout(check, 50);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
check();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-02-21 00:01:18 -05:00
|
|
|
var actions = [];
|
|
|
|
|
|
|
|
var test = function(desc, fn) {
|
|
|
|
actions.push({test: fn, desc: desc});
|
|
|
|
};
|
|
|
|
|
|
|
|
var navigate = function(desc, fn) {
|
|
|
|
actions.push({navigate: fn, desc: desc});
|
|
|
|
};
|
|
|
|
|
|
|
|
var run = function(){
|
|
|
|
var allPassed = true;
|
|
|
|
var done = function() {
|
|
|
|
if(allPassed) {
|
|
|
|
console.log("ALL PASSED");
|
2013-02-20 20:07:22 -05:00
|
|
|
} else {
|
2013-02-21 00:01:18 -05:00
|
|
|
console.log("SMOKE TEST FAILED");
|
2013-02-20 20:07:22 -05:00
|
|
|
}
|
2013-02-21 00:01:18 -05:00
|
|
|
phantom.exit();
|
2013-02-20 20:07:22 -05:00
|
|
|
};
|
|
|
|
|
2013-02-21 00:01:18 -05:00
|
|
|
var performNextAction = function(){
|
|
|
|
if(actions.length === 0) {
|
|
|
|
done();
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
var action = actions[0];
|
|
|
|
actions = actions.splice(1);
|
|
|
|
if(action.test) {
|
|
|
|
page.waitFor(action.desc, action.test, 10000, function(success){
|
|
|
|
allPassed = allPassed && success;
|
|
|
|
performNextAction();
|
|
|
|
});
|
2013-02-22 15:41:12 -05:00
|
|
|
}
|
2013-02-21 00:01:18 -05:00
|
|
|
else if(action.navigate) {
|
|
|
|
console.log("NAVIGATE: " + action.desc);
|
|
|
|
page.evaluate(action.navigate);
|
|
|
|
performNextAction();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
performNextAction();
|
|
|
|
};
|
2013-02-20 20:07:22 -05:00
|
|
|
|
2013-02-21 00:01:18 -05:00
|
|
|
page.runTests = function(){
|
2013-02-20 20:07:22 -05:00
|
|
|
|
2013-02-26 21:18:23 -05:00
|
|
|
test("at least one topic shows up", function() {
|
2014-07-29 17:38:36 -04:00
|
|
|
return $('.topic-list tbody tr').length > 0;
|
2013-02-21 00:01:18 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
test("expect a log in button", function(){
|
2014-08-11 19:08:55 -04:00
|
|
|
return $('.login-button').text().trim() === 'Log In';
|
2013-02-21 00:01:18 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
navigate("navigate to first topic", function(){
|
2013-02-21 00:37:17 -05:00
|
|
|
Em.run.later(function(){
|
2014-04-10 02:57:23 -04:00
|
|
|
if ($('.main-link > a:first').length > 0) {
|
|
|
|
$('.main-link > a:first').click(); // topic list page
|
2014-03-13 15:03:30 -04:00
|
|
|
} else {
|
|
|
|
$('.featured-topic a.title:first').click(); // categories page
|
|
|
|
}
|
2013-02-21 00:37:17 -05:00
|
|
|
}, 500);
|
2013-02-21 00:01:18 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
test("at least one post body", function(){
|
2013-02-22 15:41:12 -05:00
|
|
|
return $('.topic-post').length > 0;
|
2013-02-21 00:01:18 -05:00
|
|
|
});
|
2013-02-22 15:41:12 -05:00
|
|
|
|
2013-02-21 00:01:18 -05:00
|
|
|
navigate("navigate to first user", function(){
|
2013-02-21 00:37:17 -05:00
|
|
|
// for whatever reason the clicks do not respond at the begining
|
|
|
|
// defering
|
|
|
|
Em.run.later(function(){
|
2013-10-03 14:17:25 -04:00
|
|
|
|
|
|
|
// Remove the popup action for testing
|
|
|
|
$('.topic-meta-data a:first').data('ember-action', '');
|
|
|
|
|
2013-02-22 15:41:12 -05:00
|
|
|
$('.topic-meta-data a:first').focus().click();
|
2013-02-21 00:37:17 -05:00
|
|
|
},500);
|
2013-02-21 00:01:18 -05:00
|
|
|
});
|
|
|
|
|
2013-10-16 16:01:41 -04:00
|
|
|
test("has details",function(){
|
2014-10-20 12:11:36 -04:00
|
|
|
return $('#user-card .names').length === 1;
|
2013-02-21 00:01:18 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
run();
|
|
|
|
};
|
|
|
|
|
|
|
|
page.open(system.args[1], function (status) {
|
|
|
|
console.log("Opened " + system.args[1]);
|
|
|
|
page.runTests();
|
2013-02-20 20:07:22 -05:00
|
|
|
});
|