2018-03-09 15:18:59 -05:00
|
|
|
import $ from 'jquery';
|
2022-05-14 02:09:05 -04:00
|
|
|
import Cookies from '~/lib/utils/cookies';
|
2022-05-13 08:08:49 -04:00
|
|
|
import { loadHTMLFixture, resetHTMLFixture } from 'helpers/fixtures';
|
2021-12-15 19:15:50 -05:00
|
|
|
import { initEmojiMock, clearEmojiMock } from 'helpers/emoji';
|
2020-08-17 17:09:56 -04:00
|
|
|
import { useFakeRequestAnimationFrame } from 'helpers/fake_request_animation_frame';
|
2017-06-26 23:43:32 -04:00
|
|
|
import loadAwardsHandler from '~/awards_handler';
|
2016-09-08 06:08:09 -04:00
|
|
|
|
2018-10-17 03:07:04 -04:00
|
|
|
window.gl = window.gl || {};
|
|
|
|
window.gon = window.gon || {};
|
|
|
|
|
|
|
|
let awardsHandler = null;
|
|
|
|
const urlRoot = gon.relative_url_root;
|
|
|
|
|
2020-06-08 05:08:23 -04:00
|
|
|
describe('AwardsHandler', () => {
|
2020-07-16 02:09:33 -04:00
|
|
|
useFakeRequestAnimationFrame();
|
|
|
|
|
2020-08-27 02:10:37 -04:00
|
|
|
const emojiData = {
|
|
|
|
'8ball': {
|
|
|
|
c: 'activity',
|
|
|
|
e: '🎱',
|
|
|
|
d: 'billiards',
|
|
|
|
u: '6.0',
|
|
|
|
},
|
|
|
|
grinning: {
|
|
|
|
c: 'people',
|
|
|
|
e: '😀',
|
|
|
|
d: 'grinning face',
|
|
|
|
u: '6.1',
|
|
|
|
},
|
|
|
|
angel: {
|
|
|
|
c: 'people',
|
|
|
|
e: '👼',
|
|
|
|
d: 'baby angel',
|
|
|
|
u: '6.0',
|
|
|
|
},
|
|
|
|
anger: {
|
|
|
|
c: 'symbols',
|
|
|
|
e: '💢',
|
|
|
|
d: 'anger symbol',
|
|
|
|
u: '6.0',
|
|
|
|
},
|
|
|
|
alien: {
|
|
|
|
c: 'people',
|
|
|
|
e: '👽',
|
|
|
|
d: 'extraterrestrial alien',
|
|
|
|
u: '6.0',
|
|
|
|
},
|
|
|
|
sunglasses: {
|
|
|
|
c: 'people',
|
|
|
|
e: '😎',
|
|
|
|
d: 'smiling face with sunglasses',
|
|
|
|
u: '6.0',
|
|
|
|
},
|
2021-02-06 04:09:11 -05:00
|
|
|
grey_question: {
|
|
|
|
c: 'symbols',
|
|
|
|
e: '❔',
|
|
|
|
d: 'white question mark ornament',
|
|
|
|
u: '6.0',
|
|
|
|
},
|
2022-06-10 11:09:22 -04:00
|
|
|
thumbsup: {
|
|
|
|
c: 'people',
|
|
|
|
e: '👍',
|
|
|
|
d: 'thumbs up sign',
|
|
|
|
u: '6.0',
|
|
|
|
},
|
|
|
|
thumbsdown: {
|
|
|
|
c: 'people',
|
|
|
|
e: '👎',
|
|
|
|
d: 'thumbs down sign',
|
|
|
|
u: '6.0',
|
|
|
|
},
|
2020-08-27 02:10:37 -04:00
|
|
|
};
|
2020-07-08 02:09:13 -04:00
|
|
|
|
2020-07-16 02:09:33 -04:00
|
|
|
const openAndWaitForEmojiMenu = (sel = '.js-add-award') => {
|
2020-12-23 07:10:26 -05:00
|
|
|
$(sel).eq(0).click();
|
2020-07-16 02:09:33 -04:00
|
|
|
|
2020-08-27 02:10:37 -04:00
|
|
|
jest.runOnlyPendingTimers();
|
2020-07-16 02:09:33 -04:00
|
|
|
|
|
|
|
const $menu = $('.emoji-menu');
|
|
|
|
|
2020-12-23 16:10:24 -05:00
|
|
|
return new Promise((resolve) => {
|
2020-07-16 02:09:33 -04:00
|
|
|
$menu.one('build-emoji-menu-finish', () => {
|
|
|
|
resolve();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
beforeEach(async () => {
|
2021-12-15 19:15:50 -05:00
|
|
|
await initEmojiMock(emojiData);
|
2020-07-08 02:09:13 -04:00
|
|
|
|
2022-05-13 08:08:49 -04:00
|
|
|
loadHTMLFixture('snippets/show.html');
|
2020-07-16 02:09:33 -04:00
|
|
|
|
|
|
|
awardsHandler = await loadAwardsHandler(true);
|
|
|
|
jest.spyOn(awardsHandler, 'postEmoji').mockImplementation((button, url, emoji, cb) => cb());
|
2018-10-17 03:07:04 -04:00
|
|
|
});
|
2016-07-24 16:45:11 -04:00
|
|
|
|
2020-06-08 05:08:23 -04:00
|
|
|
afterEach(() => {
|
2018-10-17 03:07:04 -04:00
|
|
|
// restore original url root value
|
|
|
|
gon.relative_url_root = urlRoot;
|
2016-07-24 16:45:11 -04:00
|
|
|
|
2021-12-15 19:15:50 -05:00
|
|
|
clearEmojiMock();
|
2020-07-08 02:09:13 -04:00
|
|
|
|
2018-10-17 03:07:04 -04:00
|
|
|
// Undo what we did to the shared <body>
|
|
|
|
$('body').removeAttr('data-page');
|
2016-07-24 16:45:11 -04:00
|
|
|
|
2018-10-17 03:07:04 -04:00
|
|
|
awardsHandler.destroy();
|
2022-05-13 08:08:49 -04:00
|
|
|
|
|
|
|
resetHTMLFixture();
|
2018-10-17 03:07:04 -04:00
|
|
|
});
|
2016-07-24 16:45:11 -04:00
|
|
|
|
2020-06-08 05:08:23 -04:00
|
|
|
describe('::showEmojiMenu', () => {
|
2020-07-16 02:09:33 -04:00
|
|
|
it('should show emoji menu when Add emoji button clicked', async () => {
|
|
|
|
await openAndWaitForEmojiMenu();
|
2018-10-17 03:07:04 -04:00
|
|
|
|
2020-07-16 02:09:33 -04:00
|
|
|
const $emojiMenu = $('.emoji-menu');
|
|
|
|
|
|
|
|
expect($emojiMenu.length).toBe(1);
|
|
|
|
expect($emojiMenu.hasClass('is-visible')).toBe(true);
|
|
|
|
expect($emojiMenu.find('.js-emoji-menu-search').length).toBe(1);
|
|
|
|
expect($('.js-awards-block.current').length).toBe(1);
|
2018-10-17 03:07:04 -04:00
|
|
|
});
|
2016-07-24 16:45:11 -04:00
|
|
|
|
2020-07-16 02:09:33 -04:00
|
|
|
it('should also show emoji menu for the smiley icon in notes', async () => {
|
|
|
|
await openAndWaitForEmojiMenu('.js-add-award.note-action-button');
|
2016-07-24 16:45:11 -04:00
|
|
|
|
2020-07-16 02:09:33 -04:00
|
|
|
const $emojiMenu = $('.emoji-menu');
|
|
|
|
|
|
|
|
expect($emojiMenu.length).toBe(1);
|
2018-10-17 03:07:04 -04:00
|
|
|
});
|
2017-02-27 23:44:34 -05:00
|
|
|
|
2020-07-16 02:09:33 -04:00
|
|
|
it('should remove emoji menu when body is clicked', async () => {
|
|
|
|
await openAndWaitForEmojiMenu();
|
2018-10-17 03:07:04 -04:00
|
|
|
|
2020-07-16 02:09:33 -04:00
|
|
|
const $emojiMenu = $('.emoji-menu');
|
|
|
|
$('body').click();
|
|
|
|
|
|
|
|
expect($emojiMenu.length).toBe(1);
|
|
|
|
expect($emojiMenu.hasClass('is-visible')).toBe(false);
|
|
|
|
expect($('.js-awards-block.current').length).toBe(0);
|
2016-08-02 11:16:41 -04:00
|
|
|
});
|
2018-10-09 13:01:49 -04:00
|
|
|
|
2020-07-16 02:09:33 -04:00
|
|
|
it('should not remove emoji menu when search is clicked', async () => {
|
|
|
|
await openAndWaitForEmojiMenu();
|
2018-10-17 03:07:04 -04:00
|
|
|
|
2020-07-16 02:09:33 -04:00
|
|
|
const $emojiMenu = $('.emoji-menu');
|
|
|
|
$('.emoji-search').click();
|
|
|
|
|
|
|
|
expect($emojiMenu.length).toBe(1);
|
|
|
|
expect($emojiMenu.hasClass('is-visible')).toBe(true);
|
|
|
|
expect($('.js-awards-block.current').length).toBe(1);
|
2018-10-17 03:07:04 -04:00
|
|
|
});
|
|
|
|
});
|
2017-02-27 23:44:34 -05:00
|
|
|
|
2020-06-08 05:08:23 -04:00
|
|
|
describe('::addAwardToEmojiBar', () => {
|
|
|
|
it('should add emoji to votes block', () => {
|
2018-10-17 03:07:04 -04:00
|
|
|
const $votesBlock = $('.js-awards-block').eq(0);
|
|
|
|
awardsHandler.addAwardToEmojiBar($votesBlock, 'heart', false);
|
|
|
|
const $emojiButton = $votesBlock.find('[data-name=heart]');
|
2017-10-06 16:36:15 -04:00
|
|
|
|
2018-10-17 03:07:04 -04:00
|
|
|
expect($emojiButton.length).toBe(1);
|
|
|
|
expect($emojiButton.next('.js-counter').text()).toBe('1');
|
|
|
|
expect($votesBlock.hasClass('hidden')).toBe(false);
|
2016-07-24 16:45:11 -04:00
|
|
|
});
|
2018-10-09 13:01:49 -04:00
|
|
|
|
2020-06-08 05:08:23 -04:00
|
|
|
it('should remove the emoji when we click again', () => {
|
2018-10-17 03:07:04 -04:00
|
|
|
const $votesBlock = $('.js-awards-block').eq(0);
|
|
|
|
awardsHandler.addAwardToEmojiBar($votesBlock, 'heart', false);
|
|
|
|
awardsHandler.addAwardToEmojiBar($votesBlock, 'heart', false);
|
|
|
|
const $emojiButton = $votesBlock.find('[data-name=heart]');
|
2018-10-09 13:01:49 -04:00
|
|
|
|
2018-10-17 03:07:04 -04:00
|
|
|
expect($emojiButton.length).toBe(0);
|
|
|
|
});
|
2018-10-09 14:03:09 -04:00
|
|
|
|
2020-06-08 05:08:23 -04:00
|
|
|
it('should decrement the emoji counter', () => {
|
2018-10-17 03:07:04 -04:00
|
|
|
const $votesBlock = $('.js-awards-block').eq(0);
|
|
|
|
awardsHandler.addAwardToEmojiBar($votesBlock, 'heart', false);
|
|
|
|
const $emojiButton = $votesBlock.find('[data-name=heart]');
|
|
|
|
$emojiButton.next('.js-counter').text(5);
|
|
|
|
awardsHandler.addAwardToEmojiBar($votesBlock, 'heart', false);
|
2018-10-09 13:01:49 -04:00
|
|
|
|
2018-10-17 03:07:04 -04:00
|
|
|
expect($emojiButton.length).toBe(1);
|
|
|
|
expect($emojiButton.next('.js-counter').text()).toBe('4');
|
|
|
|
});
|
|
|
|
});
|
2018-10-09 13:01:49 -04:00
|
|
|
|
2020-06-08 05:08:23 -04:00
|
|
|
describe('::getAwardUrl', () => {
|
|
|
|
it('returns the url for request', () => {
|
2020-07-23 11:09:28 -04:00
|
|
|
expect(awardsHandler.getAwardUrl()).toBe('http://test.host/-/snippets/1/toggle_award_emoji');
|
2018-10-17 03:07:04 -04:00
|
|
|
});
|
|
|
|
});
|
2018-10-09 14:03:09 -04:00
|
|
|
|
2020-06-08 05:08:23 -04:00
|
|
|
describe('::addAward and ::checkMutuality', () => {
|
|
|
|
it('should handle :+1: and :-1: mutuality', () => {
|
2018-10-17 03:07:04 -04:00
|
|
|
const awardUrl = awardsHandler.getAwardUrl();
|
|
|
|
const $votesBlock = $('.js-awards-block').eq(0);
|
|
|
|
const $thumbsUpEmoji = $votesBlock.find('[data-name=thumbsup]').parent();
|
|
|
|
const $thumbsDownEmoji = $votesBlock.find('[data-name=thumbsdown]').parent();
|
|
|
|
awardsHandler.addAward($votesBlock, awardUrl, 'thumbsup', false);
|
|
|
|
|
|
|
|
expect($thumbsUpEmoji.hasClass('active')).toBe(true);
|
|
|
|
expect($thumbsDownEmoji.hasClass('active')).toBe(false);
|
|
|
|
awardsHandler.addAward($votesBlock, awardUrl, 'thumbsdown', true);
|
|
|
|
|
|
|
|
expect($thumbsUpEmoji.hasClass('active')).toBe(false);
|
|
|
|
expect($thumbsDownEmoji.hasClass('active')).toBe(true);
|
2016-07-24 16:45:11 -04:00
|
|
|
});
|
2018-10-17 03:07:04 -04:00
|
|
|
});
|
2018-10-09 13:01:49 -04:00
|
|
|
|
2020-06-08 05:08:23 -04:00
|
|
|
describe('::removeEmoji', () => {
|
|
|
|
it('should remove emoji', () => {
|
2018-10-17 03:07:04 -04:00
|
|
|
const awardUrl = awardsHandler.getAwardUrl();
|
|
|
|
const $votesBlock = $('.js-awards-block').eq(0);
|
|
|
|
awardsHandler.addAward($votesBlock, awardUrl, 'fire', false);
|
2018-10-09 13:01:49 -04:00
|
|
|
|
2018-10-17 03:07:04 -04:00
|
|
|
expect($votesBlock.find('[data-name=fire]').length).toBe(1);
|
|
|
|
awardsHandler.removeEmoji($votesBlock.find('[data-name=fire]').closest('button'));
|
|
|
|
|
|
|
|
expect($votesBlock.find('[data-name=fire]').length).toBe(0);
|
2016-09-08 06:08:09 -04:00
|
|
|
});
|
2018-10-17 03:07:04 -04:00
|
|
|
});
|
2018-10-09 13:01:49 -04:00
|
|
|
|
2020-06-08 05:08:23 -04:00
|
|
|
describe('::addYouToUserList', () => {
|
|
|
|
it('should prepend "You" to the award tooltip', () => {
|
2018-10-17 03:07:04 -04:00
|
|
|
const awardUrl = awardsHandler.getAwardUrl();
|
|
|
|
const $votesBlock = $('.js-awards-block').eq(0);
|
|
|
|
const $thumbsUpEmoji = $votesBlock.find('[data-name=thumbsup]').parent();
|
|
|
|
$thumbsUpEmoji.attr('data-title', 'sam, jerry, max, and andy');
|
|
|
|
awardsHandler.addAward($votesBlock, awardUrl, 'thumbsup', false);
|
2018-10-09 14:03:09 -04:00
|
|
|
|
2021-03-08 10:08:54 -05:00
|
|
|
expect($thumbsUpEmoji.attr('title')).toBe('You, sam, jerry, max, and andy');
|
2016-07-24 16:45:11 -04:00
|
|
|
});
|
2018-10-09 13:01:49 -04:00
|
|
|
|
2020-06-08 05:08:23 -04:00
|
|
|
it('handles the special case where "You" is not cleanly comma separated', () => {
|
2018-10-17 03:07:04 -04:00
|
|
|
const awardUrl = awardsHandler.getAwardUrl();
|
|
|
|
const $votesBlock = $('.js-awards-block').eq(0);
|
|
|
|
const $thumbsUpEmoji = $votesBlock.find('[data-name=thumbsup]').parent();
|
|
|
|
$thumbsUpEmoji.attr('data-title', 'sam');
|
|
|
|
awardsHandler.addAward($votesBlock, awardUrl, 'thumbsup', false);
|
|
|
|
|
2021-03-08 10:08:54 -05:00
|
|
|
expect($thumbsUpEmoji.attr('title')).toBe('You and sam');
|
2016-07-24 16:45:11 -04:00
|
|
|
});
|
2018-10-17 03:07:04 -04:00
|
|
|
});
|
2018-10-09 13:01:49 -04:00
|
|
|
|
2020-06-08 05:08:23 -04:00
|
|
|
describe('::removeYouToUserList', () => {
|
|
|
|
it('removes "You" from the front of the tooltip', () => {
|
2018-10-17 03:07:04 -04:00
|
|
|
const awardUrl = awardsHandler.getAwardUrl();
|
|
|
|
const $votesBlock = $('.js-awards-block').eq(0);
|
|
|
|
const $thumbsUpEmoji = $votesBlock.find('[data-name=thumbsup]').parent();
|
|
|
|
$thumbsUpEmoji.attr('data-title', 'You, sam, jerry, max, and andy');
|
|
|
|
$thumbsUpEmoji.addClass('active');
|
|
|
|
awardsHandler.addAward($votesBlock, awardUrl, 'thumbsup', false);
|
|
|
|
|
2021-03-08 10:08:54 -05:00
|
|
|
expect($thumbsUpEmoji.attr('title')).toBe('sam, jerry, max, and andy');
|
2018-10-17 03:07:04 -04:00
|
|
|
});
|
2018-10-09 14:03:09 -04:00
|
|
|
|
2020-06-08 05:08:23 -04:00
|
|
|
it('handles the special case where "You" is not cleanly comma separated', () => {
|
2018-10-17 03:07:04 -04:00
|
|
|
const awardUrl = awardsHandler.getAwardUrl();
|
|
|
|
const $votesBlock = $('.js-awards-block').eq(0);
|
|
|
|
const $thumbsUpEmoji = $votesBlock.find('[data-name=thumbsup]').parent();
|
|
|
|
$thumbsUpEmoji.attr('data-title', 'You and sam');
|
|
|
|
$thumbsUpEmoji.addClass('active');
|
|
|
|
awardsHandler.addAward($votesBlock, awardUrl, 'thumbsup', false);
|
2018-10-09 14:03:09 -04:00
|
|
|
|
2021-03-08 10:08:54 -05:00
|
|
|
expect($thumbsUpEmoji.attr('title')).toBe('sam');
|
2016-07-24 16:45:11 -04:00
|
|
|
});
|
2018-10-17 03:07:04 -04:00
|
|
|
});
|
2018-10-09 13:01:49 -04:00
|
|
|
|
2018-10-17 03:07:04 -04:00
|
|
|
describe('::searchEmojis', () => {
|
2020-07-16 02:09:33 -04:00
|
|
|
it('should filter the emoji', async () => {
|
|
|
|
await openAndWaitForEmojiMenu();
|
|
|
|
|
|
|
|
expect($('[data-name=angel]').is(':visible')).toBe(true);
|
|
|
|
expect($('[data-name=anger]').is(':visible')).toBe(true);
|
|
|
|
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);
|
|
|
|
expect($('.js-emoji-menu-search').val()).toBe('ali');
|
2016-06-19 19:06:57 -04:00
|
|
|
});
|
2018-10-09 13:01:49 -04:00
|
|
|
|
2020-07-16 02:09:33 -04:00
|
|
|
it('should clear the search when searching for nothing', async () => {
|
|
|
|
await openAndWaitForEmojiMenu();
|
|
|
|
|
|
|
|
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('');
|
2016-06-19 19:06:57 -04:00
|
|
|
});
|
2020-09-23 02:09:45 -04:00
|
|
|
|
2020-09-28 14:09:40 -04:00
|
|
|
it('should filter by emoji description', async () => {
|
|
|
|
await openAndWaitForEmojiMenu();
|
|
|
|
|
|
|
|
awardsHandler.searchEmojis('baby');
|
|
|
|
expect($('[data-name=angel]').is(':visible')).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should filter by emoji unicode value', async () => {
|
|
|
|
await openAndWaitForEmojiMenu();
|
|
|
|
|
|
|
|
awardsHandler.searchEmojis('👼');
|
|
|
|
expect($('[data-name=angel]').is(':visible')).toBe(true);
|
|
|
|
});
|
2022-06-10 11:09:22 -04:00
|
|
|
|
|
|
|
it('should show positive intent emoji first', async () => {
|
|
|
|
await openAndWaitForEmojiMenu();
|
|
|
|
|
|
|
|
awardsHandler.searchEmojis('thumb');
|
|
|
|
|
|
|
|
const $menu = $('.emoji-menu');
|
|
|
|
const $thumbsUpItem = $menu.find('[data-name=thumbsup]');
|
|
|
|
const $thumbsDownItem = $menu.find('[data-name=thumbsdown]');
|
|
|
|
|
|
|
|
expect($thumbsUpItem.is(':visible')).toBe(true);
|
|
|
|
expect($thumbsDownItem.is(':visible')).toBe(true);
|
|
|
|
|
|
|
|
expect($thumbsUpItem.parents('.emoji-menu-list-item').index()).toBeLessThan(
|
|
|
|
$thumbsDownItem.parents('.emoji-menu-list-item').index(),
|
|
|
|
);
|
|
|
|
});
|
2018-10-17 03:07:04 -04:00
|
|
|
});
|
2018-10-09 13:01:49 -04:00
|
|
|
|
2020-06-08 05:08:23 -04:00
|
|
|
describe('emoji menu', () => {
|
2018-10-17 03:07:04 -04:00
|
|
|
const emojiSelector = '[data-name="sunglasses"]';
|
2020-07-16 02:09:33 -04:00
|
|
|
|
2020-06-08 05:08:23 -04:00
|
|
|
const openEmojiMenuAndAddEmoji = () => {
|
2018-10-17 03:07:04 -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}`);
|
2018-10-09 13:01:49 -04:00
|
|
|
|
2018-10-17 03:07:04 -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
|
|
|
});
|
2018-10-17 03:07:04 -04:00
|
|
|
};
|
|
|
|
|
2020-07-16 02:09:33 -04:00
|
|
|
it('should add selected emoji to awards block', async () => {
|
|
|
|
await openEmojiMenuAndAddEmoji();
|
2016-07-24 16:45:11 -04:00
|
|
|
});
|
2017-04-07 01:28:30 -04:00
|
|
|
|
2020-07-16 02:09:33 -04:00
|
|
|
it('should remove already selected emoji', async () => {
|
|
|
|
await openEmojiMenuAndAddEmoji();
|
|
|
|
|
2020-12-23 07:10:26 -05:00
|
|
|
$('.js-add-award').eq(0).click();
|
2020-07-16 02:09:33 -04:00
|
|
|
const $block = $('.js-awards-block');
|
|
|
|
const $emoji = $('.emoji-menu').find(
|
|
|
|
`.emoji-menu-list:not(.frequent-emojis) ${emojiSelector}`,
|
|
|
|
);
|
|
|
|
$emoji.click();
|
|
|
|
|
|
|
|
expect($block.find(emojiSelector).length).toBe(0);
|
2018-10-17 03:07:04 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-06-08 05:08:23 -04:00
|
|
|
describe('frequently used emojis', () => {
|
2018-10-17 03:07:04 -04:00
|
|
|
beforeEach(() => {
|
|
|
|
// Clear it out
|
|
|
|
Cookies.set('frequently_used_emojis', '');
|
|
|
|
});
|
2018-10-09 13:01:49 -04:00
|
|
|
|
2020-07-16 02:09:33 -04:00
|
|
|
it('shouldn\'t have any "Frequently used" heading if no frequently used emojis', async () => {
|
|
|
|
await openAndWaitForEmojiMenu();
|
|
|
|
|
|
|
|
const emojiMenu = document.querySelector('.emoji-menu');
|
2020-12-23 16:10:24 -05:00
|
|
|
Array.prototype.forEach.call(emojiMenu.querySelectorAll('.emoji-menu-title'), (title) => {
|
2020-07-16 02:09:33 -04:00
|
|
|
expect(title.textContent.trim().toLowerCase()).not.toBe('frequently used');
|
|
|
|
});
|
2017-03-09 12:55:18 -05:00
|
|
|
});
|
|
|
|
|
2020-07-16 02:09:33 -04:00
|
|
|
it('should have any frequently used section when there are frequently used emojis', async () => {
|
2018-10-17 03:07:04 -04:00
|
|
|
awardsHandler.addEmojiToFrequentlyUsedList('8ball');
|
2017-03-09 12:55:18 -05:00
|
|
|
|
2020-07-16 02:09:33 -04:00
|
|
|
await openAndWaitForEmojiMenu();
|
|
|
|
|
|
|
|
const emojiMenu = document.querySelector('.emoji-menu');
|
|
|
|
const hasFrequentlyUsedHeading = Array.prototype.some.call(
|
|
|
|
emojiMenu.querySelectorAll('.emoji-menu-title'),
|
2020-12-23 16:10:24 -05:00
|
|
|
(title) => title.textContent.trim().toLowerCase() === 'frequently used',
|
2020-07-16 02:09:33 -04:00
|
|
|
);
|
|
|
|
|
|
|
|
expect(hasFrequentlyUsedHeading).toBe(true);
|
2018-10-17 03:07:04 -04:00
|
|
|
});
|
2017-03-16 15:37:25 -04:00
|
|
|
|
2020-06-08 05:08:23 -04:00
|
|
|
it('should disregard invalid frequently used emoji that are being attempted to be added', () => {
|
2018-10-17 03:07:04 -04:00
|
|
|
awardsHandler.addEmojiToFrequentlyUsedList('8ball');
|
|
|
|
awardsHandler.addEmojiToFrequentlyUsedList('invalid_emoji');
|
|
|
|
awardsHandler.addEmojiToFrequentlyUsedList('grinning');
|
2017-03-16 15:37:25 -04:00
|
|
|
|
2018-10-17 03:07:04 -04:00
|
|
|
expect(awardsHandler.getFrequentlyUsedEmojis()).toEqual(['8ball', 'grinning']);
|
|
|
|
});
|
2017-03-16 15:37:25 -04:00
|
|
|
|
2020-06-08 05:08:23 -04:00
|
|
|
it('should disregard invalid frequently used emoji already set in cookie', () => {
|
2018-10-17 03:07:04 -04:00
|
|
|
Cookies.set('frequently_used_emojis', '8ball,invalid_emoji,grinning');
|
2017-03-16 15:37:25 -04:00
|
|
|
|
2018-10-17 03:07:04 -04:00
|
|
|
expect(awardsHandler.getFrequentlyUsedEmojis()).toEqual(['8ball', 'grinning']);
|
2016-07-24 16:45:11 -04:00
|
|
|
});
|
|
|
|
});
|
2018-10-17 03:07:04 -04:00
|
|
|
});
|