diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-04-01 18:14:27 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-04-01 18:14:27 +0300 |
commit | afbaf78b0d819326741a01b093bdbc4702570417 (patch) | |
tree | a16a6f2a8fcc18e60f25ac72df6ab22cfe0eae79 /spec/frontend/emoji | |
parent | 38b3003b67db3f2eadfa81fd28b13d168f665766 (diff) |
Add latest changes from gitlab-org/gitlab@13-10-stable-ee
Diffstat (limited to 'spec/frontend/emoji')
-rw-r--r-- | spec/frontend/emoji/components/utils_spec.js | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/spec/frontend/emoji/components/utils_spec.js b/spec/frontend/emoji/components/utils_spec.js new file mode 100644 index 00000000000..36521eb1051 --- /dev/null +++ b/spec/frontend/emoji/components/utils_spec.js @@ -0,0 +1,56 @@ +import Cookies from 'js-cookie'; +import { getFrequentlyUsedEmojis, addToFrequentlyUsed } from '~/emoji/components/utils'; + +jest.mock('js-cookie'); + +describe('getFrequentlyUsedEmojis', () => { + it('it returns null when no saved emojis set', () => { + jest.spyOn(Cookies, 'get').mockReturnValue(null); + + expect(getFrequentlyUsedEmojis()).toBe(null); + }); + + it('it returns frequently used emojis object', () => { + 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, + }); + }); + + 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, + }); + }); + + 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, + }); + }); +}); |