Add tests for reactions.message_reaction_on_click().

This commit is contained in:
Steve Howell
2017-05-28 07:18:12 -07:00
committed by Tim Abbott
parent f48df30c20
commit 8d7cd2e3af

View File

@@ -1,4 +1,5 @@
set_global('document', {});
set_global('document', 'document-stub');
set_global('$', global.make_zjquery());
add_dependencies({
people: 'js/people.js',
@@ -12,6 +13,10 @@ set_global('emoji', {
octopus: 'octopus-css',
smile: 'smile-css',
},
emojis_by_name: {
alien: '1f47d',
smile: '1f604',
},
realm_emojis: {},
});
@@ -21,6 +26,8 @@ set_global('blueslip', {
set_global('page_params', {user_id: 5});
set_global('channel', {});
(function make_people() {
var alice = {
email: 'alice@example.com',
@@ -42,26 +49,27 @@ set_global('page_params', {user_id: 5});
people.add_in_realm(cali);
}());
var message = {
id: 1001,
reactions: [
{emoji_name: 'smile', user: {id: 5}},
{emoji_name: 'smile', user: {id: 6}},
{emoji_name: 'frown', user: {id: 7}},
// add some bogus user_ids
{emoji_name: 'octopus', user: {id: 8888}},
{emoji_name: 'frown', user: {id: 9999}},
],
};
set_global('message_store', {
get: function (message_id) {
assert.equal(message_id, 1001);
return message;
},
});
(function test_basics() {
var message = {
id: 1001,
reactions: [
{emoji_name: 'smile', user: {id: 5}},
{emoji_name: 'smile', user: {id: 6}},
{emoji_name: 'frown', user: {id: 7}},
// add some bogus user_ids
{emoji_name: 'octopus', user: {id: 8888}},
{emoji_name: 'frown', user: {id: 9999}},
],
};
set_global('message_store', {
get: function (message_id) {
assert.equal(message_id, 1001);
return message;
},
});
var result = reactions.get_message_reactions(message);
assert(reactions.current_user_has_reacted_to_emoji(message, 'smile'));
@@ -89,3 +97,33 @@ set_global('page_params', {user_id: 5});
];
assert.deepEqual(result, expected_result);
}());
(function test_sending() {
var message_id = 1001; // see above for setup
var emoji_name = 'smile'; // should be a current reaction
global.with_stub(function (stub) {
global.channel.del = stub.f;
reactions.message_reaction_on_click(message_id, emoji_name);
var args = stub.get_args('args').args;
assert.equal(args.url, '/json/messages/1001/emoji_reactions/smile');
// args.success() does nothing; just make sure it doesn't crash
args.success();
// similarly, we only exercise the failure codepath
global.channel.xhr_error_message = function () {};
args.error();
});
emoji_name = 'alien'; // not set yet
global.with_stub(function (stub) {
global.channel.put = stub.f;
reactions.message_reaction_on_click(message_id, emoji_name);
var args = stub.get_args('args').args;
assert.equal(args.url, '/json/messages/1001/emoji_reactions/alien');
});
emoji_name = 'unknown-emoji';
reactions.message_reaction_on_click(message_id, emoji_name);
}());