2017-05-28 16:18:12 +02:00
|
|
|
set_global('document', 'document-stub');
|
|
|
|
set_global('$', global.make_zjquery());
|
2017-03-26 20:20:42 +02:00
|
|
|
|
|
|
|
add_dependencies({
|
|
|
|
people: 'js/people.js',
|
|
|
|
});
|
|
|
|
|
|
|
|
set_global('emoji', {
|
2017-05-17 16:06:20 +02:00
|
|
|
emojis_name_to_css_class: {
|
|
|
|
frown: 'frown-css',
|
|
|
|
octopus: 'octopus-css',
|
|
|
|
smile: 'smile-css',
|
2017-03-26 20:20:42 +02:00
|
|
|
},
|
2017-05-28 16:18:12 +02:00
|
|
|
emojis_by_name: {
|
|
|
|
alien: '1f47d',
|
|
|
|
smile: '1f604',
|
|
|
|
},
|
2017-06-23 23:41:41 +02:00
|
|
|
all_realm_emojis: {
|
|
|
|
realm_emoji: {
|
|
|
|
emoji_name: 'realm_emoji',
|
|
|
|
emoji_url: 'TBD',
|
|
|
|
deactivated: false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
active_realm_emojis: {
|
|
|
|
realm_emoji: {
|
|
|
|
emoji_name: 'realm_emoji',
|
|
|
|
emoji_url: 'TBD',
|
|
|
|
},
|
2017-05-30 04:07:28 +02:00
|
|
|
},
|
2017-03-26 20:20:42 +02:00
|
|
|
});
|
|
|
|
|
2017-03-26 20:38:47 +02:00
|
|
|
set_global('blueslip', {
|
|
|
|
warn: function () {},
|
|
|
|
});
|
|
|
|
|
2017-05-11 17:00:24 +02:00
|
|
|
set_global('page_params', {user_id: 5});
|
2017-03-26 20:20:42 +02:00
|
|
|
|
2017-05-28 16:18:12 +02:00
|
|
|
set_global('channel', {});
|
2017-05-28 17:04:30 +02:00
|
|
|
set_global('templates', {});
|
2017-05-29 21:36:24 +02:00
|
|
|
set_global('emoji_picker', {
|
|
|
|
hide_emoji_popover: function () {},
|
|
|
|
});
|
2017-05-28 16:18:12 +02:00
|
|
|
|
2017-05-28 17:04:30 +02:00
|
|
|
var reactions = require("js/reactions.js");
|
|
|
|
|
|
|
|
var alice = {
|
|
|
|
email: 'alice@example.com',
|
|
|
|
user_id: 5,
|
|
|
|
full_name: 'Alice',
|
|
|
|
};
|
|
|
|
var bob = {
|
|
|
|
email: 'bob@example.com',
|
|
|
|
user_id: 6,
|
|
|
|
full_name: 'Bob van Roberts',
|
|
|
|
};
|
|
|
|
var cali = {
|
|
|
|
email: 'cali@example.com',
|
|
|
|
user_id: 7,
|
|
|
|
full_name: 'Cali',
|
|
|
|
};
|
|
|
|
people.add_in_realm(alice);
|
|
|
|
people.add_in_realm(bob);
|
|
|
|
people.add_in_realm(cali);
|
2017-03-26 20:20:42 +02:00
|
|
|
|
2017-05-28 16:18:12 +02:00
|
|
|
var message = {
|
|
|
|
id: 1001,
|
|
|
|
reactions: [
|
2017-05-01 07:29:56 +02:00
|
|
|
{emoji_name: 'smile', user: {id: 5}, reaction_type: 'unicode_emoji', emoji_code: '1'},
|
|
|
|
{emoji_name: 'smile', user: {id: 6}, reaction_type: 'unicode_emoji', emoji_code: '1'},
|
|
|
|
{emoji_name: 'frown', user: {id: 7}, reaction_type: 'unicode_emoji', emoji_code: '2'},
|
2017-03-26 20:20:42 +02:00
|
|
|
|
2017-05-28 16:18:12 +02:00
|
|
|
// add some bogus user_ids
|
2017-05-01 07:29:56 +02:00
|
|
|
{emoji_name: 'octopus', user: {id: 8888}, reaction_type: 'unicode_emoji', emoji_code: '3'},
|
|
|
|
{emoji_name: 'frown', user: {id: 9999}, reaction_type: 'unicode_emoji', emoji_code: '2'},
|
2017-05-28 16:18:12 +02:00
|
|
|
],
|
|
|
|
};
|
|
|
|
|
|
|
|
set_global('message_store', {
|
|
|
|
get: function (message_id) {
|
|
|
|
assert.equal(message_id, 1001);
|
|
|
|
return message;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2017-09-18 22:06:39 +02:00
|
|
|
set_global('current_msg_list', {
|
|
|
|
selected_message: function () {
|
|
|
|
return { sent_by_me: true };
|
|
|
|
},
|
|
|
|
selected_row: function () {
|
|
|
|
return $('.selected-row');
|
|
|
|
},
|
|
|
|
selected_id: function () {
|
|
|
|
return 42;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
(function test_open_reactions_popover() {
|
|
|
|
$('.selected-row').set_find_results('.actions_hover', $('.target-action'));
|
|
|
|
$('.selected-row').set_find_results('.reaction_button', $('.target-reaction'));
|
|
|
|
|
|
|
|
var called = false;
|
|
|
|
emoji_picker.toggle_emoji_popover = function (target, id) {
|
|
|
|
called = true;
|
|
|
|
assert.equal(id, 42);
|
|
|
|
assert.equal(target, $('.target-reaction')[0]);
|
|
|
|
};
|
|
|
|
|
|
|
|
assert(reactions.open_reactions_popover());
|
|
|
|
assert(called);
|
|
|
|
|
|
|
|
current_msg_list.selected_message = function () { return { sent_by_me: false }; };
|
|
|
|
|
|
|
|
called = false;
|
|
|
|
emoji_picker.toggle_emoji_popover = function (target, id) {
|
|
|
|
called = true;
|
|
|
|
assert.equal(id, 42);
|
|
|
|
assert.equal(target, $('.target-action')[0]);
|
|
|
|
};
|
|
|
|
|
|
|
|
assert(reactions.open_reactions_popover());
|
|
|
|
assert(called);
|
|
|
|
}());
|
|
|
|
|
2017-05-28 16:18:12 +02:00
|
|
|
(function test_basics() {
|
2017-03-26 20:20:42 +02:00
|
|
|
var result = reactions.get_message_reactions(message);
|
|
|
|
|
2017-05-11 17:00:24 +02:00
|
|
|
assert(reactions.current_user_has_reacted_to_emoji(message, 'smile'));
|
|
|
|
assert(!reactions.current_user_has_reacted_to_emoji(message, 'frown'));
|
|
|
|
|
|
|
|
result.sort(function (a, b) { return a.count - b.count; });
|
2017-03-26 20:20:42 +02:00
|
|
|
|
|
|
|
var expected_result = [
|
|
|
|
{
|
|
|
|
emoji_name: 'frown',
|
2017-05-01 07:29:56 +02:00
|
|
|
reaction_type: 'unicode_emoji',
|
|
|
|
emoji_code: '2',
|
|
|
|
emoji_name_css_class: '2',
|
2017-03-26 20:20:42 +02:00
|
|
|
count: 1,
|
2017-05-01 07:29:56 +02:00
|
|
|
user_ids: [ 7 ],
|
2017-03-26 20:20:42 +02:00
|
|
|
title: 'Cali reacted with :frown:',
|
|
|
|
emoji_alt_code: undefined,
|
|
|
|
class: 'message_reaction',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
emoji_name: 'smile',
|
2017-05-01 07:29:56 +02:00
|
|
|
reaction_type: 'unicode_emoji',
|
|
|
|
emoji_code: '1',
|
|
|
|
emoji_name_css_class: '1',
|
2017-03-26 20:20:42 +02:00
|
|
|
count: 2,
|
2017-05-01 07:29:56 +02:00
|
|
|
user_ids: [ 5, 6 ],
|
2017-05-11 17:00:24 +02:00
|
|
|
title: 'You (click to remove) and Bob van Roberts reacted with :smile:',
|
2017-03-26 20:20:42 +02:00
|
|
|
emoji_alt_code: undefined,
|
2017-05-11 17:00:24 +02:00
|
|
|
class: 'message_reaction reacted',
|
2017-03-26 20:20:42 +02:00
|
|
|
},
|
|
|
|
];
|
|
|
|
assert.deepEqual(result, expected_result);
|
|
|
|
}());
|
2017-05-28 16:18:12 +02:00
|
|
|
|
|
|
|
(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;
|
2017-05-29 21:18:59 +02:00
|
|
|
reactions.toggle_emoji_reaction(message_id, emoji_name);
|
2017-05-28 16:18:12 +02:00
|
|
|
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;
|
2017-05-29 21:18:59 +02:00
|
|
|
reactions.toggle_emoji_reaction(message_id, emoji_name);
|
2017-05-28 16:18:12 +02:00
|
|
|
var args = stub.get_args('args').args;
|
|
|
|
assert.equal(args.url, '/json/messages/1001/emoji_reactions/alien');
|
|
|
|
});
|
|
|
|
|
|
|
|
emoji_name = 'unknown-emoji';
|
2017-05-29 21:18:59 +02:00
|
|
|
reactions.toggle_emoji_reaction(message_id, emoji_name);
|
2017-05-28 16:18:12 +02:00
|
|
|
}());
|
2017-05-28 17:04:30 +02:00
|
|
|
|
2017-05-29 19:24:31 +02:00
|
|
|
(function test_set_reaction_count() {
|
2017-07-08 15:16:19 +02:00
|
|
|
var count_element = $.create('count-stub');
|
|
|
|
var reaction_element = $.create('reaction-stub');
|
2017-05-29 19:24:31 +02:00
|
|
|
|
2017-07-08 14:31:18 +02:00
|
|
|
reaction_element.set_find_results('.message_reaction_count', count_element);
|
2017-05-29 19:24:31 +02:00
|
|
|
|
|
|
|
reactions.set_reaction_count(reaction_element, 5);
|
|
|
|
|
|
|
|
assert.equal(count_element.html(), '5');
|
|
|
|
}());
|
|
|
|
|
2017-06-29 17:19:14 +02:00
|
|
|
(function test_get_reaction_section() {
|
2017-07-08 15:16:19 +02:00
|
|
|
var message_table = $.create('.message_table');
|
|
|
|
var message_row = $.create('some-message-row');
|
|
|
|
var message_reactions = $.create('our-reactions-section');
|
2017-06-29 17:19:14 +02:00
|
|
|
|
2017-07-08 14:31:18 +02:00
|
|
|
message_table.set_find_results("[zid='555']", message_row);
|
|
|
|
message_row.set_find_results('.message_reactions', message_reactions);
|
2017-06-29 17:19:14 +02:00
|
|
|
|
|
|
|
var section = reactions.get_reaction_section(555);
|
|
|
|
|
|
|
|
assert.equal(section, message_reactions);
|
|
|
|
}());
|
|
|
|
|
2017-05-29 20:13:58 +02:00
|
|
|
(function test_add_and_remove_reaction() {
|
2017-05-30 04:46:36 +02:00
|
|
|
// Insert 8ball for Alice.
|
2017-05-29 20:13:58 +02:00
|
|
|
var alice_event = {
|
2017-05-28 17:04:30 +02:00
|
|
|
message_id: 1001,
|
|
|
|
emoji_name: '8ball',
|
|
|
|
user: {
|
|
|
|
user_id: alice.user_id,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2017-07-08 15:16:19 +02:00
|
|
|
var message_reactions = $.create('our-reactions');
|
2017-05-28 17:04:30 +02:00
|
|
|
|
2017-06-29 17:19:14 +02:00
|
|
|
reactions.get_reaction_section = function (message_id) {
|
|
|
|
assert.equal(message_id, 1001);
|
|
|
|
return message_reactions;
|
|
|
|
};
|
2017-05-28 17:04:30 +02:00
|
|
|
|
|
|
|
message_reactions.find = function (selector) {
|
|
|
|
assert.equal(selector, '.reaction_button');
|
|
|
|
return 'reaction-button-stub';
|
|
|
|
};
|
|
|
|
|
|
|
|
var template_called;
|
|
|
|
global.templates.render = function (template_name, data) {
|
|
|
|
template_called = true;
|
|
|
|
assert.equal(template_name, 'message_reaction');
|
2017-05-30 04:07:28 +02:00
|
|
|
assert.equal(data.class, 'message_reaction reacted');
|
|
|
|
assert(!data.is_realm_emoji);
|
2017-05-28 17:04:30 +02:00
|
|
|
assert.equal(data.message_id, 1001);
|
|
|
|
assert.equal(data.title, 'You (click to remove) reacted with :8ball:');
|
2017-07-08 15:16:19 +02:00
|
|
|
return '<new reaction html>';
|
2017-05-28 17:04:30 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
var insert_called;
|
2017-07-08 15:16:19 +02:00
|
|
|
$('<new reaction html>').insertBefore = function (element) {
|
2017-05-28 17:04:30 +02:00
|
|
|
assert.equal(element, 'reaction-button-stub');
|
|
|
|
insert_called = true;
|
|
|
|
};
|
|
|
|
|
2017-05-29 20:13:58 +02:00
|
|
|
reactions.add_reaction(alice_event);
|
2017-05-28 17:04:30 +02:00
|
|
|
|
|
|
|
assert(template_called);
|
|
|
|
assert(insert_called);
|
|
|
|
|
2017-05-30 04:46:36 +02:00
|
|
|
// Now, have Bob react to the same emoji (update).
|
2017-05-28 17:04:30 +02:00
|
|
|
|
2017-05-29 20:13:58 +02:00
|
|
|
var bob_event = {
|
2017-05-28 17:04:30 +02:00
|
|
|
message_id: 1001,
|
|
|
|
emoji_name: '8ball',
|
|
|
|
user: {
|
|
|
|
user_id: bob.user_id,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2017-07-08 15:16:19 +02:00
|
|
|
var count_element = $.create('count-element');
|
|
|
|
var reaction_element = $.create('reaction-element');
|
2017-07-08 14:31:18 +02:00
|
|
|
reaction_element.set_find_results('.message_reaction_count', count_element);
|
2017-05-28 17:04:30 +02:00
|
|
|
|
|
|
|
var title_set;
|
|
|
|
reaction_element.prop = function (prop_name, value) {
|
|
|
|
assert.equal(prop_name, 'title');
|
|
|
|
var expected_msg = 'You (click to remove)' +
|
|
|
|
' and Bob van Roberts reacted with :8ball:';
|
|
|
|
assert.equal(value, expected_msg);
|
|
|
|
title_set = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
message_reactions.find = function (selector) {
|
|
|
|
assert.equal(selector, "[data-emoji-name='8ball']");
|
|
|
|
return reaction_element;
|
|
|
|
};
|
|
|
|
|
2017-05-29 20:13:58 +02:00
|
|
|
reactions.add_reaction(bob_event);
|
2017-05-28 17:04:30 +02:00
|
|
|
assert(title_set);
|
2017-05-29 19:24:31 +02:00
|
|
|
assert.equal(count_element.html(), '2');
|
2017-05-28 17:04:30 +02:00
|
|
|
|
2017-05-29 20:13:58 +02:00
|
|
|
// Now, remove Bob's 8ball emoji. The event has the same exact
|
|
|
|
// structure as the add event.
|
|
|
|
title_set = false;
|
|
|
|
reaction_element.prop = function (prop_name, value) {
|
|
|
|
assert.equal(prop_name, 'title');
|
|
|
|
var expected_msg = 'You (click to remove) reacted with :8ball:';
|
|
|
|
assert.equal(value, expected_msg);
|
|
|
|
title_set = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
reactions.remove_reaction(bob_event);
|
|
|
|
assert(title_set);
|
|
|
|
assert.equal(count_element.html(), '1');
|
|
|
|
|
2017-05-30 03:34:06 +02:00
|
|
|
var current_emojis = reactions.get_emojis_used_by_user_for_message_id(1001);
|
|
|
|
assert.deepEqual(current_emojis, ['smile', '8ball']);
|
|
|
|
|
2017-05-29 20:13:58 +02:00
|
|
|
// Next, remove Alice's reaction, which exercises removing the
|
|
|
|
// emoji icon.
|
|
|
|
var removed;
|
|
|
|
reaction_element.remove = function () {
|
|
|
|
removed = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
reactions.remove_reaction(alice_event);
|
|
|
|
assert(removed);
|
2017-05-30 03:34:06 +02:00
|
|
|
|
|
|
|
current_emojis = reactions.get_emojis_used_by_user_for_message_id(1001);
|
|
|
|
assert.deepEqual(current_emojis, ['smile']);
|
2017-05-30 04:07:28 +02:00
|
|
|
|
|
|
|
|
|
|
|
// Now add Cali's realm_emoji reaction.
|
|
|
|
var cali_event = {
|
|
|
|
message_id: 1001,
|
|
|
|
emoji_name: 'realm_emoji',
|
|
|
|
user: {
|
|
|
|
user_id: cali.user_id,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
template_called = false;
|
|
|
|
global.templates.render = function (template_name, data) {
|
|
|
|
assert.equal(data.class, 'message_reaction');
|
|
|
|
assert(data.is_realm_emoji);
|
|
|
|
template_called = true;
|
2017-07-08 15:16:19 +02:00
|
|
|
return '<new reaction html>';
|
2017-05-30 04:07:28 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
message_reactions.find = function (selector) {
|
|
|
|
assert.equal(selector, '.reaction_button');
|
|
|
|
return 'reaction-button-stub';
|
|
|
|
};
|
|
|
|
|
|
|
|
reactions.add_reaction(cali_event);
|
|
|
|
assert(template_called);
|
2017-05-30 04:46:36 +02:00
|
|
|
assert(!reaction_element.hasClass('reacted'));
|
2017-05-30 04:07:28 +02:00
|
|
|
|
2017-05-30 04:46:36 +02:00
|
|
|
// And then have Alice update it.
|
|
|
|
alice_event = {
|
|
|
|
message_id: 1001,
|
|
|
|
emoji_name: 'realm_emoji',
|
|
|
|
user: {
|
|
|
|
user_id: alice.user_id,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
message_reactions.find = function (selector) {
|
|
|
|
assert.equal(selector, "[data-emoji-name='realm_emoji']");
|
|
|
|
return reaction_element;
|
|
|
|
};
|
|
|
|
reaction_element.prop = function () {};
|
|
|
|
reactions.add_reaction(alice_event);
|
|
|
|
|
|
|
|
assert(reaction_element.hasClass('reacted'));
|
2017-05-30 23:24:21 +02:00
|
|
|
var result = reactions.get_message_reactions(message);
|
|
|
|
var realm_emoji_data = _.filter(result, function (v) {
|
|
|
|
return v.emoji_name === 'realm_emoji';
|
|
|
|
})[0];
|
|
|
|
|
|
|
|
assert.equal(realm_emoji_data.count, 2);
|
|
|
|
assert.equal(realm_emoji_data.is_realm_emoji, true);
|
|
|
|
|
|
|
|
// And then remove Alice's reaction.
|
|
|
|
reactions.remove_reaction(alice_event);
|
|
|
|
assert(!reaction_element.hasClass('reacted'));
|
|
|
|
|
2017-05-28 17:04:30 +02:00
|
|
|
}());
|
2017-05-31 00:09:50 +02:00
|
|
|
|
2017-06-28 22:47:47 +02:00
|
|
|
(function test_with_view_stubs() {
|
|
|
|
// This function tests reaction events by mocking out calls to
|
|
|
|
// the view.
|
|
|
|
|
|
|
|
var message = {
|
|
|
|
id: 2001,
|
|
|
|
reactions: [],
|
|
|
|
};
|
|
|
|
|
|
|
|
message_store.get = function () {
|
|
|
|
return message;
|
|
|
|
};
|
|
|
|
|
|
|
|
function test_view_calls(test_params) {
|
|
|
|
var calls = [];
|
|
|
|
|
|
|
|
function add_call_func(name) {
|
|
|
|
return function (opts) {
|
|
|
|
calls.push({
|
|
|
|
name: name,
|
|
|
|
opts: opts,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
reactions.view = {
|
|
|
|
insert_new_reaction: add_call_func('insert_new_reaction'),
|
|
|
|
update_existing_reaction: add_call_func('update_existing_reaction'),
|
|
|
|
remove_reaction: add_call_func('remove_reaction'),
|
|
|
|
};
|
|
|
|
|
|
|
|
test_params.run_code();
|
|
|
|
|
|
|
|
assert.deepEqual(calls, test_params.expected_view_calls);
|
|
|
|
}
|
|
|
|
|
|
|
|
var alice_8ball_event = {
|
|
|
|
message_id: 2001,
|
|
|
|
emoji_name: '8ball',
|
|
|
|
user: {
|
|
|
|
user_id: alice.user_id,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
var bob_8ball_event = {
|
|
|
|
message_id: 2001,
|
|
|
|
emoji_name: '8ball',
|
|
|
|
user: {
|
|
|
|
user_id: bob.user_id,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
var cali_airplane_event = {
|
|
|
|
message_id: 2001,
|
|
|
|
emoji_name: 'airplane',
|
|
|
|
user: {
|
|
|
|
user_id: cali.user_id,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
test_view_calls({
|
|
|
|
run_code: function () {
|
|
|
|
reactions.add_reaction(alice_8ball_event);
|
|
|
|
},
|
|
|
|
expected_view_calls: [
|
|
|
|
{
|
|
|
|
name: 'insert_new_reaction',
|
|
|
|
opts: {
|
|
|
|
message_id: 2001,
|
|
|
|
emoji_name: '8ball',
|
|
|
|
user_id: alice.user_id,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
|
|
|
|
|
|
|
test_view_calls({
|
|
|
|
run_code: function () {
|
|
|
|
reactions.add_reaction(bob_8ball_event);
|
|
|
|
},
|
|
|
|
expected_view_calls: [
|
|
|
|
{
|
|
|
|
name: 'update_existing_reaction',
|
|
|
|
opts: {
|
|
|
|
message_id: 2001,
|
|
|
|
emoji_name: '8ball',
|
|
|
|
user_id: bob.user_id,
|
|
|
|
user_list: [alice.user_id, bob.user_id],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
|
|
|
|
|
|
|
test_view_calls({
|
|
|
|
run_code: function () {
|
|
|
|
reactions.add_reaction(cali_airplane_event);
|
|
|
|
},
|
|
|
|
expected_view_calls: [
|
|
|
|
{
|
|
|
|
name: 'insert_new_reaction',
|
|
|
|
opts: {
|
|
|
|
message_id: 2001,
|
|
|
|
emoji_name: 'airplane',
|
|
|
|
user_id: cali.user_id,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
|
|
|
|
|
|
|
test_view_calls({
|
|
|
|
run_code: function () {
|
|
|
|
reactions.remove_reaction(bob_8ball_event);
|
|
|
|
},
|
|
|
|
expected_view_calls: [
|
|
|
|
{
|
|
|
|
name: 'remove_reaction',
|
|
|
|
opts: {
|
|
|
|
message_id: 2001,
|
|
|
|
emoji_name: '8ball',
|
|
|
|
user_id: bob.user_id,
|
|
|
|
user_list: [alice.user_id],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
|
|
|
|
|
|
|
test_view_calls({
|
|
|
|
run_code: function () {
|
|
|
|
reactions.remove_reaction(alice_8ball_event);
|
|
|
|
},
|
|
|
|
expected_view_calls: [
|
|
|
|
{
|
|
|
|
name: 'remove_reaction',
|
|
|
|
opts: {
|
|
|
|
message_id: 2001,
|
|
|
|
emoji_name: '8ball',
|
|
|
|
user_id: alice.user_id,
|
|
|
|
user_list: [],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
|
|
|
|
|
|
|
}());
|
|
|
|
|
2017-05-31 00:09:50 +02:00
|
|
|
(function test_error_handling() {
|
|
|
|
var error_msg;
|
|
|
|
|
|
|
|
global.message_store.get = function () {
|
|
|
|
return;
|
|
|
|
};
|
|
|
|
|
|
|
|
global.blueslip.error = function (msg) {
|
|
|
|
error_msg = msg;
|
|
|
|
};
|
|
|
|
|
|
|
|
var bogus_event = {
|
|
|
|
message_id: 55,
|
|
|
|
emoji_name: 'realm_emoji',
|
|
|
|
user: {
|
|
|
|
user_id: 99,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
reactions.toggle_emoji_reaction(55);
|
|
|
|
assert.equal(error_msg, 'reactions: Bad message id: 55');
|
|
|
|
|
|
|
|
error_msg = undefined;
|
|
|
|
reactions.add_reaction(bogus_event);
|
|
|
|
assert.equal(error_msg, undefined);
|
|
|
|
|
|
|
|
reactions.remove_reaction(bogus_event);
|
|
|
|
assert.equal(error_msg, undefined);
|
|
|
|
}());
|