Welcome to mirror list, hosted at ThFree Co, Russian Federation.

utils_spec.js « gitlab_version_check « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6126d88dfec6ac2d6ed86003ab9a7b5288b4bdf7 (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
import { parseBoolean, getCookie, setCookie } from '~/lib/utils/common_utils';
import { getHideAlertModalCookie, setHideAlertModalCookie } from '~/gitlab_version_check/utils';
import { COOKIE_EXPIRATION, COOKIE_SUFFIX } from '~/gitlab_version_check/constants';

jest.mock('~/lib/utils/common_utils', () => ({
  parseBoolean: jest.fn().mockReturnValue(true),
  getCookie: jest.fn().mockReturnValue('true'),
  setCookie: jest.fn(),
}));

describe('GitLab Version Check Utils', () => {
  describe('setHideAlertModalCookie', () => {
    it('properly generates a key based on the currentVersion and sets Cookie to `true`', () => {
      const currentVersion = '99.9.9';

      setHideAlertModalCookie(currentVersion);

      expect(setCookie).toHaveBeenCalledWith(`${currentVersion}${COOKIE_SUFFIX}`, true, {
        expires: COOKIE_EXPIRATION,
      });
    });
  });

  describe('getHideAlertModalCookie', () => {
    it('properly generates a key based on the currentVersion, fetches said Cooke, and parsesBoolean it', () => {
      const currentVersion = '99.9.9';

      const res = getHideAlertModalCookie(currentVersion);

      expect(getCookie).toHaveBeenCalledWith(`${currentVersion}${COOKIE_SUFFIX}`);
      expect(parseBoolean).toHaveBeenCalledWith('true');
      expect(res).toBe(true);
    });
  });
});