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

icon_utils_spec.js « utils « lib « javascripts « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 3fd3940efe8677dae6832157b1f68a7877b3ad31 (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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
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;
    let getIcon;
    const mockName = 'mockIconName';
    const mockPath = 'mockPath';

    beforeEach(() => {
      axiosMock = new MockAdapter(axios);
      mockEndpoint = axiosMock.onGet(gon.sprite_icons);
      getIcon = iconUtils.getSvgIconPathContent(mockName);
    });

    afterEach(() => {
      axiosMock.restore();
    });

    it('extracts svg icon path content from sprite icons', done => {
      mockEndpoint.replyOnce(
        200,
        `<svg><symbol id="${mockName}"><path d="${mockPath}"/></symbol></svg>`,
      );
      getIcon
        .then(path => {
          expect(path).toBe(mockPath);
          done();
        })
        .catch(done.fail);
    });

    it('returns null if icon path content does not exist', done => {
      mockEndpoint.replyOnce(200, ``);
      getIcon
        .then(path => {
          expect(path).toBe(null);
          done();
        })
        .catch(done.fail);
    });

    it('returns null if an http error occurs', done => {
      mockEndpoint.replyOnce(500);
      getIcon
        .then(path => {
          expect(path).toBe(null);
          done();
        })
        .catch(done.fail);
    });
  });
});