debian-mirror-gitlab/spec/frontend/lib/utils/chart_utils_spec.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

69 lines
1.9 KiB
JavaScript
Raw Normal View History

2023-06-20 00:43:36 +05:30
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');
2019-12-26 22:10:19 +05:30
describe('Chart utils', () => {
describe('firstAndLastY', () => {
it('returns the first and last y-values of a given data set as an array', () => {
2021-03-08 18:12:59 +05:30
const data = [
['', 1],
['', 2],
['', 3],
];
2019-12-26 22:10:19 +05:30
expect(firstAndLastY(data)).toEqual([1, 3]);
});
});
2023-06-20 00:43:36 +05:30
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,
);
});
});
});
2019-12-26 22:10:19 +05:30
});