2019-01-23 19:06:02 -05:00
|
|
|
import MockAdapter from 'axios-mock-adapter';
|
|
|
|
import axios from '~/lib/utils/axios_utils';
|
|
|
|
import * as iconUtils from '~/lib/utils/icon_utils';
|
|
|
|
|
|
|
|
describe('Icon utils', () => {
|
|
|
|
describe('getSvgIconPathContent', () => {
|
|
|
|
let spriteIcons;
|
|
|
|
|
|
|
|
beforeAll(() => {
|
|
|
|
spriteIcons = gon.sprite_icons;
|
|
|
|
gon.sprite_icons = 'mockSpriteIconsEndpoint';
|
|
|
|
});
|
|
|
|
|
|
|
|
afterAll(() => {
|
|
|
|
gon.sprite_icons = spriteIcons;
|
|
|
|
});
|
|
|
|
|
|
|
|
let axiosMock;
|
|
|
|
let mockEndpoint;
|
|
|
|
const mockName = 'mockIconName';
|
|
|
|
const mockPath = 'mockPath';
|
2019-12-02 19:06:28 -05:00
|
|
|
const getIcon = () => iconUtils.getSvgIconPathContent(mockName);
|
2019-01-23 19:06:02 -05:00
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
axiosMock = new MockAdapter(axios);
|
|
|
|
mockEndpoint = axiosMock.onGet(gon.sprite_icons);
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
axiosMock.restore();
|
|
|
|
});
|
|
|
|
|
2019-12-02 19:06:28 -05:00
|
|
|
it('extracts svg icon path content from sprite icons', () => {
|
2019-01-23 19:06:02 -05:00
|
|
|
mockEndpoint.replyOnce(
|
|
|
|
200,
|
|
|
|
`<svg><symbol id="${mockName}"><path d="${mockPath}"/></symbol></svg>`,
|
|
|
|
);
|
2019-12-02 19:06:28 -05:00
|
|
|
|
|
|
|
return getIcon().then(path => {
|
|
|
|
expect(path).toBe(mockPath);
|
|
|
|
});
|
2019-01-23 19:06:02 -05:00
|
|
|
});
|
|
|
|
|
2019-12-02 19:06:28 -05:00
|
|
|
it('returns null if icon path content does not exist', () => {
|
2019-01-23 19:06:02 -05:00
|
|
|
mockEndpoint.replyOnce(200, ``);
|
2019-12-02 19:06:28 -05:00
|
|
|
|
|
|
|
return getIcon().then(path => {
|
|
|
|
expect(path).toBe(null);
|
|
|
|
});
|
2019-01-23 19:06:02 -05:00
|
|
|
});
|
|
|
|
|
2019-12-02 19:06:28 -05:00
|
|
|
it('returns null if an http error occurs', () => {
|
2019-01-23 19:06:02 -05:00
|
|
|
mockEndpoint.replyOnce(500);
|
2019-12-02 19:06:28 -05:00
|
|
|
|
|
|
|
return getIcon().then(path => {
|
|
|
|
expect(path).toBe(null);
|
|
|
|
});
|
2019-01-23 19:06:02 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|