2019-03-02 22:35:43 +05:30
|
|
|
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';
|
2020-01-01 13:55:28 +05:30
|
|
|
const getIcon = () => iconUtils.getSvgIconPathContent(mockName);
|
2019-03-02 22:35:43 +05:30
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
axiosMock = new MockAdapter(axios);
|
|
|
|
mockEndpoint = axiosMock.onGet(gon.sprite_icons);
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
axiosMock.restore();
|
|
|
|
});
|
|
|
|
|
2020-01-01 13:55:28 +05:30
|
|
|
it('extracts svg icon path content from sprite icons', () => {
|
2019-03-02 22:35:43 +05:30
|
|
|
mockEndpoint.replyOnce(
|
|
|
|
200,
|
|
|
|
`<svg><symbol id="${mockName}"><path d="${mockPath}"/></symbol></svg>`,
|
|
|
|
);
|
2020-01-01 13:55:28 +05:30
|
|
|
|
|
|
|
return getIcon().then(path => {
|
|
|
|
expect(path).toBe(mockPath);
|
|
|
|
});
|
2019-03-02 22:35:43 +05:30
|
|
|
});
|
|
|
|
|
2020-01-01 13:55:28 +05:30
|
|
|
it('returns null if icon path content does not exist', () => {
|
2019-03-02 22:35:43 +05:30
|
|
|
mockEndpoint.replyOnce(200, ``);
|
2020-01-01 13:55:28 +05:30
|
|
|
|
|
|
|
return getIcon().then(path => {
|
|
|
|
expect(path).toBe(null);
|
|
|
|
});
|
2019-03-02 22:35:43 +05:30
|
|
|
});
|
|
|
|
|
2020-01-01 13:55:28 +05:30
|
|
|
it('returns null if an http error occurs', () => {
|
2019-03-02 22:35:43 +05:30
|
|
|
mockEndpoint.replyOnce(500);
|
2020-01-01 13:55:28 +05:30
|
|
|
|
|
|
|
return getIcon().then(path => {
|
|
|
|
expect(path).toBe(null);
|
|
|
|
});
|
2019-03-02 22:35:43 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|