blueslip: Protect against drafts pitfall for rows.id.

If folks use an overly broad selector for message rows,
they will accidentally include drafts from the drafts
dialog, which won't have zids.  More specific selectors
will be more efficient and possibly prevent strange
behaviors.

For testing convenience, we extract the message.
This commit is contained in:
Steve Howell
2020-04-02 13:13:23 +00:00
committed by Tim Abbott
parent 5eb5b6a5ad
commit 02947d6b41
2 changed files with 12 additions and 0 deletions

View File

@@ -14,6 +14,8 @@ set_global('popovers', {
hide_all: () => {},
});
rows.is_draft_row = () => false;
set_global('$', global.make_zjquery());
run_test('pan_and_zoom', () => {

View File

@@ -41,7 +41,16 @@ exports.last_visible = function () {
return $('.focused_table .selectable_row').last();
};
exports.is_draft_row = function (row) {
return row.find('.restore-draft').length >= 1;
};
exports.id = function (message_row) {
if (exports.is_draft_row(message_row)) {
blueslip.error('Drafts have no zid');
return;
}
/*
For blueslip errors, don't return early, since
we may have some code now that actually relies
@@ -49,6 +58,7 @@ exports.id = function (message_row) {
that up in the future, but we mainly just want
more data now.
*/
if (message_row.length !== 1) {
blueslip.error("Caller should pass in a single row.");
}