mirror of
https://github.com/zulip/zulip.git
synced 2025-11-04 22:13:26 +00:00
casper: Improve common.js.
These changes prepare us for the casperjs upgrade:
Extract init_viewport().
Have then_log_out() do more explicit waiting.
Add turn_off_press_enter_to_send().
This commit is contained in:
@@ -24,6 +24,11 @@ function log_in(credentials) {
|
||||
}, true /* submit form */);
|
||||
}
|
||||
|
||||
|
||||
exports.init_viewport = function () {
|
||||
casper.options.viewportSize = {width: 1280, height: 1024};
|
||||
};
|
||||
|
||||
exports.initialize_casper = function (viewport) {
|
||||
if (casper.zulip_initialized !== undefined) {
|
||||
return;
|
||||
@@ -32,9 +37,6 @@ exports.initialize_casper = function (viewport) {
|
||||
// These initialization steps will fail if they run before
|
||||
// casper.start has been called.
|
||||
|
||||
// Set default viewport size to something reasonable
|
||||
casper.page.viewportSize = viewport || {width: 1280, height: 1024};
|
||||
|
||||
// Fail if we get a JavaScript error in the page's context.
|
||||
// Based on the example at http://phantomjs.org/release-1.5.html
|
||||
//
|
||||
@@ -90,6 +92,7 @@ exports.start_and_log_in = function (credentials, viewport) {
|
||||
} else {
|
||||
log_in_url = "http://localhost:9981/accounts/login";
|
||||
}
|
||||
exports.init_viewport();
|
||||
casper.start(log_in_url, function () {
|
||||
exports.initialize_casper(viewport);
|
||||
log_in(credentials);
|
||||
@@ -97,11 +100,22 @@ exports.start_and_log_in = function (credentials, viewport) {
|
||||
};
|
||||
|
||||
exports.then_log_out = function () {
|
||||
casper.then(function () {
|
||||
var menu_selector = '#settings-dropdown';
|
||||
var logout_selector = 'li[title="Log out"] a';
|
||||
|
||||
casper.waitUntilVisible(menu_selector, function () {
|
||||
casper.click(menu_selector);
|
||||
|
||||
casper.waitUntilVisible(logout_selector, function () {
|
||||
casper.test.info('Logging out');
|
||||
casper.click('li[title="Log out"] a');
|
||||
casper.click(logout_selector);
|
||||
|
||||
casper.then(function () {
|
||||
casper.test.assertUrlMatch(/accounts\/login\/$/);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
casper.waitForSelector(".login-page-header", function () {
|
||||
casper.test.info("Logged out");
|
||||
});
|
||||
@@ -166,6 +180,19 @@ exports.wait_for_message_actually_sent = function () {
|
||||
});
|
||||
};
|
||||
|
||||
exports.turn_off_press_enter_to_send = function () {
|
||||
var enter_send_selector = '#enter_sends';
|
||||
casper.waitForSelector(enter_send_selector);
|
||||
|
||||
var is_checked = casper.evaluate(function (enter_send_selector) {
|
||||
return document.querySelector(enter_send_selector).checked;
|
||||
}, enter_send_selector);
|
||||
|
||||
if (is_checked) {
|
||||
casper.click(enter_send_selector);
|
||||
}
|
||||
};
|
||||
|
||||
// Wait for any previous send to finish, then send a message.
|
||||
exports.then_send_message = function (type, params) {
|
||||
casper.then(function () {
|
||||
@@ -182,8 +209,13 @@ exports.then_send_message = function (type, params) {
|
||||
casper.test.assertTrue(false, "send_message got valid message type");
|
||||
}
|
||||
casper.fill('form[action^="/json/messages"]', params);
|
||||
|
||||
exports.turn_off_press_enter_to_send();
|
||||
|
||||
casper.then(function () {
|
||||
casper.click('#compose-send-button');
|
||||
});
|
||||
});
|
||||
|
||||
casper.then(function () {
|
||||
casper.waitFor(function emptyComposeBox() {
|
||||
|
||||
@@ -8,6 +8,7 @@ if (REALMS_HAVE_SUBDOMAINS) {
|
||||
realm_url = "http://localhost:9981/";
|
||||
}
|
||||
// Start of test script.
|
||||
common.init_viewport();
|
||||
casper.start(realm_url, common.initialize_casper);
|
||||
|
||||
casper.then(function () {
|
||||
|
||||
Reference in New Issue
Block a user