mirror of
https://github.com/zulip/zulip.git
synced 2025-11-04 14:03:30 +00:00
node tests: Add tests for message_store.js.
This commit is contained in:
66
frontend_tests/node_tests/message_store.js
Normal file
66
frontend_tests/node_tests/message_store.js
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
global.stub_out_jquery();
|
||||||
|
|
||||||
|
add_dependencies({
|
||||||
|
people: 'js/people.js',
|
||||||
|
util: 'js/util.js'
|
||||||
|
});
|
||||||
|
|
||||||
|
var noop = function () {};
|
||||||
|
var people = global.people;
|
||||||
|
|
||||||
|
set_global('page_params', {
|
||||||
|
email: 'me@example.com'
|
||||||
|
});
|
||||||
|
|
||||||
|
set_global('alert_words', {
|
||||||
|
process_message: noop
|
||||||
|
});
|
||||||
|
|
||||||
|
var me = {
|
||||||
|
email: 'me@example.com',
|
||||||
|
user_id: 101,
|
||||||
|
full_name: 'Me Myself'
|
||||||
|
};
|
||||||
|
|
||||||
|
var alice = {
|
||||||
|
email: 'alice@example.com',
|
||||||
|
user_id: 102,
|
||||||
|
full_name: 'Alice'
|
||||||
|
};
|
||||||
|
|
||||||
|
var bob = {
|
||||||
|
email: 'bob@example.com',
|
||||||
|
user_id: 103,
|
||||||
|
full_name: 'Bob'
|
||||||
|
};
|
||||||
|
|
||||||
|
var cindy = {
|
||||||
|
email: 'cindy@example.com',
|
||||||
|
user_id: 104,
|
||||||
|
full_name: 'Cindy'
|
||||||
|
};
|
||||||
|
|
||||||
|
people.add_in_realm(me);
|
||||||
|
people.add_in_realm(alice);
|
||||||
|
people.add_in_realm(bob);
|
||||||
|
people.add_in_realm(cindy);
|
||||||
|
|
||||||
|
global.util.execute_early = noop;
|
||||||
|
|
||||||
|
var message_store = require('js/message_store.js');
|
||||||
|
|
||||||
|
(function test_add_message_metadata() {
|
||||||
|
var message = {
|
||||||
|
sender_email: 'me@example.com',
|
||||||
|
type: 'private',
|
||||||
|
display_recipient: [me, bob, cindy],
|
||||||
|
flags: ['has_alert_word']
|
||||||
|
};
|
||||||
|
message_store._add_message_metadata(message);
|
||||||
|
|
||||||
|
assert.equal(message.is_private, true);
|
||||||
|
assert.equal(message.reply_to, 'bob@example.com,cindy@example.com');
|
||||||
|
assert.equal(message.display_reply_to, 'Bob, Cindy');
|
||||||
|
assert.equal(message.alerted, true);
|
||||||
|
assert.equal(message.is_me_message, false);
|
||||||
|
}());
|
||||||
@@ -49,6 +49,7 @@ exports.stub_out_jquery = function () {
|
|||||||
});
|
});
|
||||||
$.fn = {};
|
$.fn = {};
|
||||||
$.now = function () {};
|
$.now = function () {};
|
||||||
|
$.trim = function (s) { return s.trim(); };
|
||||||
};
|
};
|
||||||
|
|
||||||
return exports;
|
return exports;
|
||||||
|
|||||||
@@ -641,6 +641,9 @@ util.execute_early(function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// This is for testing.
|
||||||
|
exports._add_message_metadata = add_message_metadata;
|
||||||
|
|
||||||
return exports;
|
return exports;
|
||||||
|
|
||||||
}());
|
}());
|
||||||
|
|||||||
Reference in New Issue
Block a user