debian-mirror-gitlab/spec/frontend/emoji/components/utils_spec.js

60 lines
1.6 KiB
JavaScript
Raw Normal View History

2022-07-16 23:28:13 +05:30
import Cookies from '~/lib/utils/cookies';
2021-04-17 20:07:23 +05:30
import { getFrequentlyUsedEmojis, addToFrequentlyUsed } from '~/emoji/components/utils';
2022-07-16 23:28:13 +05:30
jest.mock('~/lib/utils/cookies');
2021-04-17 20:07:23 +05:30
describe('getFrequentlyUsedEmojis', () => {
2022-10-11 01:57:18 +05:30
it('returns null when no saved emojis set', () => {
2021-04-17 20:07:23 +05:30
jest.spyOn(Cookies, 'get').mockReturnValue(null);
expect(getFrequentlyUsedEmojis()).toBe(null);
});
2022-10-11 01:57:18 +05:30
it('returns frequently used emojis object', () => {
2021-04-17 20:07:23 +05:30
jest.spyOn(Cookies, 'get').mockReturnValue('thumbsup,thumbsdown');
expect(getFrequentlyUsedEmojis()).toEqual({
frequently_used: {
emojis: [['thumbsup', 'thumbsdown']],
top: 0,
height: 71,
},
});
});
});
describe('addToFrequentlyUsed', () => {
it('sets cookie value', () => {
jest.spyOn(Cookies, 'get').mockReturnValue(null);
addToFrequentlyUsed('thumbsup');
expect(Cookies.set).toHaveBeenCalledWith('frequently_used_emojis', 'thumbsup', {
expires: 365,
2022-04-04 11:22:00 +05:30
secure: false,
2021-04-17 20:07:23 +05:30
});
});
it('sets cookie value to include previously set cookie value', () => {
jest.spyOn(Cookies, 'get').mockReturnValue('thumbsdown');
addToFrequentlyUsed('thumbsup');
expect(Cookies.set).toHaveBeenCalledWith('frequently_used_emojis', 'thumbsdown,thumbsup', {
expires: 365,
2022-04-04 11:22:00 +05:30
secure: false,
2021-04-17 20:07:23 +05:30
});
});
it('sets cookie value with uniq values', () => {
jest.spyOn(Cookies, 'get').mockReturnValue('thumbsup');
addToFrequentlyUsed('thumbsup');
expect(Cookies.set).toHaveBeenCalledWith('frequently_used_emojis', 'thumbsup', {
expires: 365,
2022-04-04 11:22:00 +05:30
secure: false,
2021-04-17 20:07:23 +05:30
});
});
});