casper: Improve logic to confirm message sends.

We now use `wait_for_message_fully_processed`
to check that messages are fully rendered.

Before this, we had loopholes where messages
sent outside the view were effectively ignored.
Now we explicitly ignore the check for the
one place we do that.

The more important behavior is for messages
that get sent to the current view.

Before this change, the older version of this
function declared victory as soon as we put the
server version of a locally echoed message into
the current message list's data.

This fixes flaky behavior with 07-stars in
particular, since we need the star icon
on our last message to be there before
we click on it.

Because this function is more robust now, we
can remove some redundant checks in 08-edit.js.
This commit is contained in:
Steve Howell
2020-03-26 11:25:10 +00:00
committed by showell
parent 41f0069a08
commit d604814347
3 changed files with 65 additions and 25 deletions

View File

@@ -181,11 +181,58 @@ exports.check_form = function (form_selector, expected, test_name) {
}
};
exports.wait_for_message_actually_sent = function () {
exports.wait_for_message_fully_processed = function (content) {
casper.waitFor(function () {
return casper.evaluate(function () {
return !current_msg_list.last().locally_echoed;
});
return casper.evaluate(function (content) {
/*
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?
*/
const last_msg = current_msg_list.last();
if (last_msg.raw_content !== content) {
return false;
}
if (last_msg.locally_echoed) {
return false;
}
var row = rows.last_visible();
if (rows.id(row) !== last_msg.id) {
return false;
}
/*
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.
*/
return row.find('.star').length === 1;
}, { content: content});
});
};
@@ -220,6 +267,11 @@ exports.pm_recipient = {
// Wait for any previous send to finish, then send a message.
exports.then_send_message = function (type, params) {
// If a message is outside the view, we will skip
// validation later.
var outside_view = params.outside_view;
delete params.outside_view;
casper.then(function () {
casper.waitForSelector('#compose-send-button:enabled');
casper.waitForSelector('#compose-textarea');
@@ -260,7 +312,9 @@ exports.then_send_message = function (type, params) {
casper.waitFor(function emptyComposeBox() {
return casper.getFormValues('form[action^="/json/messages"]').content === '';
});
exports.wait_for_message_actually_sent();
if (!outside_view) {
exports.wait_for_message_fully_processed(params.content);
}
casper.evaluate(function () {
compose_actions.cancel();
});
@@ -329,7 +383,6 @@ exports.keypress = function (code) {
});
};
// Send a whole list of messages using then_send_message.
exports.then_send_many = function (msgs) {
msgs.forEach(function (msg) {
exports.then_send_message(

View File

@@ -167,9 +167,12 @@ casper.then(function () {
common.keypress(27); // escape to dismiss compose box
});
casper.waitWhileVisible('.message_comp');
common.then_send_many([
{ recipient: recipients.join(','),
content: 'A huddle to check spaces' }]);
common.then_send_message('private', {
recipient: recipients.join(','),
outside_view: true,
content: 'A huddle to check spaces',
});
casper.then(function () {
common.keypress(27); // escape to dismiss compose box

View File

@@ -26,12 +26,6 @@ common.then_send_message('stream', {
content: 'test editing',
});
casper.then(function () {
casper.waitForSelectorText("#zhome .message_row", "test editing");
});
common.wait_for_message_actually_sent();
then_edit_last_message();
casper.then(function () {
@@ -53,12 +47,6 @@ common.then_send_message('stream', {
content: '/me test editing one line with me',
});
casper.then(function () {
casper.waitForSelectorText("#zhome .message_row", "test editing one line with me");
});
common.wait_for_message_actually_sent();
then_edit_last_message();
casper.then(function () {
@@ -79,10 +67,6 @@ common.then_send_message('private', {
content: "test editing pm",
});
casper.then(function () {
casper.waitForSelectorText("#zhome .message_row", "test editing pm");
});
common.wait_for_message_actually_sent();
then_edit_last_message();
casper.then(function () {