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

chart_utils_spec.js « utils « lib « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 3b34b0ef672cde8fb747e7f6655d89ef85f08039 (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
68
import { firstAndLastY, getToolboxOptions } from '~/lib/utils/chart_utils';
import { __ } from '~/locale';
import * as iconUtils from '~/lib/utils/icon_utils';

jest.mock('~/lib/utils/icon_utils');

describe('Chart utils', () => {
  describe('firstAndLastY', () => {
    it('returns the first and last y-values of a given data set as an array', () => {
      const data = [
        ['', 1],
        ['', 2],
        ['', 3],
      ];

      expect(firstAndLastY(data)).toEqual([1, 3]);
    });
  });

  describe('getToolboxOptions', () => {
    describe('when icons are successfully fetched', () => {
      beforeEach(() => {
        iconUtils.getSvgIconPathContent.mockImplementation((name) =>
          Promise.resolve(`${name}-svg-path-mock`),
        );
      });

      it('returns toolbox config', async () => {
        await expect(getToolboxOptions()).resolves.toEqual({
          toolbox: {
            feature: {
              dataZoom: {
                icon: {
                  zoom: 'path://marquee-selection-svg-path-mock',
                  back: 'path://redo-svg-path-mock',
                },
              },
              restore: {
                icon: 'path://repeat-svg-path-mock',
              },
              saveAsImage: {
                icon: 'path://download-svg-path-mock',
              },
            },
          },
        });
      });
    });

    describe('when icons are not successfully fetched', () => {
      const error = new Error();

      beforeEach(() => {
        iconUtils.getSvgIconPathContent.mockRejectedValue(error);
        jest.spyOn(console, 'warn').mockImplementation();
      });

      it('returns empty object and calls `console.warn`', async () => {
        await expect(getToolboxOptions()).resolves.toEqual({});
        // eslint-disable-next-line no-console
        expect(console.warn).toHaveBeenCalledWith(
          __('SVG could not be rendered correctly: '),
          error,
        );
      });
    });
  });
});