{"size": 3911, "ext": "js", "max_stars_repo_path": "vue-element-admin/node_modules/tui-chart/test/models/scaleData/scaleLabelFormatter.spec.js", "max_stars_repo_name": "jiangjianli/qianyueweb", "max_stars_repo_stars_event_min_datetime": "2019-04-11T10:15:42.000Z", "max_stars_repo_stars_event_max_datetime": "2019-06-18T06:08:41.000Z", "max_issues_repo_path": "vue-element-admin/node_modules/tui-chart/test/models/scaleData/scaleLabelFormatter.spec.js", "max_issues_repo_name": "jiangjianli/qianyueweb", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "vue-element-admin/node_modules/tui-chart/test/models/scaleData/scaleLabelFormatter.spec.js", "max_forks_repo_name": "jiangjianli/qianyueweb", "max_forks_repo_forks_event_min_datetime": "2020-12-04T14:31:43.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-04T14:31:43.000Z"}
{"max_stars_count": 3, "max_issues_count": null, "max_forks_count": 1, "avg_line_length": 34.9196428571, "max_line_length": 115, "alphanum_fraction": 0.5320889798}
/**
 * @fileoverview Test for scaleLabelFormatter.
 * @author NHN Ent.
 *         FE Development Lab <dl_javascript@nhnent.com>
 */
import scaleLabelFormatter from '../../../src/js/models/scaleData/scaleLabelFormatter.js';
import chartConst from '../../../src/js/const';

describe('Test for scaleLabelFormatter', () => {
    describe('_getFormatFunctions()', () => {
        it('get format functions, when is percent stacked chart', () => {
            const chartType = 'bar';
            const stackType = 'percent';

            scaleLabelFormatter.chartType = chartConst.CHART_TYPE_BAR;
            scaleLabelFormatter.stackType = chartConst.PERCENT_STACK_TYPE;
            const actual = scaleLabelFormatter._getFormatFunctions(chartType, stackType);
            const expected = '10%';

            expect(actual[0](10)).toBe(expected);
        });

        it('get format functions, when is not percent stacked chart', () => {
            const chartType = chartConst.CHART_TYPE_LINE;
            const stackType = '';
            const formatFunctions = 'formatFunctions';

            const actual = scaleLabelFormatter._getFormatFunctions(chartType, stackType, formatFunctions);

            expect(actual).toBe('formatFunctions');
        });
    });

    describe('_createScaleValues()', () => {
        it('create scale values, when is diverging chart', () => {
            const scaleData = {
                limit: {
                    min: -50,
                    max: 50
                },
                step: 25
            };
            const chartType = chartConst.CHART_TYPE_BAR;
            const diverging = true;
            const actual = scaleLabelFormatter._createScaleValues(scaleData, chartType, diverging);
            const expected = [50, 25, 0, 25, 50];

            expect(actual).toEqual(expected);
        });

        it('create scale values, when is not diverging chart', () => {
            const scaleData = {
                limit: {
                    min: -50,
                    max: 50
                },
                step: 25
            };
            const chartType = chartConst.CHART_TYPE_LINE;
            const diverging = false;
            const actual = scaleLabelFormatter._createScaleValues(scaleData, chartType, diverging);
            const expected = [-50, -25, 0, 25, 50];

            expect(actual).toEqual(expected);
        });
    });

    describe('createFormattedLabels()', () => {
        it('create formatted scale values, when axis type is datetime', () => {
            const scaleData = {};
            const typeMap = {};
            const options = {
                type: chartConst.AXIS_TYPE_DATETIME,
                dateFormat: 'YYYY.MM'
            };

            spyOn(scaleLabelFormatter, '_createScaleValues').and.returnValue([
                (new Date('01/01/2016')),
                (new Date('04/01/2016')),
                (new Date('08/01/2016'))
            ]);

            const actual = scaleLabelFormatter.createFormattedLabels(scaleData, typeMap, options);

            expect(actual).toEqual([
                '2016.01',
                '2016.04',
                '2016.08'
            ]);
        });

        it('create formatted scale values, when axis type is not datetime', () => {
            const scaleData = {};
            const typeMap = {
                chartType: chartConst.CHART_TYPE_LINE
            };
            const options = {};
            const formatFunctions = [value => `formatted:${value}`];

            spyOn(scaleLabelFormatter, '_createScaleValues').and.returnValue([10, 20, 30]);

            const actual = scaleLabelFormatter.createFormattedLabels(scaleData, typeMap, options, formatFunctions);

            expect(actual).toEqual([
                'formatted:10',
                'formatted:20',
                'formatted:30'
            ]);
        });
    });
});
