summaryrefslogtreecommitdiff
path: root/spec/frontend/emoji/components/utils_spec.js
blob: 03eeb6b6bf73d65ffaca1fbcae1b10c320f00f66 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
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,
      secure: false,
    });
  });

  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,
      secure: false,
    });
  });

  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,
      secure: false,
    });
  });
});