2013-02-21 15:25:40 -06:00
|
|
|
/*global phantom:true */
|
|
|
|
|
2015-07-27 04:07:42 -05:00
|
|
|
console.log("Starting Discourse Smoke Test");
|
2013-02-20 19:07:22 -06:00
|
|
|
|
2015-07-27 04:07:42 -05:00
|
|
|
var system = require("system");
|
|
|
|
|
|
|
|
if (system.args.length !== 2) {
|
|
|
|
console.log("Expecting: phantomjs {smoke_test.js} {url}");
|
2013-02-20 19:07:22 -06:00
|
|
|
phantom.exit(1);
|
|
|
|
}
|
|
|
|
|
2017-05-12 15:40:38 -05:00
|
|
|
var TIMEOUT = 25000;
|
2015-07-27 04:07:42 -05:00
|
|
|
var page = require("webpage").create();
|
|
|
|
|
2017-05-17 06:24:43 -05:00
|
|
|
if (system.env["AUTH_USER"] && system.env["AUTH_PASSWORD"]) {
|
|
|
|
page.settings.userName = system.env["AUTH_USER"];
|
|
|
|
page.settings.password = system.env["AUTH_PASSWORD"];
|
|
|
|
}
|
|
|
|
|
2015-07-27 04:07:42 -05:00
|
|
|
page.viewportSize = {
|
|
|
|
width: 1366,
|
|
|
|
height: 768
|
|
|
|
};
|
|
|
|
|
2015-09-15 11:26:09 -05:00
|
|
|
// In the browser, when the cookies are disabled, it also disables the localStorage
|
|
|
|
// Here, we're mocking that behavior and making sure the application doesn't blow up
|
|
|
|
page.onInitialized = function() {
|
|
|
|
page.evaluate(function() {
|
|
|
|
localStorage["disableLocalStorage"] = true;
|
2015-09-16 05:18:48 -05:00
|
|
|
});
|
|
|
|
};
|
2015-09-15 11:26:09 -05:00
|
|
|
|
2015-11-06 13:09:03 -06:00
|
|
|
page.onConsoleMessage = function(msg) {
|
|
|
|
console.log(msg);
|
2016-08-17 16:59:18 -05:00
|
|
|
};
|
2013-02-20 19:07:22 -06:00
|
|
|
|
2015-07-27 04:07:42 -05:00
|
|
|
page.waitFor = function(desc, fn, cb) {
|
|
|
|
var start = +new Date();
|
2013-02-20 19:07:22 -06:00
|
|
|
|
2015-07-27 04:07:42 -05:00
|
|
|
var check = function() {
|
2013-02-20 19:07:22 -06:00
|
|
|
var r;
|
|
|
|
|
2015-07-27 04:07:42 -05:00
|
|
|
try { r = page.evaluate(fn); } catch (err) { }
|
2013-02-20 19:07:22 -06:00
|
|
|
|
2013-02-20 23:01:18 -06:00
|
|
|
var diff = (+new Date()) - start;
|
|
|
|
|
2015-07-27 04:07:42 -05:00
|
|
|
if (r) {
|
|
|
|
console.log("PASSED: " + desc + " - " + diff + "ms");
|
|
|
|
cb(true);
|
2013-02-20 19:07:22 -06:00
|
|
|
} else {
|
2015-07-27 04:07:42 -05:00
|
|
|
if (diff > TIMEOUT) {
|
|
|
|
console.log("FAILED: " + desc + " - " + diff + "ms");
|
2015-11-06 13:09:03 -06:00
|
|
|
page.render('/tmp/failed.png');
|
2017-01-17 04:40:46 -06:00
|
|
|
console.log('Content:' + page.content);
|
2015-07-27 04:07:42 -05:00
|
|
|
cb(false);
|
2013-02-20 19:07:22 -06:00
|
|
|
} else {
|
2015-07-27 04:07:42 -05:00
|
|
|
setTimeout(check, 25);
|
2013-02-20 19:07:22 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
check();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-02-20 23:01:18 -06:00
|
|
|
var actions = [];
|
|
|
|
|
2015-11-06 13:09:03 -06:00
|
|
|
function test(desc, fn) {
|
2015-07-27 04:07:42 -05:00
|
|
|
actions.push({ test: fn, desc: desc });
|
2015-09-16 05:18:48 -05:00
|
|
|
};
|
2013-02-20 23:01:18 -06:00
|
|
|
|
2016-08-17 16:59:18 -05:00
|
|
|
// function wait(delay) {
|
|
|
|
// actions.push({ wait: delay });
|
|
|
|
// }
|
2015-11-06 13:09:03 -06:00
|
|
|
|
|
|
|
function exec(desc, fn) {
|
2015-07-27 04:07:42 -05:00
|
|
|
actions.push({ exec: fn, desc: desc });
|
2015-09-16 05:18:48 -05:00
|
|
|
};
|
2015-07-27 04:07:42 -05:00
|
|
|
|
2015-11-06 13:09:03 -06:00
|
|
|
function execAsync(desc, delay, fn) {
|
2015-07-27 04:07:42 -05:00
|
|
|
actions.push({ execAsync: fn, delay: delay, desc: desc });
|
2015-09-16 05:18:48 -05:00
|
|
|
};
|
2015-07-27 04:07:42 -05:00
|
|
|
|
2016-08-17 16:59:18 -05:00
|
|
|
// function upload(input, path) {
|
|
|
|
// actions.push({ upload: path, input: input });
|
|
|
|
// };
|
2015-07-27 04:07:42 -05:00
|
|
|
|
2016-08-17 16:59:18 -05:00
|
|
|
// function screenshot(filename) {
|
|
|
|
// actions.push({ screenshot: filename });
|
|
|
|
// }
|
2013-02-20 23:01:18 -06:00
|
|
|
|
2015-11-06 13:09:03 -06:00
|
|
|
function run() {
|
2013-02-20 23:01:18 -06:00
|
|
|
var allPassed = true;
|
2015-07-27 04:07:42 -05:00
|
|
|
|
2013-02-20 23:01:18 -06:00
|
|
|
var done = function() {
|
2015-07-27 04:07:42 -05:00
|
|
|
console.log(allPassed ? "ALL PASSED" : "SMOKE TEST FAILED");
|
2013-02-20 23:01:18 -06:00
|
|
|
phantom.exit();
|
2013-02-20 19:07:22 -06:00
|
|
|
};
|
|
|
|
|
2015-07-27 04:07:42 -05:00
|
|
|
var performNextAction = function() {
|
|
|
|
if (!allPassed || actions.length === 0) {
|
2013-02-20 23:01:18 -06:00
|
|
|
done();
|
2015-07-27 04:07:42 -05:00
|
|
|
} else {
|
2013-02-20 23:01:18 -06:00
|
|
|
var action = actions[0];
|
|
|
|
actions = actions.splice(1);
|
2015-07-27 04:07:42 -05:00
|
|
|
if (action.test) {
|
|
|
|
page.waitFor(action.desc, action.test, function(success) {
|
2015-08-21 14:06:47 -05:00
|
|
|
allPassed = allPassed && success;
|
2013-02-20 23:01:18 -06:00
|
|
|
performNextAction();
|
|
|
|
});
|
2015-07-27 04:07:42 -05:00
|
|
|
} else if (action.exec) {
|
|
|
|
console.log("EXEC: " + action.desc);
|
2017-05-17 23:17:31 -05:00
|
|
|
page.evaluate(action.exec, system);
|
2015-07-27 04:07:42 -05:00
|
|
|
performNextAction();
|
|
|
|
} else if (action.execAsync) {
|
|
|
|
console.log("EXEC ASYNC: " + action.desc + " - " + action.delay + "ms");
|
|
|
|
setTimeout(function() {
|
|
|
|
page.evaluate(action.execAsync);
|
|
|
|
performNextAction();
|
|
|
|
}, action.delay);
|
|
|
|
} else if (action.upload) {
|
|
|
|
console.log("UPLOAD: " + action.upload);
|
|
|
|
page.uploadFile(action.input, action.upload);
|
|
|
|
performNextAction();
|
|
|
|
} else if (action.screenshot) {
|
|
|
|
console.log("SCREENSHOT: " + action.screenshot);
|
|
|
|
page.render(action.screenshot);
|
2013-02-20 23:01:18 -06:00
|
|
|
performNextAction();
|
2015-11-06 13:09:03 -06:00
|
|
|
} else if (action.wait) {
|
|
|
|
console.log("WAIT: " + action.wait + "ms");
|
|
|
|
setTimeout(function() {
|
|
|
|
performNextAction();
|
|
|
|
}, action.wait);
|
2013-02-20 23:01:18 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
performNextAction();
|
|
|
|
};
|
2013-02-20 19:07:22 -06:00
|
|
|
|
2015-07-27 04:07:42 -05:00
|
|
|
var runTests = function() {
|
|
|
|
|
2017-05-21 19:01:33 -05:00
|
|
|
test("expect a log in button in the header", function() {
|
|
|
|
return $("header .login-button").length;
|
2015-07-27 04:07:42 -05:00
|
|
|
});
|
2013-02-20 19:07:22 -06:00
|
|
|
|
2017-05-17 06:24:43 -05:00
|
|
|
execAsync("go to latest page", 500, function(){
|
|
|
|
window.location = "/latest";
|
|
|
|
});
|
|
|
|
|
2013-02-26 20:18:23 -06:00
|
|
|
test("at least one topic shows up", function() {
|
2016-12-19 10:19:10 -06:00
|
|
|
return $(".topic-list tbody tr").length;
|
2013-02-20 23:01:18 -06:00
|
|
|
});
|
|
|
|
|
2017-05-12 16:42:28 -05:00
|
|
|
execAsync("go to categories page", 500, function(){
|
|
|
|
window.location = "/categories";
|
|
|
|
});
|
|
|
|
|
|
|
|
test("can see categories on the page", function() {
|
|
|
|
return $('.category-list').length;
|
|
|
|
});
|
|
|
|
|
2015-07-27 04:07:42 -05:00
|
|
|
execAsync("navigate to 1st topic", 500, function() {
|
2016-08-17 16:59:18 -05:00
|
|
|
$(".main-link a.title:first").click();
|
2013-02-20 23:01:18 -06:00
|
|
|
});
|
|
|
|
|
2015-07-27 04:07:42 -05:00
|
|
|
test("at least one post body", function() {
|
2016-12-19 10:19:10 -06:00
|
|
|
return $(".topic-post").length;
|
2013-02-20 23:01:18 -06:00
|
|
|
});
|
|
|
|
|
2015-07-27 04:07:42 -05:00
|
|
|
execAsync("click on the 1st user", 500, function() {
|
|
|
|
// remove the popup action for testing
|
|
|
|
$(".topic-meta-data a:first").data("ember-action", "");
|
|
|
|
$(".topic-meta-data a:first").focus().click();
|
2013-02-20 23:01:18 -06:00
|
|
|
});
|
2013-02-22 14:41:12 -06:00
|
|
|
|
2015-07-27 04:07:42 -05:00
|
|
|
test("user has details", function() {
|
2016-12-19 10:19:10 -06:00
|
|
|
return $("#user-card .names").length;
|
2015-07-27 04:07:42 -05:00
|
|
|
});
|
2013-10-03 13:17:25 -05:00
|
|
|
|
2015-07-27 04:07:42 -05:00
|
|
|
exec("open login modal", function() {
|
|
|
|
$(".login-button").click();
|
|
|
|
});
|
|
|
|
|
|
|
|
test("login modal is open", function() {
|
2016-12-19 10:19:10 -06:00
|
|
|
return $(".login-modal").length;
|
2015-07-27 04:07:42 -05:00
|
|
|
});
|
|
|
|
|
2017-05-17 23:17:31 -05:00
|
|
|
exec("type in credentials & log in", function(system) {
|
|
|
|
$("#login-account-name").val(system.env['DISCOURSE_USERNAME'] || 'smoke_user').trigger("change");
|
|
|
|
$("#login-account-password").val(system.env["DISCOURSE_PASSWORD"] || 'P4ssw0rd').trigger("change");
|
2015-07-27 04:07:42 -05:00
|
|
|
$(".login-modal .btn-primary").click();
|
|
|
|
});
|
|
|
|
|
|
|
|
test("is logged in", function() {
|
2016-12-19 10:19:10 -06:00
|
|
|
return $(".current-user").length;
|
2015-07-27 04:07:42 -05:00
|
|
|
});
|
|
|
|
|
2015-11-06 13:09:03 -06:00
|
|
|
exec("go home", function() {
|
2017-05-19 09:33:06 -05:00
|
|
|
if ($('#site-logo').length) $('#site-logo').click();
|
|
|
|
if ($('#site-text-logo').length) $('#site-text-logo').click();
|
2015-11-06 13:09:03 -06:00
|
|
|
});
|
|
|
|
|
|
|
|
test("it shows a topic list", function() {
|
2016-12-19 10:19:10 -06:00
|
|
|
return $(".topic-list").length;
|
2015-11-06 13:09:03 -06:00
|
|
|
});
|
|
|
|
|
2016-05-23 22:25:47 -05:00
|
|
|
test('we have a create topic button', function() {
|
2016-12-19 10:19:10 -06:00
|
|
|
return $("#create-topic").length;
|
2016-05-23 22:25:47 -05:00
|
|
|
});
|
|
|
|
|
2015-11-06 13:09:03 -06:00
|
|
|
exec("open composer", function() {
|
|
|
|
$("#create-topic").click();
|
|
|
|
});
|
|
|
|
|
|
|
|
test('the editor is visible', function() {
|
2016-12-19 10:19:10 -06:00
|
|
|
return $(".d-editor").length;
|
2015-11-06 13:09:03 -06:00
|
|
|
});
|
|
|
|
|
2015-07-27 04:07:42 -05:00
|
|
|
exec("compose new topic", function() {
|
|
|
|
var date = " (" + (+new Date()) + ")",
|
|
|
|
title = "This is a new topic" + date,
|
|
|
|
post = "I can write a new topic inside the smoke test!" + date + "\n\n";
|
|
|
|
|
|
|
|
$("#reply-title").val(title).trigger("change");
|
2015-11-03 15:25:37 -06:00
|
|
|
$("#reply-control .d-editor-input").val(post).trigger("change");
|
|
|
|
$("#reply-control .d-editor-input").focus()[0].setSelectionRange(post.length, post.length);
|
2015-07-27 04:07:42 -05:00
|
|
|
});
|
|
|
|
|
2015-11-06 13:09:03 -06:00
|
|
|
test("updates preview", function() {
|
2016-12-19 10:19:10 -06:00
|
|
|
return $(".d-editor-preview p").length;
|
2015-11-06 13:09:03 -06:00
|
|
|
});
|
|
|
|
|
2015-07-27 04:07:42 -05:00
|
|
|
exec("open upload modal", function() {
|
2015-11-03 15:25:37 -06:00
|
|
|
$(".d-editor-button-bar .upload").click();
|
2015-07-27 04:07:42 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
test("upload modal is open", function() {
|
2016-12-19 10:19:10 -06:00
|
|
|
return $("#filename-input").length;
|
2015-07-27 04:07:42 -05:00
|
|
|
});
|
|
|
|
|
2015-11-06 13:21:52 -06:00
|
|
|
// TODO: Looks like PhantomJS 2.0.0 has a bug with `uploadFile`
|
|
|
|
// which breaks this code.
|
|
|
|
|
|
|
|
// upload("#filename-input", "spec/fixtures/images/large & unoptimized.png");
|
|
|
|
// test("the file is inserted into the input", function() {
|
|
|
|
// return document.getElementById('filename-input').files.length
|
|
|
|
// });
|
|
|
|
// screenshot('/tmp/upload-modal.png');
|
|
|
|
//
|
|
|
|
// test("upload modal is open", function() {
|
|
|
|
// return document.querySelector("#filename-input");
|
|
|
|
// });
|
|
|
|
//
|
|
|
|
// exec("click upload button", function() {
|
|
|
|
// $(".modal .btn-primary").click();
|
|
|
|
// });
|
|
|
|
//
|
|
|
|
// test("image is uploaded", function() {
|
|
|
|
// return document.querySelector(".cooked img");
|
|
|
|
// });
|
2015-07-27 04:07:42 -05:00
|
|
|
|
|
|
|
exec("submit the topic", function() {
|
|
|
|
$("#reply-control .create").click();
|
|
|
|
});
|
|
|
|
|
|
|
|
test("topic is created", function() {
|
2016-12-19 10:19:10 -06:00
|
|
|
return $(".fancy-title").length;
|
2015-07-27 04:07:42 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
exec("click reply button", function() {
|
|
|
|
$(".post-controls:first .create").click();
|
|
|
|
});
|
|
|
|
|
|
|
|
test("composer is open", function() {
|
2016-12-19 10:19:10 -06:00
|
|
|
return $("#reply-control .d-editor-input").length;
|
2015-07-27 04:07:42 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
exec("compose reply", function() {
|
|
|
|
var post = "I can even write a reply inside the smoke test ;) (" + (+new Date()) + ")";
|
2015-11-03 15:25:37 -06:00
|
|
|
$("#reply-control .d-editor-input").val(post).trigger("change");
|
2015-07-27 04:07:42 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
test("waiting for the preview", function() {
|
2015-11-03 15:25:37 -06:00
|
|
|
return $(".d-editor-preview").text().trim().indexOf("I can even write") === 0;
|
2015-07-27 04:07:42 -05:00
|
|
|
});
|
2013-10-03 13:17:25 -05:00
|
|
|
|
2015-07-27 04:07:42 -05:00
|
|
|
execAsync("submit the reply", 6000, function() {
|
|
|
|
$("#reply-control .create").click();
|
2013-02-20 23:01:18 -06:00
|
|
|
});
|
|
|
|
|
2015-07-27 04:07:42 -05:00
|
|
|
test("reply is created", function() {
|
|
|
|
return !document.querySelector(".saving-text")
|
|
|
|
&& $(".topic-post").length === 2;
|
2013-02-20 23:01:18 -06:00
|
|
|
});
|
|
|
|
|
|
|
|
run();
|
|
|
|
};
|
|
|
|
|
2015-11-06 13:09:03 -06:00
|
|
|
phantom.clearCookies();
|
2015-08-21 14:06:47 -05:00
|
|
|
page.open(system.args[1], function() {
|
2015-11-06 13:09:03 -06:00
|
|
|
page.evaluate(function() { localStorage.clear(); });
|
2015-07-27 04:07:42 -05:00
|
|
|
console.log("OPENED: " + system.args[1]);
|
|
|
|
runTests();
|
2013-02-20 19:07:22 -06:00
|
|
|
});
|