2018-06-21 08:22:40 -04:00
|
|
|
/* eslint-disable no-var, one-var, one-var-declaration-per-line, no-unused-expressions, no-unused-vars, prefer-template, max-len */
|
2016-07-24 16:45:11 -04:00
|
|
|
|
2018-03-09 15:18:59 -05:00
|
|
|
import $ from 'jquery';
|
2017-03-09 12:55:18 -05:00
|
|
|
import Cookies from 'js-cookie';
|
2017-06-26 23:43:32 -04:00
|
|
|
import loadAwardsHandler from '~/awards_handler';
|
2017-02-27 23:44:34 -05:00
|
|
|
|
2017-05-16 17:01:51 -04:00
|
|
|
import '~/lib/utils/common_utils';
|
2016-09-08 06:08:09 -04:00
|
|
|
|
2016-07-24 16:45:11 -04:00
|
|
|
(function() {
|
2017-02-27 23:44:34 -05:00
|
|
|
var awardsHandler, lazyAssert, urlRoot, openAndWaitForEmojiMenu;
|
2016-07-24 16:45:11 -04:00
|
|
|
|
|
|
|
awardsHandler = null;
|
|
|
|
|
|
|
|
window.gl || (window.gl = {});
|
|
|
|
|
|
|
|
window.gon || (window.gon = {});
|
|
|
|
|
2016-08-02 11:16:41 -04:00
|
|
|
urlRoot = gon.relative_url_root;
|
2016-07-24 16:45:11 -04:00
|
|
|
|
|
|
|
lazyAssert = function(done, assertFn) {
|
|
|
|
return setTimeout(function() {
|
|
|
|
assertFn();
|
|
|
|
return done();
|
2018-06-21 08:22:40 -04:00
|
|
|
// Maybe jasmine.clock here?
|
2016-07-24 16:45:11 -04:00
|
|
|
}, 333);
|
|
|
|
};
|
|
|
|
|
|
|
|
describe('AwardsHandler', function() {
|
2018-06-21 08:22:40 -04:00
|
|
|
preloadFixtures('snippets/show.html.raw');
|
2017-06-26 23:43:32 -04:00
|
|
|
beforeEach(function(done) {
|
2018-06-21 08:22:40 -04:00
|
|
|
loadFixtures('snippets/show.html.raw');
|
|
|
|
loadAwardsHandler(true)
|
|
|
|
.then(obj => {
|
|
|
|
awardsHandler = obj;
|
|
|
|
spyOn(awardsHandler, 'postEmoji').and.callFake((button, url, emoji, cb) => cb());
|
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(fail);
|
2017-02-27 23:44:34 -05:00
|
|
|
|
|
|
|
let isEmojiMenuBuilt = false;
|
|
|
|
openAndWaitForEmojiMenu = function() {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
if (isEmojiMenuBuilt) {
|
|
|
|
resolve();
|
|
|
|
} else {
|
2018-06-21 08:22:40 -04:00
|
|
|
$('.js-add-award')
|
|
|
|
.eq(0)
|
|
|
|
.click();
|
2017-02-27 23:44:34 -05:00
|
|
|
const $menu = $('.emoji-menu');
|
|
|
|
$menu.one('build-emoji-menu-finish', () => {
|
|
|
|
isEmojiMenuBuilt = true;
|
|
|
|
resolve();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
2016-08-02 11:16:41 -04:00
|
|
|
});
|
|
|
|
afterEach(function() {
|
|
|
|
// restore original url root value
|
|
|
|
gon.relative_url_root = urlRoot;
|
2017-02-27 23:44:34 -05:00
|
|
|
|
2017-10-06 16:36:15 -04:00
|
|
|
// Undo what we did to the shared <body>
|
|
|
|
$('body').removeAttr('data-page');
|
|
|
|
|
2017-02-27 23:44:34 -05:00
|
|
|
awardsHandler.destroy();
|
2016-07-24 16:45:11 -04:00
|
|
|
});
|
|
|
|
describe('::showEmojiMenu', function() {
|
|
|
|
it('should show emoji menu when Add emoji button clicked', function(done) {
|
2018-06-21 08:22:40 -04:00
|
|
|
$('.js-add-award')
|
|
|
|
.eq(0)
|
|
|
|
.click();
|
2016-07-24 16:45:11 -04:00
|
|
|
return lazyAssert(done, function() {
|
|
|
|
var $emojiMenu;
|
|
|
|
$emojiMenu = $('.emoji-menu');
|
|
|
|
expect($emojiMenu.length).toBe(1);
|
|
|
|
expect($emojiMenu.hasClass('is-visible')).toBe(true);
|
2017-04-07 01:28:30 -04:00
|
|
|
expect($emojiMenu.find('.js-emoji-menu-search').length).toBe(1);
|
2016-07-24 16:45:11 -04:00
|
|
|
return expect($('.js-awards-block.current').length).toBe(1);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
it('should also show emoji menu for the smiley icon in notes', function(done) {
|
2017-02-27 23:44:34 -05:00
|
|
|
$('.js-add-award.note-action-button').click();
|
2016-07-24 16:45:11 -04:00
|
|
|
return lazyAssert(done, function() {
|
2017-02-27 23:44:34 -05:00
|
|
|
var $emojiMenu = $('.emoji-menu');
|
2016-07-24 16:45:11 -04:00
|
|
|
return expect($emojiMenu.length).toBe(1);
|
|
|
|
});
|
|
|
|
});
|
2018-02-06 16:36:49 -05:00
|
|
|
it('should remove emoji menu when body is clicked', function(done) {
|
2018-06-21 08:22:40 -04:00
|
|
|
$('.js-add-award')
|
|
|
|
.eq(0)
|
|
|
|
.click();
|
2016-07-24 16:45:11 -04:00
|
|
|
return lazyAssert(done, function() {
|
|
|
|
var $emojiMenu;
|
|
|
|
$emojiMenu = $('.emoji-menu');
|
|
|
|
$('body').click();
|
|
|
|
expect($emojiMenu.length).toBe(1);
|
|
|
|
expect($emojiMenu.hasClass('is-visible')).toBe(false);
|
|
|
|
return expect($('.js-awards-block.current').length).toBe(0);
|
|
|
|
});
|
|
|
|
});
|
2018-02-06 16:36:49 -05:00
|
|
|
it('should not remove emoji menu when search is clicked', function(done) {
|
2018-06-21 08:22:40 -04:00
|
|
|
$('.js-add-award')
|
|
|
|
.eq(0)
|
|
|
|
.click();
|
2018-02-06 16:36:49 -05:00
|
|
|
return lazyAssert(done, function() {
|
|
|
|
var $emojiMenu;
|
|
|
|
$emojiMenu = $('.emoji-menu');
|
|
|
|
$('.emoji-search').click();
|
|
|
|
expect($emojiMenu.length).toBe(1);
|
|
|
|
expect($emojiMenu.hasClass('is-visible')).toBe(true);
|
|
|
|
return expect($('.js-awards-block.current').length).toBe(1);
|
|
|
|
});
|
|
|
|
});
|
2016-07-24 16:45:11 -04:00
|
|
|
});
|
2018-06-21 08:22:40 -04:00
|
|
|
|
2016-07-24 16:45:11 -04:00
|
|
|
describe('::addAwardToEmojiBar', function() {
|
|
|
|
it('should add emoji to votes block', function() {
|
|
|
|
var $emojiButton, $votesBlock;
|
|
|
|
$votesBlock = $('.js-awards-block').eq(0);
|
|
|
|
awardsHandler.addAwardToEmojiBar($votesBlock, 'heart', false);
|
2017-02-27 23:44:34 -05:00
|
|
|
$emojiButton = $votesBlock.find('[data-name=heart]');
|
2016-07-24 16:45:11 -04:00
|
|
|
expect($emojiButton.length).toBe(1);
|
|
|
|
expect($emojiButton.next('.js-counter').text()).toBe('1');
|
|
|
|
return expect($votesBlock.hasClass('hidden')).toBe(false);
|
|
|
|
});
|
|
|
|
it('should remove the emoji when we click again', function() {
|
|
|
|
var $emojiButton, $votesBlock;
|
|
|
|
$votesBlock = $('.js-awards-block').eq(0);
|
|
|
|
awardsHandler.addAwardToEmojiBar($votesBlock, 'heart', false);
|
|
|
|
awardsHandler.addAwardToEmojiBar($votesBlock, 'heart', false);
|
2017-02-27 23:44:34 -05:00
|
|
|
$emojiButton = $votesBlock.find('[data-name=heart]');
|
2016-07-24 16:45:11 -04:00
|
|
|
return expect($emojiButton.length).toBe(0);
|
|
|
|
});
|
|
|
|
return it('should decrement the emoji counter', function() {
|
|
|
|
var $emojiButton, $votesBlock;
|
|
|
|
$votesBlock = $('.js-awards-block').eq(0);
|
|
|
|
awardsHandler.addAwardToEmojiBar($votesBlock, 'heart', false);
|
2017-02-27 23:44:34 -05:00
|
|
|
$emojiButton = $votesBlock.find('[data-name=heart]');
|
2016-07-24 16:45:11 -04:00
|
|
|
$emojiButton.next('.js-counter').text(5);
|
|
|
|
awardsHandler.addAwardToEmojiBar($votesBlock, 'heart', false);
|
|
|
|
expect($emojiButton.length).toBe(1);
|
|
|
|
return expect($emojiButton.next('.js-counter').text()).toBe('4');
|
|
|
|
});
|
|
|
|
});
|
2016-09-08 06:08:09 -04:00
|
|
|
describe('::userAuthored', function() {
|
|
|
|
it('should update tooltip to user authored title', function() {
|
|
|
|
var $thumbsUpEmoji, $votesBlock;
|
|
|
|
$votesBlock = $('.js-awards-block').eq(0);
|
|
|
|
$thumbsUpEmoji = $votesBlock.find('[data-name=thumbsup]').parent();
|
|
|
|
$thumbsUpEmoji.attr('data-title', 'sam');
|
|
|
|
awardsHandler.userAuthored($thumbsUpEmoji);
|
2018-06-21 08:22:40 -04:00
|
|
|
return expect($thumbsUpEmoji.data('originalTitle')).toBe(
|
|
|
|
'You cannot vote on your own issue, MR and note',
|
|
|
|
);
|
2016-09-08 06:08:09 -04:00
|
|
|
});
|
|
|
|
it('should restore tooltip back to initial vote list', function() {
|
|
|
|
var $thumbsUpEmoji, $votesBlock;
|
|
|
|
jasmine.clock().install();
|
|
|
|
$votesBlock = $('.js-awards-block').eq(0);
|
|
|
|
$thumbsUpEmoji = $votesBlock.find('[data-name=thumbsup]').parent();
|
|
|
|
$thumbsUpEmoji.attr('data-title', 'sam');
|
|
|
|
awardsHandler.userAuthored($thumbsUpEmoji);
|
|
|
|
jasmine.clock().tick(2801);
|
|
|
|
jasmine.clock().uninstall();
|
2018-06-21 08:22:40 -04:00
|
|
|
return expect($thumbsUpEmoji.data('originalTitle')).toBe('sam');
|
2016-09-08 06:08:09 -04:00
|
|
|
});
|
|
|
|
});
|
2016-07-24 16:45:11 -04:00
|
|
|
describe('::getAwardUrl', function() {
|
2016-08-11 11:30:18 -04:00
|
|
|
return it('returns the url for request', function() {
|
2018-06-21 08:22:40 -04:00
|
|
|
return expect(awardsHandler.getAwardUrl()).toBe(
|
|
|
|
'http://test.host/snippets/1/toggle_award_emoji',
|
|
|
|
);
|
2016-07-24 16:45:11 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
describe('::addAward and ::checkMutuality', function() {
|
|
|
|
return it('should handle :+1: and :-1: mutuality', function() {
|
|
|
|
var $thumbsDownEmoji, $thumbsUpEmoji, $votesBlock, awardUrl;
|
|
|
|
awardUrl = awardsHandler.getAwardUrl();
|
|
|
|
$votesBlock = $('.js-awards-block').eq(0);
|
2017-02-27 23:44:34 -05:00
|
|
|
$thumbsUpEmoji = $votesBlock.find('[data-name=thumbsup]').parent();
|
|
|
|
$thumbsDownEmoji = $votesBlock.find('[data-name=thumbsdown]').parent();
|
2016-07-24 16:45:11 -04:00
|
|
|
awardsHandler.addAward($votesBlock, awardUrl, 'thumbsup', false);
|
|
|
|
expect($thumbsUpEmoji.hasClass('active')).toBe(true);
|
|
|
|
expect($thumbsDownEmoji.hasClass('active')).toBe(false);
|
|
|
|
$thumbsUpEmoji.tooltip();
|
|
|
|
$thumbsDownEmoji.tooltip();
|
|
|
|
awardsHandler.addAward($votesBlock, awardUrl, 'thumbsdown', true);
|
|
|
|
expect($thumbsUpEmoji.hasClass('active')).toBe(false);
|
|
|
|
return expect($thumbsDownEmoji.hasClass('active')).toBe(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
describe('::removeEmoji', function() {
|
|
|
|
return it('should remove emoji', function() {
|
|
|
|
var $votesBlock, awardUrl;
|
|
|
|
awardUrl = awardsHandler.getAwardUrl();
|
|
|
|
$votesBlock = $('.js-awards-block').eq(0);
|
|
|
|
awardsHandler.addAward($votesBlock, awardUrl, 'fire', false);
|
2017-02-27 23:44:34 -05:00
|
|
|
expect($votesBlock.find('[data-name=fire]').length).toBe(1);
|
|
|
|
awardsHandler.removeEmoji($votesBlock.find('[data-name=fire]').closest('button'));
|
|
|
|
return expect($votesBlock.find('[data-name=fire]').length).toBe(0);
|
2016-07-24 16:45:11 -04:00
|
|
|
});
|
|
|
|
});
|
2016-07-11 14:53:07 -04:00
|
|
|
describe('::addYouToUserList', function() {
|
|
|
|
it('should prepend "You" to the award tooltip', function() {
|
2016-06-19 19:06:57 -04:00
|
|
|
var $thumbsUpEmoji, $votesBlock, awardUrl;
|
|
|
|
awardUrl = awardsHandler.getAwardUrl();
|
|
|
|
$votesBlock = $('.js-awards-block').eq(0);
|
2017-02-27 23:44:34 -05:00
|
|
|
$thumbsUpEmoji = $votesBlock.find('[data-name=thumbsup]').parent();
|
2016-06-23 15:02:11 -04:00
|
|
|
$thumbsUpEmoji.attr('data-title', 'sam, jerry, max, and andy');
|
2016-06-19 19:06:57 -04:00
|
|
|
awardsHandler.addAward($votesBlock, awardUrl, 'thumbsup', false);
|
|
|
|
$thumbsUpEmoji.tooltip();
|
2018-06-21 08:22:40 -04:00
|
|
|
return expect($thumbsUpEmoji.data('originalTitle')).toBe('You, sam, jerry, max, and andy');
|
2016-06-23 15:02:11 -04:00
|
|
|
});
|
2016-07-11 14:53:07 -04:00
|
|
|
return it('handles the special case where "You" is not cleanly comma seperated', function() {
|
2016-06-23 15:02:11 -04:00
|
|
|
var $thumbsUpEmoji, $votesBlock, awardUrl;
|
|
|
|
awardUrl = awardsHandler.getAwardUrl();
|
|
|
|
$votesBlock = $('.js-awards-block').eq(0);
|
2017-02-27 23:44:34 -05:00
|
|
|
$thumbsUpEmoji = $votesBlock.find('[data-name=thumbsup]').parent();
|
2016-06-23 15:02:11 -04:00
|
|
|
$thumbsUpEmoji.attr('data-title', 'sam');
|
|
|
|
awardsHandler.addAward($votesBlock, awardUrl, 'thumbsup', false);
|
|
|
|
$thumbsUpEmoji.tooltip();
|
2018-06-21 08:22:40 -04:00
|
|
|
return expect($thumbsUpEmoji.data('originalTitle')).toBe('You and sam');
|
2016-06-19 19:06:57 -04:00
|
|
|
});
|
|
|
|
});
|
2016-07-11 14:53:07 -04:00
|
|
|
describe('::removeYouToUserList', function() {
|
|
|
|
it('removes "You" from the front of the tooltip', function() {
|
2016-06-23 15:02:11 -04:00
|
|
|
var $thumbsUpEmoji, $votesBlock, awardUrl;
|
|
|
|
awardUrl = awardsHandler.getAwardUrl();
|
|
|
|
$votesBlock = $('.js-awards-block').eq(0);
|
2017-02-27 23:44:34 -05:00
|
|
|
$thumbsUpEmoji = $votesBlock.find('[data-name=thumbsup]').parent();
|
2016-07-11 14:53:07 -04:00
|
|
|
$thumbsUpEmoji.attr('data-title', 'You, sam, jerry, max, and andy');
|
2016-06-23 15:02:11 -04:00
|
|
|
$thumbsUpEmoji.addClass('active');
|
|
|
|
awardsHandler.addAward($votesBlock, awardUrl, 'thumbsup', false);
|
|
|
|
$thumbsUpEmoji.tooltip();
|
2018-06-21 08:22:40 -04:00
|
|
|
return expect($thumbsUpEmoji.data('originalTitle')).toBe('sam, jerry, max, and andy');
|
2016-06-23 15:02:11 -04:00
|
|
|
});
|
2016-07-11 14:53:07 -04:00
|
|
|
return it('handles the special case where "You" is not cleanly comma seperated', function() {
|
2016-06-19 19:06:57 -04:00
|
|
|
var $thumbsUpEmoji, $votesBlock, awardUrl;
|
|
|
|
awardUrl = awardsHandler.getAwardUrl();
|
|
|
|
$votesBlock = $('.js-awards-block').eq(0);
|
2017-02-27 23:44:34 -05:00
|
|
|
$thumbsUpEmoji = $votesBlock.find('[data-name=thumbsup]').parent();
|
2016-07-11 14:53:07 -04:00
|
|
|
$thumbsUpEmoji.attr('data-title', 'You and sam');
|
2016-06-19 19:06:57 -04:00
|
|
|
$thumbsUpEmoji.addClass('active');
|
|
|
|
awardsHandler.addAward($votesBlock, awardUrl, 'thumbsup', false);
|
|
|
|
$thumbsUpEmoji.tooltip();
|
2018-06-21 08:22:40 -04:00
|
|
|
return expect($thumbsUpEmoji.data('originalTitle')).toBe('sam');
|
2016-06-19 19:06:57 -04:00
|
|
|
});
|
|
|
|
});
|
2017-04-07 01:28:30 -04:00
|
|
|
describe('::searchEmojis', () => {
|
|
|
|
it('should filter the emoji', function(done) {
|
2017-02-27 23:44:34 -05:00
|
|
|
return openAndWaitForEmojiMenu()
|
|
|
|
.then(() => {
|
|
|
|
expect($('[data-name=angel]').is(':visible')).toBe(true);
|
|
|
|
expect($('[data-name=anger]').is(':visible')).toBe(true);
|
2017-04-07 01:28:30 -04:00
|
|
|
awardsHandler.searchEmojis('ali');
|
2017-02-27 23:44:34 -05:00
|
|
|
expect($('[data-name=angel]').is(':visible')).toBe(false);
|
|
|
|
expect($('[data-name=anger]').is(':visible')).toBe(false);
|
|
|
|
expect($('[data-name=alien]').is(':visible')).toBe(true);
|
2017-04-07 01:28:30 -04:00
|
|
|
expect($('.js-emoji-menu-search').val()).toBe('ali');
|
|
|
|
})
|
|
|
|
.then(done)
|
2018-06-21 08:22:40 -04:00
|
|
|
.catch(err => {
|
2017-04-07 01:28:30 -04:00
|
|
|
done.fail(`Failed to open and build emoji menu: ${err.message}`);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
it('should clear the search when searching for nothing', function(done) {
|
|
|
|
return openAndWaitForEmojiMenu()
|
|
|
|
.then(() => {
|
|
|
|
awardsHandler.searchEmojis('ali');
|
|
|
|
expect($('[data-name=angel]').is(':visible')).toBe(false);
|
|
|
|
expect($('[data-name=anger]').is(':visible')).toBe(false);
|
|
|
|
expect($('[data-name=alien]').is(':visible')).toBe(true);
|
|
|
|
awardsHandler.searchEmojis('');
|
|
|
|
expect($('[data-name=angel]').is(':visible')).toBe(true);
|
|
|
|
expect($('[data-name=anger]').is(':visible')).toBe(true);
|
|
|
|
expect($('[data-name=alien]').is(':visible')).toBe(true);
|
|
|
|
expect($('.js-emoji-menu-search').val()).toBe('');
|
2017-02-27 23:44:34 -05:00
|
|
|
})
|
|
|
|
.then(done)
|
2018-06-21 08:22:40 -04:00
|
|
|
.catch(err => {
|
2017-03-09 12:55:18 -05:00
|
|
|
done.fail(`Failed to open and build emoji menu: ${err.message}`);
|
2017-02-27 23:44:34 -05:00
|
|
|
});
|
2016-07-24 16:45:11 -04:00
|
|
|
});
|
|
|
|
});
|
2017-04-07 01:28:30 -04:00
|
|
|
|
2017-02-27 23:44:34 -05:00
|
|
|
describe('emoji menu', function() {
|
2017-03-02 23:34:48 -05:00
|
|
|
const emojiSelector = '[data-name="sunglasses"]';
|
2017-02-27 23:44:34 -05:00
|
|
|
const openEmojiMenuAndAddEmoji = function() {
|
2018-06-21 08:22:40 -04:00
|
|
|
return openAndWaitForEmojiMenu().then(() => {
|
|
|
|
const $menu = $('.emoji-menu');
|
|
|
|
const $block = $('.js-awards-block');
|
|
|
|
const $emoji = $menu.find('.emoji-menu-list:not(.frequent-emojis) ' + emojiSelector);
|
2017-02-27 23:44:34 -05:00
|
|
|
|
2018-06-21 08:22:40 -04:00
|
|
|
expect($emoji.length).toBe(1);
|
|
|
|
expect($block.find(emojiSelector).length).toBe(0);
|
|
|
|
$emoji.click();
|
|
|
|
expect($menu.hasClass('.is-visible')).toBe(false);
|
|
|
|
expect($block.find(emojiSelector).length).toBe(1);
|
|
|
|
});
|
2016-07-24 16:45:11 -04:00
|
|
|
};
|
2017-02-27 23:44:34 -05:00
|
|
|
it('should add selected emoji to awards block', function(done) {
|
|
|
|
return openEmojiMenuAndAddEmoji()
|
|
|
|
.then(done)
|
2018-06-21 08:22:40 -04:00
|
|
|
.catch(err => {
|
2017-03-09 12:55:18 -05:00
|
|
|
done.fail(`Failed to open and build emoji menu: ${err.message}`);
|
2017-02-27 23:44:34 -05:00
|
|
|
});
|
2016-07-24 16:45:11 -04:00
|
|
|
});
|
2017-02-27 23:44:34 -05:00
|
|
|
it('should remove already selected emoji', function(done) {
|
|
|
|
return openEmojiMenuAndAddEmoji()
|
|
|
|
.then(() => {
|
2018-06-21 08:22:40 -04:00
|
|
|
$('.js-add-award')
|
|
|
|
.eq(0)
|
|
|
|
.click();
|
2017-02-27 23:44:34 -05:00
|
|
|
const $block = $('.js-awards-block');
|
2018-06-21 08:22:40 -04:00
|
|
|
const $emoji = $('.emoji-menu').find(
|
|
|
|
`.emoji-menu-list:not(.frequent-emojis) ${emojiSelector}`,
|
|
|
|
);
|
2017-02-27 23:44:34 -05:00
|
|
|
$emoji.click();
|
|
|
|
expect($block.find(emojiSelector).length).toBe(0);
|
|
|
|
})
|
|
|
|
.then(done)
|
2018-06-21 08:22:40 -04:00
|
|
|
.catch(err => {
|
2017-03-09 12:55:18 -05:00
|
|
|
done.fail(`Failed to open and build emoji menu: ${err.message}`);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('frequently used emojis', function() {
|
|
|
|
beforeEach(() => {
|
|
|
|
// Clear it out
|
|
|
|
Cookies.set('frequently_used_emojis', '');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('shouldn\'t have any "Frequently used" heading if no frequently used emojis', function(done) {
|
|
|
|
return openAndWaitForEmojiMenu()
|
|
|
|
.then(() => {
|
|
|
|
const emojiMenu = document.querySelector('.emoji-menu');
|
2018-06-21 08:22:40 -04:00
|
|
|
Array.prototype.forEach.call(emojiMenu.querySelectorAll('.emoji-menu-title'), title => {
|
2017-03-09 12:55:18 -05:00
|
|
|
expect(title.textContent.trim().toLowerCase()).not.toBe('frequently used');
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.then(done)
|
2018-06-21 08:22:40 -04:00
|
|
|
.catch(err => {
|
2017-03-09 12:55:18 -05:00
|
|
|
done.fail(`Failed to open and build emoji menu: ${err.message}`);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should have any frequently used section when there are frequently used emojis', function(done) {
|
|
|
|
awardsHandler.addEmojiToFrequentlyUsedList('8ball');
|
|
|
|
|
|
|
|
return openAndWaitForEmojiMenu()
|
|
|
|
.then(() => {
|
|
|
|
const emojiMenu = document.querySelector('.emoji-menu');
|
2018-06-21 08:22:40 -04:00
|
|
|
const hasFrequentlyUsedHeading = Array.prototype.some.call(
|
|
|
|
emojiMenu.querySelectorAll('.emoji-menu-title'),
|
|
|
|
title => title.textContent.trim().toLowerCase() === 'frequently used',
|
2017-03-09 12:55:18 -05:00
|
|
|
);
|
|
|
|
|
|
|
|
expect(hasFrequentlyUsedHeading).toBe(true);
|
|
|
|
})
|
|
|
|
.then(done)
|
2018-06-21 08:22:40 -04:00
|
|
|
.catch(err => {
|
2017-03-09 12:55:18 -05:00
|
|
|
done.fail(`Failed to open and build emoji menu: ${err.message}`);
|
2017-02-27 23:44:34 -05:00
|
|
|
});
|
2016-07-24 16:45:11 -04:00
|
|
|
});
|
2017-03-16 15:37:25 -04:00
|
|
|
|
|
|
|
it('should disregard invalid frequently used emoji that are being attempted to be added', function() {
|
|
|
|
awardsHandler.addEmojiToFrequentlyUsedList('8ball');
|
|
|
|
awardsHandler.addEmojiToFrequentlyUsedList('invalid_emoji');
|
|
|
|
awardsHandler.addEmojiToFrequentlyUsedList('grinning');
|
|
|
|
|
|
|
|
expect(awardsHandler.getFrequentlyUsedEmojis()).toEqual(['8ball', 'grinning']);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should disregard invalid frequently used emoji already set in cookie', function() {
|
|
|
|
Cookies.set('frequently_used_emojis', '8ball,invalid_emoji,grinning');
|
|
|
|
|
|
|
|
expect(awardsHandler.getFrequentlyUsedEmojis()).toEqual(['8ball', 'grinning']);
|
|
|
|
});
|
2016-07-24 16:45:11 -04:00
|
|
|
});
|
|
|
|
});
|
2018-06-21 08:22:40 -04:00
|
|
|
}.call(window));
|