debian-mirror-gitlab/spec/frontend/emoji/support/unicode_support_map_spec.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

53 lines
1.9 KiB
JavaScript
Raw Normal View History

2020-10-24 23:57:45 +05:30
import { useLocalStorageSpy } from 'helpers/local_storage_helper';
2017-09-10 17:25:29 +05:30
import getUnicodeSupportMap from '~/emoji/support/unicode_support_map';
2017-08-17 22:00:37 +05:30
import AccessorUtilities from '~/lib/utils/accessor';
describe('Unicode Support Map', () => {
2020-06-23 00:09:42 +05:30
useLocalStorageSpy();
2017-08-17 22:00:37 +05:30
describe('getUnicodeSupportMap', () => {
const stringSupportMap = 'stringSupportMap';
beforeEach(() => {
2021-11-11 11:23:49 +05:30
jest.spyOn(AccessorUtilities, 'canUseLocalStorage').mockImplementation(() => {});
2020-06-23 00:09:42 +05:30
jest.spyOn(JSON, 'parse').mockImplementation(() => {});
jest.spyOn(JSON, 'stringify').mockReturnValue(stringSupportMap);
2017-08-17 22:00:37 +05:30
});
2020-06-23 00:09:42 +05:30
describe('if isLocalStorageAvailable is `true`', () => {
2017-08-17 22:00:37 +05:30
beforeEach(() => {
2021-11-11 11:23:49 +05:30
jest.spyOn(AccessorUtilities, 'canUseLocalStorage').mockReturnValue(true);
2017-08-17 22:00:37 +05:30
getUnicodeSupportMap();
});
it('should call .getItem and .setItem', () => {
2020-06-23 00:09:42 +05:30
const getArgs = window.localStorage.getItem.mock.calls;
const setArgs = window.localStorage.setItem.mock.calls;
2018-03-17 18:26:18 +05:30
expect(getArgs[0][0]).toBe('gl-emoji-version');
expect(getArgs[1][0]).toBe('gl-emoji-user-agent');
expect(setArgs[0][0]).toBe('gl-emoji-version');
expect(setArgs[0][1]).toBe('0.2.0');
expect(setArgs[1][0]).toBe('gl-emoji-user-agent');
expect(setArgs[1][1]).toBe(navigator.userAgent);
expect(setArgs[2][0]).toBe('gl-emoji-unicode-support-map');
expect(setArgs[2][1]).toBe(stringSupportMap);
2017-08-17 22:00:37 +05:30
});
});
2020-06-23 00:09:42 +05:30
describe('if isLocalStorageAvailable is `false`', () => {
2017-08-17 22:00:37 +05:30
beforeEach(() => {
2021-11-11 11:23:49 +05:30
jest.spyOn(AccessorUtilities, 'canUseLocalStorage').mockReturnValue(false);
2017-08-17 22:00:37 +05:30
getUnicodeSupportMap();
});
it('should not call .getItem or .setItem', () => {
2020-06-23 00:09:42 +05:30
expect(window.localStorage.getItem.mock.calls.length).toBe(1);
2017-08-17 22:00:37 +05:30
expect(window.localStorage.setItem).not.toHaveBeenCalled();
});
});
});
});