2013-02-22 05:25:40 +08:00
|
|
|
/*global phantom:true */
|
|
|
|
|
2013-02-21 09:07:22 +08: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 13:01:18 +08:00
|
|
|
page.waitFor = function(desc, fn, timeout, after) {
|
2013-02-21 09:07:22 +08:00
|
|
|
var check,start,promise;
|
|
|
|
|
|
|
|
start = +new Date();
|
|
|
|
promise = {};
|
|
|
|
check = function() {
|
|
|
|
var r;
|
|
|
|
|
|
|
|
try {
|
|
|
|
r = page.evaluate(fn);
|
2013-02-23 04:41:12 +08:00
|
|
|
}
|
2013-02-21 09:07:22 +08:00
|
|
|
catch(err) {
|
|
|
|
// next time
|
|
|
|
}
|
|
|
|
|
2013-02-21 13:01:18 +08:00
|
|
|
var diff = (+new Date()) - start;
|
|
|
|
|
2013-02-21 09:07:22 +08:00
|
|
|
if(r) {
|
2013-02-21 13:01:18 +08:00
|
|
|
console.log("PASSED: " + desc + " " + diff + "ms" );
|
|
|
|
after(true);
|
2013-02-21 09:07:22 +08:00
|
|
|
} else {
|
2013-02-21 13:01:18 +08:00
|
|
|
if(diff > timeout) {
|
|
|
|
console.log("FAILED: " + desc + " " + diff + "ms");
|
|
|
|
after(false);
|
2013-02-21 09:07:22 +08:00
|
|
|
} else {
|
|
|
|
setTimeout(check, 50);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
check();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-02-21 13:01:18 +08: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-21 09:07:22 +08:00
|
|
|
} else {
|
2013-02-21 13:01:18 +08:00
|
|
|
console.log("SMOKE TEST FAILED");
|
2013-02-21 09:07:22 +08:00
|
|
|
}
|
2013-02-21 13:01:18 +08:00
|
|
|
phantom.exit();
|
2013-02-21 09:07:22 +08:00
|
|
|
};
|
|
|
|
|
2013-02-21 13:01:18 +08: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-23 04:41:12 +08:00
|
|
|
}
|
2013-02-21 13:01:18 +08:00
|
|
|
else if(action.navigate) {
|
|
|
|
console.log("NAVIGATE: " + action.desc);
|
|
|
|
page.evaluate(action.navigate);
|
|
|
|
performNextAction();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
performNextAction();
|
|
|
|
};
|
2013-02-21 09:07:22 +08:00
|
|
|
|
2013-02-21 13:01:18 +08:00
|
|
|
page.runTests = function(){
|
2013-02-21 09:07:22 +08:00
|
|
|
|
2013-02-27 10:18:23 +08:00
|
|
|
test("at least one topic shows up", function() {
|
2013-02-23 04:41:12 +08:00
|
|
|
return $('#topic-list tbody tr').length > 0;
|
2013-02-21 13:01:18 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
test("expect a log in button", function(){
|
2013-02-23 04:41:12 +08:00
|
|
|
return $('.current-username .btn').text() === 'Log In';
|
2013-02-21 13:01:18 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
navigate("navigate to first topic", function(){
|
2013-02-21 13:37:17 +08:00
|
|
|
Em.run.later(function(){
|
2014-04-10 14:57:23 +08:00
|
|
|
if ($('.main-link > a:first').length > 0) {
|
|
|
|
$('.main-link > a:first').click(); // topic list page
|
2014-03-14 03:03:30 +08:00
|
|
|
} else {
|
|
|
|
$('.featured-topic a.title:first').click(); // categories page
|
|
|
|
}
|
2013-02-21 13:37:17 +08:00
|
|
|
}, 500);
|
2013-02-21 13:01:18 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
test("at least one post body", function(){
|
2013-02-23 04:41:12 +08:00
|
|
|
return $('.topic-post').length > 0;
|
2013-02-21 13:01:18 +08:00
|
|
|
});
|
2013-02-23 04:41:12 +08:00
|
|
|
|
2013-02-21 13:01:18 +08:00
|
|
|
navigate("navigate to first user", function(){
|
2013-02-21 13:37:17 +08:00
|
|
|
// for whatever reason the clicks do not respond at the begining
|
|
|
|
// defering
|
|
|
|
Em.run.later(function(){
|
2013-10-04 02:17:25 +08:00
|
|
|
|
|
|
|
// Remove the popup action for testing
|
|
|
|
$('.topic-meta-data a:first').data('ember-action', '');
|
|
|
|
|
2013-02-23 04:41:12 +08:00
|
|
|
$('.topic-meta-data a:first').focus().click();
|
2013-02-21 13:37:17 +08:00
|
|
|
},500);
|
2013-02-21 13:01:18 +08:00
|
|
|
});
|
|
|
|
|
2013-10-17 04:01:41 +08:00
|
|
|
test("has details",function(){
|
|
|
|
return $('.details').length === 1;
|
2013-02-21 13:01:18 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
run();
|
|
|
|
};
|
|
|
|
|
|
|
|
page.open(system.args[1], function (status) {
|
|
|
|
console.log("Opened " + system.args[1]);
|
|
|
|
page.runTests();
|
2013-02-21 09:07:22 +08:00
|
|
|
});
|