Add node JS unit tests for MessageList.

(imported from commit 486a343add91fd5037431504e1ce4a750bfa9fbf)
This commit is contained in:
Steve Howell 2013-08-06 15:30:31 -04:00
parent de252b0ee9
commit 57f518c9c2
3 changed files with 103 additions and 0 deletions

View File

@ -720,3 +720,6 @@ $(document).on('message_selected.zulip hashchange.zulip mousewheel', function (e
}); });
}()); }());
/*jslint nomen: false */ /*jslint nomen: false */
if (typeof module !== 'undefined') {
module.exports = MessageList;
}

View File

@ -8,6 +8,7 @@ export NODE_PATH=$STATIC_DIR
NODEJS=$(which nodejs || which node) NODEJS=$(which nodejs || which node)
$NODEJS message_list.js
$NODEJS message_tour.js $NODEJS message_tour.js
$NODEJS unread.js $NODEJS unread.js
$NODEJS search_suggestion.js $NODEJS search_suggestion.js

View File

@ -0,0 +1,99 @@
// These unit tests for static/js/message_list.js emphasize the model-ish
// aspects of the MessageList class. We have to stub out a few functions
// related to views and events to get the tests working.
var assert = require('assert');
(function set_up_dependencies () {
global.document = null;
global.$ = function () {
return {
on: function () {},
trigger: function () {}
};
};
global._ = require('third/underscore/underscore.js');
global.util = require('js/util.js');
}());
var MessageList = require('js/message_list');
(function test_basics() {
var table;
var filter = {};
var list = new MessageList(table, filter);
var messages = [
{
id: 50,
content: 'fifty'
},
{
id: 60
},
{
id: 70
},
{
id: 80
}
];
assert.equal(list.empty(), true);
list.append(messages, true);
assert.equal(list.empty(), false);
assert.equal(list.first().id, 50);
assert.equal(list.last().id, 80);
assert.equal(list.get(50).content, 'fifty');
assert.equal(list.closest_id(49), 50);
assert.equal(list.closest_id(50), 50);
assert.equal(list.closest_id(51), 50);
assert.equal(list.closest_id(59), 60);
assert.equal(list.closest_id(60), 60);
assert.equal(list.closest_id(61), 60);
assert.deepEqual(list.all(), messages);
global.$.Event = function (ev) {
assert.equal(ev, 'message_selected.zulip');
};
list.select_id(50);
assert.equal(list.selected_id(), 50);
list.advance_past_messages([60, 80]);
assert.equal(list.selected_id(), 60);
var old_messages = [
{
id: 30
},
{
id: 40
}
];
list.prepend(old_messages, true);
assert.equal(list.first().id, 30);
assert.equal(list.last().id, 80);
var new_messages = [
{
id: 90
}
];
list.append(new_messages, true);
assert.equal(list.last().id, 90);
list._clear_table = function () {};
list.clear();
assert.deepEqual(list.all(), []);
}());