2020-08-01 03:43:15 +02:00
|
|
|
"use strict";
|
|
|
|
|
2017-06-07 08:43:39 +02:00
|
|
|
var util = require("util");
|
2013-03-05 17:05:12 +01:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
var test_credentials = require("../../var/casper/test_credentials.js").test_credentials;
|
2015-08-20 02:57:30 +02:00
|
|
|
|
2020-02-28 23:59:07 +01:00
|
|
|
casper.options.clientScripts.push("frontend_tests/casper_lib/polyfill.js");
|
|
|
|
|
2013-03-20 23:59:44 +01:00
|
|
|
function timestamp() {
|
|
|
|
return new Date().getTime();
|
|
|
|
}
|
|
|
|
|
|
|
|
// The timestamp of the last message send or get_events result.
|
|
|
|
var last_send_or_update = -1;
|
|
|
|
|
2020-03-31 14:18:28 +02:00
|
|
|
function log_in() {
|
|
|
|
var credentials = test_credentials.default_user;
|
2013-03-05 20:52:54 +01:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
casper.test.info("Logging in");
|
2020-07-15 00:34:28 +02:00
|
|
|
casper.fill(
|
|
|
|
'form[action^="/accounts/login/"]',
|
|
|
|
{
|
|
|
|
username: credentials.username,
|
|
|
|
password: credentials.password,
|
|
|
|
},
|
|
|
|
true /* submit form */
|
|
|
|
);
|
2013-03-05 20:52:54 +01:00
|
|
|
}
|
2013-03-05 17:05:12 +01:00
|
|
|
|
2016-10-07 18:15:12 +02:00
|
|
|
exports.init_viewport = function () {
|
|
|
|
casper.options.viewportSize = {width: 1280, height: 1024};
|
|
|
|
};
|
|
|
|
|
2020-03-31 14:39:19 +02:00
|
|
|
// This function should always be enclosed within a then() otherwise
|
|
|
|
// it might not exist on casper object.
|
|
|
|
exports.wait_for_text = function (selector, text, then, onTimeout, timeout) {
|
2020-07-15 00:34:28 +02:00
|
|
|
casper.waitForSelector(
|
|
|
|
selector,
|
|
|
|
function _then() {
|
|
|
|
casper.waitFor(
|
|
|
|
function _check() {
|
|
|
|
var content = casper.fetchText(selector);
|
|
|
|
if (util.isRegExp(text)) {
|
|
|
|
return text.test(content);
|
|
|
|
}
|
|
|
|
return content.indexOf(text) !== -1;
|
|
|
|
},
|
|
|
|
then,
|
|
|
|
onTimeout,
|
|
|
|
timeout
|
|
|
|
);
|
|
|
|
},
|
|
|
|
onTimeout,
|
|
|
|
timeout
|
|
|
|
);
|
2020-03-31 14:39:19 +02:00
|
|
|
};
|
|
|
|
|
2016-12-02 14:06:06 +01:00
|
|
|
exports.initialize_casper = function () {
|
2014-03-07 23:46:33 +01:00
|
|
|
if (casper.zulip_initialized !== undefined) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
casper.zulip_initialized = true;
|
2013-03-20 23:09:46 +01:00
|
|
|
// These initialization steps will fail if they run before
|
|
|
|
// casper.start has been called.
|
|
|
|
|
|
|
|
// Fail if we get a JavaScript error in the page's context.
|
2020-03-27 01:32:21 +01:00
|
|
|
// Based on the example at https://phantomjs.org/release-1.5.html
|
2013-03-20 23:09:46 +01:00
|
|
|
//
|
|
|
|
// casper.on('error') doesn't work (it never gets called) so we
|
|
|
|
// set this at the PhantomJS level.
|
|
|
|
casper.page.onError = function (msg, trace) {
|
|
|
|
casper.test.error(msg);
|
2020-07-15 01:29:15 +02:00
|
|
|
casper.echo("Traceback:");
|
2013-03-20 23:09:46 +01:00
|
|
|
trace.forEach(function (item) {
|
2020-07-15 01:29:15 +02:00
|
|
|
casper.echo(" " + item.file + ":" + item.line);
|
2013-03-20 23:09:46 +01:00
|
|
|
});
|
|
|
|
casper.exit(1);
|
|
|
|
};
|
|
|
|
|
|
|
|
// Capture screens from all failures
|
|
|
|
var casper_failure_count = 1;
|
2020-07-15 01:29:15 +02:00
|
|
|
casper.test.on("fail", function failure() {
|
2013-03-20 23:09:46 +01:00
|
|
|
if (casper_failure_count <= 10) {
|
2016-09-27 10:12:40 +02:00
|
|
|
casper.capture("var/casper/casper-failure" + casper_failure_count + ".png");
|
2016-11-30 19:05:04 +01:00
|
|
|
casper_failure_count += 1;
|
2013-03-20 23:09:46 +01:00
|
|
|
}
|
|
|
|
});
|
2013-03-20 23:59:44 +01:00
|
|
|
|
|
|
|
// Update last_send_or_update whenever get_events returns.
|
2020-07-15 01:29:15 +02:00
|
|
|
casper.on("resource.received", function (resource) {
|
2013-03-20 23:59:44 +01:00
|
|
|
if (/\/json\/get_events/.test(resource.url)) {
|
|
|
|
last_send_or_update = timestamp();
|
|
|
|
}
|
|
|
|
});
|
2014-03-10 22:48:47 +01:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
casper.on("load.finished", function () {
|
|
|
|
casper.test.info("page load finished");
|
2014-03-07 00:44:15 +01:00
|
|
|
});
|
|
|
|
|
2014-03-10 22:48:47 +01:00
|
|
|
casper.evaluate(function () {
|
|
|
|
window.localStorage.clear();
|
|
|
|
});
|
2018-01-11 22:24:00 +01:00
|
|
|
|
|
|
|
// This captures console messages from the app.
|
2020-07-15 01:29:15 +02:00
|
|
|
casper.on("remote.message", function (msg) {
|
2018-01-11 22:24:00 +01:00
|
|
|
casper.echo("app console: " + msg);
|
|
|
|
});
|
2013-03-20 23:09:46 +01:00
|
|
|
};
|
|
|
|
|
2020-03-31 14:18:28 +02:00
|
|
|
exports.start_and_log_in = function () {
|
2018-12-04 02:12:08 +01:00
|
|
|
var log_in_url = "http://zulip.zulipdev.com:9981/accounts/login/";
|
2016-10-07 18:15:12 +02:00
|
|
|
exports.init_viewport();
|
2016-07-19 14:35:08 +02:00
|
|
|
casper.start(log_in_url, function () {
|
2020-03-31 14:18:28 +02:00
|
|
|
exports.initialize_casper();
|
|
|
|
log_in();
|
2013-03-05 17:05:12 +01:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2017-12-28 00:08:58 +01:00
|
|
|
exports.then_click = function (selector) {
|
|
|
|
casper.then(function () {
|
|
|
|
casper.waitUntilVisible(selector, function () {
|
|
|
|
casper.click(selector);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2020-03-31 15:03:34 +02:00
|
|
|
exports.then_log_in = function () {
|
|
|
|
casper.then(function () {
|
|
|
|
log_in();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2013-03-05 20:52:54 +01:00
|
|
|
exports.then_log_out = function () {
|
2020-07-15 01:29:15 +02:00
|
|
|
var menu_selector = "#settings-dropdown";
|
2017-08-16 12:33:02 +02:00
|
|
|
var logout_selector = 'a[href="#logout"]';
|
2016-10-07 18:15:12 +02:00
|
|
|
|
|
|
|
casper.waitUntilVisible(menu_selector, function () {
|
|
|
|
casper.click(menu_selector);
|
|
|
|
|
|
|
|
casper.waitUntilVisible(logout_selector, function () {
|
2020-07-15 01:29:15 +02:00
|
|
|
casper.test.info("Logging out");
|
2016-10-07 18:15:12 +02:00
|
|
|
casper.click(logout_selector);
|
|
|
|
});
|
|
|
|
});
|
2017-04-20 21:02:56 +02:00
|
|
|
casper.waitUntilVisible(".login-page-container", function () {
|
2016-10-13 02:28:39 +02:00
|
|
|
casper.test.assertUrlMatch(/accounts\/login\/$/);
|
2016-10-03 12:08:18 +02:00
|
|
|
casper.test.info("Logged out");
|
|
|
|
});
|
2013-03-05 17:05:12 +01:00
|
|
|
};
|
|
|
|
|
2016-06-09 09:29:49 +02:00
|
|
|
// Put the specified string into the field_selector, then
|
|
|
|
// select the menu item matching item by typing str.
|
|
|
|
exports.select_item_via_typeahead = function (field_selector, str, item) {
|
|
|
|
casper.then(function () {
|
2020-07-15 01:29:15 +02:00
|
|
|
casper.test.info("Looking in " + field_selector + " to select " + str + ", " + item);
|
2016-06-09 09:29:49 +02:00
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
casper.evaluate(
|
|
|
|
function (field_selector, str, item) {
|
|
|
|
// Set the value and then send a bogus keyup event to trigger
|
|
|
|
// the typeahead.
|
|
|
|
$(field_selector)
|
2020-07-20 21:24:26 +02:00
|
|
|
.trigger("focus")
|
2020-07-15 00:34:28 +02:00
|
|
|
.val(str)
|
|
|
|
.trigger($.Event("keyup", {which: 0}));
|
|
|
|
|
|
|
|
// You might think these steps should be split by casper.then,
|
|
|
|
// but apparently that's enough to make the typeahead close (??),
|
|
|
|
// but not the first time.
|
|
|
|
|
|
|
|
// Trigger the typeahead.
|
|
|
|
// Reaching into the guts of Bootstrap Typeahead like this is not
|
|
|
|
// great, but I found it very hard to do it any other way.
|
|
|
|
|
|
|
|
var tah = $(field_selector).data().typeahead;
|
|
|
|
tah.mouseenter({
|
|
|
|
currentTarget: $('.typeahead:visible li:contains("' + item + '")')[0],
|
|
|
|
});
|
|
|
|
tah.select();
|
|
|
|
},
|
|
|
|
{field_selector: field_selector, str: str, item: item}
|
|
|
|
);
|
2016-06-09 09:29:49 +02:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2013-06-11 23:08:11 +02:00
|
|
|
exports.check_form = function (form_selector, expected, test_name) {
|
|
|
|
var values = casper.getFormValues(form_selector);
|
|
|
|
var k;
|
|
|
|
for (k in expected) {
|
2020-05-27 00:50:02 +02:00
|
|
|
if (Object.prototype.hasOwnProperty.call(expected, k)) {
|
2020-07-15 00:34:28 +02:00
|
|
|
casper.test.assertEqual(
|
|
|
|
values[k],
|
|
|
|
expected[k],
|
|
|
|
test_name ? test_name + ": " + k : undefined
|
|
|
|
);
|
2013-06-11 23:08:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-03-26 12:25:10 +01:00
|
|
|
exports.wait_for_message_fully_processed = function (content) {
|
2016-10-03 14:07:45 +02:00
|
|
|
casper.waitFor(function () {
|
2020-07-15 00:34:28 +02:00
|
|
|
return casper.evaluate(
|
|
|
|
function (content) {
|
|
|
|
/*
|
2020-03-26 12:25:10 +01:00
|
|
|
The tricky part about making sure that
|
|
|
|
a message has actually been fully processed
|
|
|
|
is that we'll "locally echo" the message
|
|
|
|
first on the client. Until the server
|
|
|
|
actually acks the message, the message will
|
|
|
|
have a temporary id and will not have all
|
|
|
|
the normal message controls.
|
|
|
|
|
|
|
|
For the Casper tests, we want to avoid all
|
|
|
|
the edge cases with locally echoed messages.
|
|
|
|
|
|
|
|
In order to make sure a message is processed,
|
|
|
|
we use internals to determine the following:
|
|
|
|
- has message_list even been updated with
|
|
|
|
the message with out content?
|
|
|
|
- has the locally_echoed flag been cleared?
|
|
|
|
|
|
|
|
But for the final steps we look at the
|
|
|
|
actual DOM (via JQuery):
|
|
|
|
- is it visible?
|
|
|
|
- does it look to have been
|
|
|
|
re-rendered based on server info?
|
|
|
|
*/
|
2020-08-01 04:36:12 +02:00
|
|
|
var last_msg = current_msg_list.last();
|
2020-03-26 12:25:10 +01:00
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
if (last_msg.raw_content !== content) {
|
|
|
|
return false;
|
|
|
|
}
|
2020-03-26 12:25:10 +01:00
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
if (last_msg.locally_echoed) {
|
|
|
|
return false;
|
|
|
|
}
|
2020-03-26 12:25:10 +01:00
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
var row = rows.last_visible();
|
2020-03-26 12:25:10 +01:00
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
if (rows.id(row) !== last_msg.id) {
|
|
|
|
return false;
|
|
|
|
}
|
2020-03-26 12:25:10 +01:00
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
/*
|
2020-03-26 12:25:10 +01:00
|
|
|
Make sure the message is completely
|
|
|
|
re-rendered from its original "local echo"
|
|
|
|
version by looking for the star icon. We
|
|
|
|
don't add the star icon until the server
|
|
|
|
responds.
|
|
|
|
*/
|
2020-07-15 00:34:28 +02:00
|
|
|
return row.find(".star").length === 1;
|
|
|
|
},
|
|
|
|
{content: content}
|
|
|
|
);
|
2016-10-03 14:07:45 +02:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2016-10-07 18:15:12 +02:00
|
|
|
exports.turn_off_press_enter_to_send = function () {
|
2020-07-15 01:29:15 +02:00
|
|
|
var enter_send_selector = "#enter_sends";
|
2016-10-07 18:15:12 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-03-06 15:07:55 +01:00
|
|
|
exports.pm_recipient = {
|
|
|
|
set: function (recip) {
|
2020-07-15 00:34:28 +02:00
|
|
|
casper.evaluate(
|
|
|
|
function (recipient) {
|
|
|
|
$("#private_message_recipient")
|
|
|
|
.text(recipient)
|
|
|
|
.trigger({type: "keydown", keyCode: 13});
|
|
|
|
},
|
|
|
|
{recipient: recip}
|
|
|
|
);
|
2018-03-06 15:07:55 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
expect: function (expected_value) {
|
|
|
|
var displayed_recipients = casper.evaluate(function () {
|
2019-12-02 17:53:55 +01:00
|
|
|
return compose_state.private_message_recipient();
|
2018-03-06 15:07:55 +01:00
|
|
|
});
|
|
|
|
casper.test.assertEquals(displayed_recipients, expected_value);
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2014-03-07 23:05:26 +01:00
|
|
|
// Wait for any previous send to finish, then send a message.
|
2014-03-07 20:59:30 +01:00
|
|
|
exports.then_send_message = function (type, params) {
|
2020-03-26 12:25:10 +01:00
|
|
|
// If a message is outside the view, we will skip
|
|
|
|
// validation later.
|
|
|
|
var outside_view = params.outside_view;
|
|
|
|
delete params.outside_view;
|
|
|
|
|
2016-09-30 13:08:39 +02:00
|
|
|
casper.then(function () {
|
2020-07-15 01:29:15 +02:00
|
|
|
casper.waitForSelector("#compose-send-button:enabled");
|
|
|
|
casper.waitForSelector("#compose-textarea");
|
2016-09-30 13:08:39 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
casper.then(function () {
|
2016-06-09 22:47:12 +02:00
|
|
|
if (type === "stream") {
|
2020-07-15 01:29:15 +02:00
|
|
|
casper.page.sendEvent("keypress", "c");
|
2016-06-09 23:02:49 +02:00
|
|
|
} else if (type === "private") {
|
2020-07-15 01:29:15 +02:00
|
|
|
casper.page.sendEvent("keypress", "x");
|
2016-06-09 23:02:49 +02:00
|
|
|
} else {
|
2013-05-15 20:06:06 +02:00
|
|
|
casper.test.assertTrue(false, "send_message got valid message type");
|
|
|
|
}
|
2018-03-06 15:07:55 +01:00
|
|
|
|
|
|
|
exports.pm_recipient.set(params.recipient);
|
|
|
|
delete params.recipient;
|
|
|
|
|
2018-11-13 17:16:02 +01:00
|
|
|
if (params.stream) {
|
|
|
|
params.stream_message_recipient_stream = params.stream;
|
|
|
|
delete params.stream;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (params.subject) {
|
|
|
|
params.stream_message_recipient_topic = params.subject;
|
|
|
|
delete params.subject;
|
|
|
|
}
|
|
|
|
|
2015-12-01 00:18:33 +01:00
|
|
|
casper.fill('form[action^="/json/messages"]', params);
|
2016-10-07 18:15:12 +02:00
|
|
|
|
|
|
|
exports.turn_off_press_enter_to_send();
|
|
|
|
|
|
|
|
casper.then(function () {
|
2020-07-15 01:29:15 +02:00
|
|
|
casper.click("#compose-send-button");
|
2016-10-07 18:15:12 +02:00
|
|
|
});
|
2014-03-07 20:58:18 +01:00
|
|
|
});
|
2016-09-30 13:08:39 +02:00
|
|
|
|
|
|
|
casper.then(function () {
|
|
|
|
casper.waitFor(function emptyComposeBox() {
|
2020-07-15 01:29:15 +02:00
|
|
|
return casper.getFormValues('form[action^="/json/messages"]').content === "";
|
2016-09-30 13:08:39 +02:00
|
|
|
});
|
2020-03-26 12:25:10 +01:00
|
|
|
if (!outside_view) {
|
|
|
|
exports.wait_for_message_fully_processed(params.content);
|
|
|
|
}
|
2018-03-06 15:07:55 +01:00
|
|
|
casper.evaluate(function () {
|
|
|
|
compose_actions.cancel();
|
|
|
|
});
|
2016-09-30 13:08:39 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
casper.then(function () {
|
2014-03-07 20:58:18 +01:00
|
|
|
last_send_or_update = timestamp();
|
2013-03-05 20:52:54 +01:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2013-03-20 23:59:44 +01:00
|
|
|
// Get message headings (recipient rows) and bodies out of the DOM.
|
|
|
|
// casper.evaluate plays weird tricks with a closure, evaluating
|
|
|
|
// it in the web page's context. Passing arguments from the test
|
|
|
|
// script's context is awkward (c.f. the various appearances of
|
|
|
|
// 'table' here).
|
|
|
|
exports.get_rendered_messages = function (table) {
|
2020-07-15 00:34:28 +02:00
|
|
|
return casper.evaluate(
|
|
|
|
function (table) {
|
|
|
|
var tbl = $("#" + table);
|
|
|
|
return {
|
|
|
|
headings: $.map(tbl.find(".recipient_row .message-header-contents"), function (
|
|
|
|
elem
|
|
|
|
) {
|
|
|
|
var $clone = $(elem).clone(true);
|
|
|
|
$clone.find(".recipient_row_date").remove();
|
|
|
|
|
|
|
|
return $clone.text().trim().replace(/\s+/g, " ");
|
|
|
|
}),
|
|
|
|
|
|
|
|
bodies: $.map(tbl.find(".message_content"), function (elem) {
|
|
|
|
return elem.innerHTML;
|
|
|
|
}),
|
|
|
|
};
|
|
|
|
},
|
|
|
|
{
|
|
|
|
table: table,
|
|
|
|
}
|
|
|
|
);
|
2013-03-20 23:59:44 +01:00
|
|
|
};
|
|
|
|
|
2014-02-19 16:07:28 +01:00
|
|
|
exports.get_form_field_value = function (selector) {
|
|
|
|
return casper.evaluate(function (selector) {
|
|
|
|
return $(selector).val();
|
|
|
|
}, selector);
|
|
|
|
};
|
|
|
|
|
2020-01-27 16:42:48 +01:00
|
|
|
exports.get_user_id = function (email) {
|
2020-07-15 00:34:28 +02:00
|
|
|
return casper.evaluate(
|
|
|
|
function (email) {
|
|
|
|
return people.get_user_id(email);
|
|
|
|
},
|
|
|
|
{
|
|
|
|
email: email,
|
|
|
|
}
|
|
|
|
);
|
2020-01-27 16:42:48 +01:00
|
|
|
};
|
|
|
|
|
2020-01-28 21:43:44 +01:00
|
|
|
exports.get_stream_id = function (stream_name) {
|
2020-07-15 00:34:28 +02:00
|
|
|
return casper.evaluate(
|
|
|
|
function (stream_name) {
|
|
|
|
return stream_data.get_stream_id(stream_name);
|
|
|
|
},
|
|
|
|
{
|
|
|
|
stream_name: stream_name,
|
|
|
|
}
|
|
|
|
);
|
2020-01-28 21:43:44 +01:00
|
|
|
};
|
|
|
|
|
2013-03-20 23:59:44 +01:00
|
|
|
// Inject key presses by running some jQuery code in page context.
|
2013-03-21 00:07:30 +01:00
|
|
|
// PhantomJS and CasperJS don't provide a clean way to insert key
|
|
|
|
// presses by code, only strings of printable characters.
|
2013-03-20 23:59:44 +01:00
|
|
|
exports.keypress = function (code) {
|
2020-07-15 00:34:28 +02:00
|
|
|
casper.evaluate(
|
|
|
|
function (code) {
|
|
|
|
$("body").trigger($.Event("keydown", {which: code}));
|
|
|
|
},
|
|
|
|
{
|
|
|
|
code: code,
|
|
|
|
}
|
|
|
|
);
|
2013-03-20 23:59:44 +01:00
|
|
|
};
|
|
|
|
|
2014-03-07 20:59:30 +01:00
|
|
|
exports.then_send_many = function (msgs) {
|
2013-03-21 17:46:52 +01:00
|
|
|
msgs.forEach(function (msg) {
|
2020-07-15 00:34:28 +02:00
|
|
|
exports.then_send_message(msg.stream !== undefined ? "stream" : "private", msg);
|
2013-03-21 17:46:52 +01:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2013-03-20 23:59:44 +01:00
|
|
|
// Wait to receive queued messages.
|
|
|
|
exports.wait_for_receive = function (step) {
|
2013-05-21 19:38:41 +02:00
|
|
|
// Wait until the last send or get_events result was more than 1000 ms ago.
|
2013-03-20 23:59:44 +01:00
|
|
|
casper.waitFor(function () {
|
2018-06-06 18:50:09 +02:00
|
|
|
return timestamp() - last_send_or_update > 1000;
|
2013-03-20 23:59:44 +01:00
|
|
|
}, step);
|
|
|
|
};
|
|
|
|
|
2013-08-22 01:44:51 +02:00
|
|
|
// Wait until the loading spinner goes away (helpful just after logging in).
|
|
|
|
exports.wait_for_load = function (step) {
|
2020-07-15 01:29:15 +02:00
|
|
|
casper.waitWhileVisible("#page_loading_indicator", step);
|
2013-08-22 01:44:51 +02:00
|
|
|
};
|
|
|
|
|
2013-03-20 23:59:44 +01:00
|
|
|
// innerText sometimes gives us non-breaking space characters, and occasionally
|
|
|
|
// a different number of spaces than we expect.
|
|
|
|
exports.normalize_spaces = function (str) {
|
2020-07-15 01:29:15 +02:00
|
|
|
return str.replace(/\s+/g, " ");
|
2013-03-20 23:59:44 +01:00
|
|
|
};
|
|
|
|
|
2013-08-23 01:04:34 +02:00
|
|
|
exports.ltrim = function (str) {
|
2020-07-15 01:29:15 +02:00
|
|
|
return str.replace(/^\s+/g, "");
|
2013-08-23 01:04:34 +02:00
|
|
|
};
|
|
|
|
|
2014-01-07 17:23:14 +01:00
|
|
|
exports.rtrim = function (str) {
|
2020-07-15 01:29:15 +02:00
|
|
|
return str.replace(/\s+$/g, "");
|
2014-01-07 17:23:14 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
exports.trim = function (str) {
|
|
|
|
return exports.rtrim(exports.ltrim(str));
|
|
|
|
};
|
|
|
|
|
2013-03-20 23:59:44 +01:00
|
|
|
// Call get_rendered_messages and then check that the last few headings and
|
|
|
|
// bodies match the specified arrays.
|
|
|
|
exports.expected_messages = function (table, headings, bodies) {
|
2020-07-15 01:29:15 +02:00
|
|
|
casper.test.assertVisible("#" + table, table + " is visible");
|
2013-03-20 23:59:44 +01:00
|
|
|
|
|
|
|
var msg = exports.get_rendered_messages(table);
|
|
|
|
|
|
|
|
casper.test.assertEquals(
|
2020-03-25 17:16:36 +01:00
|
|
|
msg.headings.slice(-headings.length),
|
2014-01-07 17:23:14 +01:00
|
|
|
headings.map(exports.trim),
|
2020-07-15 00:34:28 +02:00
|
|
|
"Got expected message headings"
|
|
|
|
);
|
2013-03-20 23:59:44 +01:00
|
|
|
|
|
|
|
casper.test.assertEquals(
|
|
|
|
msg.bodies.slice(-bodies.length),
|
|
|
|
bodies,
|
2020-07-15 00:34:28 +02:00
|
|
|
"Got expected message bodies"
|
|
|
|
);
|
2013-03-20 23:59:44 +01:00
|
|
|
};
|
2013-03-05 20:52:54 +01:00
|
|
|
|
2013-03-29 00:03:11 +01:00
|
|
|
exports.un_narrow = function () {
|
2020-07-15 01:29:15 +02:00
|
|
|
casper.test.info("Un-narrowing");
|
|
|
|
if (casper.visible(".message_comp")) {
|
2017-04-16 14:58:42 +02:00
|
|
|
// close the compose box
|
|
|
|
common.keypress(27); // Esc
|
|
|
|
}
|
2013-03-29 00:03:11 +01:00
|
|
|
common.keypress(27); // Esc
|
|
|
|
};
|
2020-04-10 12:44:12 +02:00
|
|
|
|
|
|
|
exports.manage_organization = function () {
|
|
|
|
casper.then(function () {
|
2020-07-15 01:29:15 +02:00
|
|
|
var menu_selector = "#settings-dropdown";
|
2020-04-10 12:44:12 +02:00
|
|
|
casper.waitUntilVisible(menu_selector, function () {
|
|
|
|
casper.click(menu_selector);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
casper.then(function () {
|
2020-07-15 01:29:15 +02:00
|
|
|
casper.test.info("Organization page");
|
2020-04-10 12:44:12 +02:00
|
|
|
casper.click('a[href^="#organization"]');
|
|
|
|
});
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
casper.waitForSelector("#settings_overlay_container.show", function () {
|
|
|
|
casper.test.info("Organization page is active");
|
2020-07-15 00:34:28 +02:00
|
|
|
casper.test.assertUrlMatch(
|
|
|
|
/^http:\/\/[^/]+\/#organization/,
|
|
|
|
"URL suggests we are on organization page"
|
|
|
|
);
|
2020-04-10 12:44:12 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
casper.then(function () {
|
|
|
|
casper.click("li[data-section='organization-settings']");
|
|
|
|
});
|
|
|
|
};
|