summaryrefslogtreecommitdiff
path: root/spec/frontend/lib/utils
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-03-17 09:09:20 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-03-17 09:09:20 +0000
commitfc1df8c8307fc5022f9e8aae04164c089d8fdf2e (patch)
treea759f58abf9e41200c48a60de73c84cab47a250d /spec/frontend/lib/utils
parentc8df22c555ab707a705e57c4257fd3ed1ce7c3b0 (diff)
downloadgitlab-ce-fc1df8c8307fc5022f9e8aae04164c089d8fdf2e.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/lib/utils')
-rw-r--r--spec/frontend/lib/utils/icon_utils_spec.js72
1 files changed, 47 insertions, 25 deletions
diff --git a/spec/frontend/lib/utils/icon_utils_spec.js b/spec/frontend/lib/utils/icon_utils_spec.js
index 816d634ad15..f798dc6744d 100644
--- a/spec/frontend/lib/utils/icon_utils_spec.js
+++ b/spec/frontend/lib/utils/icon_utils_spec.js
@@ -1,10 +1,14 @@
import MockAdapter from 'axios-mock-adapter';
import axios from '~/lib/utils/axios_utils';
-import * as iconUtils from '~/lib/utils/icon_utils';
+import { clearSvgIconPathContentCache, getSvgIconPathContent } from '~/lib/utils/icon_utils';
describe('Icon utils', () => {
describe('getSvgIconPathContent', () => {
let spriteIcons;
+ let axiosMock;
+ const mockName = 'mockIconName';
+ const mockPath = 'mockPath';
+ const mockIcons = `<svg><symbol id="${mockName}"><path d="${mockPath}"/></symbol></svg>`;
beforeAll(() => {
spriteIcons = gon.sprite_icons;
@@ -15,45 +19,63 @@ describe('Icon utils', () => {
gon.sprite_icons = spriteIcons;
});
- let axiosMock;
- let mockEndpoint;
- const mockName = 'mockIconName';
- const mockPath = 'mockPath';
- const getIcon = () => iconUtils.getSvgIconPathContent(mockName);
-
beforeEach(() => {
axiosMock = new MockAdapter(axios);
- mockEndpoint = axiosMock.onGet(gon.sprite_icons);
});
afterEach(() => {
axiosMock.restore();
+ clearSvgIconPathContentCache();
});
- it('extracts svg icon path content from sprite icons', () => {
- mockEndpoint.replyOnce(
- 200,
- `<svg><symbol id="${mockName}"><path d="${mockPath}"/></symbol></svg>`,
- );
-
- return getIcon().then(path => {
- expect(path).toBe(mockPath);
+ describe('when the icons can be loaded', () => {
+ beforeEach(() => {
+ axiosMock.onGet(gon.sprite_icons).reply(200, mockIcons);
});
- });
- it('returns null if icon path content does not exist', () => {
- mockEndpoint.replyOnce(200, ``);
+ it('extracts svg icon path content from sprite icons', () => {
+ return getSvgIconPathContent(mockName).then(path => {
+ expect(path).toBe(mockPath);
+ });
+ });
- return getIcon().then(path => {
- expect(path).toBe(null);
+ it('returns null if icon path content does not exist', () => {
+ return getSvgIconPathContent('missing-icon').then(path => {
+ expect(path).toBe(null);
+ });
});
});
- it('returns null if an http error occurs', () => {
- mockEndpoint.replyOnce(500);
+ describe('when the icons cannot be loaded on the first 2 tries', () => {
+ beforeEach(() => {
+ axiosMock
+ .onGet(gon.sprite_icons)
+ .replyOnce(500)
+ .onGet(gon.sprite_icons)
+ .replyOnce(500)
+ .onGet(gon.sprite_icons)
+ .reply(200, mockIcons);
+ });
+
+ it('returns null', () => {
+ return getSvgIconPathContent(mockName).then(path => {
+ expect(path).toBe(null);
+ });
+ });
- return getIcon().then(path => {
- expect(path).toBe(null);
+ it('extracts svg icon path content, after 2 attempts', () => {
+ return getSvgIconPathContent(mockName)
+ .then(path1 => {
+ expect(path1).toBe(null);
+ return getSvgIconPathContent(mockName);
+ })
+ .then(path2 => {
+ expect(path2).toBe(null);
+ return getSvgIconPathContent(mockName);
+ })
+ .then(path3 => {
+ expect(path3).toBe(mockPath);
+ });
});
});
});