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',
|
|
|
|
});
|
|
|
|
|
|
|
|
var reactions = require("js/reactions.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-03-26 20:20:42 +02:00
|
|
|
realm_emojis: {},
|
|
|
|
});
|
|
|
|
|
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-03-26 20:20:42 +02:00
|
|
|
(function make_people() {
|
|
|
|
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-05-28 16:18:12 +02:00
|
|
|
var message = {
|
|
|
|
id: 1001,
|
|
|
|
reactions: [
|
|
|
|
{emoji_name: 'smile', user: {id: 5}},
|
|
|
|
{emoji_name: 'smile', user: {id: 6}},
|
|
|
|
{emoji_name: 'frown', user: {id: 7}},
|
2017-03-26 20:20:42 +02:00
|
|
|
|
2017-05-28 16:18:12 +02:00
|
|
|
// 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() {
|
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',
|
|
|
|
emoji_name_css_class: 'frown-css',
|
|
|
|
count: 1,
|
|
|
|
title: 'Cali reacted with :frown:',
|
|
|
|
emoji_alt_code: undefined,
|
|
|
|
class: 'message_reaction',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
emoji_name: 'smile',
|
|
|
|
emoji_name_css_class: 'smile-css',
|
|
|
|
count: 2,
|
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;
|
|
|
|
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);
|
|
|
|
}());
|