@datarailsshared/dr_renderer 1.2.322-dragons → 1.2.324

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,6 +2,10 @@ import * as JQuery from "jquery";
2
2
  import * as lodash from 'lodash';
3
3
  import moment from 'moment/min/moment.min';
4
4
  import tables from './mock/tables.json';
5
+ import addInTables from './mock/add-in-tables.json';
6
+ import addInFunctions from './mock/add-in-functions.json';
7
+ import addInDynamicRanges from './mock/add-in-dynamic-ranges.json';
8
+ import widgets from './mock/widgets.json';
5
9
  import initPivotTable from "../src/pivottable";
6
10
  import initDRPivotTable from "../src/dr_pivottable";
7
11
 
@@ -483,6 +487,7 @@ describe('highcharts_renderer', () => {
483
487
  let opts;
484
488
 
485
489
  beforeEach(() => {
490
+ highchartsRenderer.enabledNewWidgetValueFormatting = false;
486
491
  funcContext = { y: '12345.678' };
487
492
  opts = {}
488
493
  });
@@ -1563,6 +1568,228 @@ describe('highcharts_renderer', () => {
1563
1568
  });
1564
1569
  });
1565
1570
 
1571
+ describe('function addTemplateDataToExTableOptions', () => {
1572
+ it('should fill pivot options', () => {
1573
+ const addInTable = lodash.cloneDeep(addInTables[0]);
1574
+ const template = lodash.cloneDeep(lodash.find(tables, { id: addInTable.template_id }));
1575
+ const uniqFields = lodash.uniqBy(lodash.concat(addInTable.fields, addInTable.filters), 'name');
1576
+ const filtersWithoutFields = lodash.differenceBy(addInTable.filters, addInTable.fields, 'name');
1577
+
1578
+ highchartsRenderer.addTemplateDataToExTableOptions(template, addInTable);
1579
+ expect(addInTable.pivot).toBeTruthy();
1580
+ expect(addInTable.pivot.fieldsArray.length).toBe(template.fields.length - uniqFields.length);
1581
+ expect(addInTable.pivot.selectedFieldsArray.length).toBe(addInTable.fields.length);
1582
+ expect(addInTable.pivot.filtersArray.length).toBe(filtersWithoutFields.length);
1583
+ expect(addInTable.pivot.calculatedValues.length).toBe(0);
1584
+ });
1585
+ });
1586
+
1587
+ describe('function addTemplateDataToDynamicRangeOptions', () => {
1588
+ it('should fill pivot options', () => {
1589
+ const dynamicRange = lodash.cloneDeep(addInDynamicRanges[0]);
1590
+ const template = lodash.cloneDeep(lodash.find(tables, { id: dynamicRange.table_id }));
1591
+ const uniqFields = lodash.uniqBy(lodash.concat(dynamicRange.fields, dynamicRange.filters), 'name');
1592
+ const filtersWithoutFields = lodash.differenceBy(dynamicRange.filters, dynamicRange.fields, 'name');
1593
+
1594
+ highchartsRenderer.addTemplateDataToDynamicRangeOptions(template, dynamicRange);
1595
+ expect(dynamicRange.pivot).toBeTruthy();
1596
+ expect(dynamicRange.pivot.fieldsArray.length).toBe(template.fields.length - uniqFields.length);
1597
+ expect(dynamicRange.pivot.selectedFieldsArray.length).toBe(dynamicRange.fields.length);
1598
+ expect(dynamicRange.pivot.filtersArray.length).toBe(filtersWithoutFields.length);
1599
+ expect(dynamicRange.pivot.calculatedValues.length).toBe(0);
1600
+ });
1601
+ });
1602
+
1603
+ describe('function addTemplateDataToFunctionOptions', () => {
1604
+ it('should fill pivot options', () => {
1605
+ const addInFunction = lodash.cloneDeep(addInFunctions[0]);
1606
+ const template = lodash.cloneDeep(lodash.find(tables, { id: addInFunction.template_id }));
1607
+
1608
+ highchartsRenderer.addTemplateDataToFunctionOptions(template, addInFunction);
1609
+ expect(addInFunction.pivot).toBeTruthy();
1610
+
1611
+ expect(addInFunction.pivot.fieldsArray.length).toBe(template.fields.length - addInFunction.filters.length - addInFunction.vals.length);
1612
+ expect(addInFunction.pivot.valuesArray.length).toBe(addInFunction.vals.length);
1613
+ expect(addInFunction.pivot.filtersArray.length).toBe(addInFunction.filters.length);
1614
+ expect(addInFunction.pivot.calculatedValues.length).toBe(addInFunction.calculated_values.length);
1615
+ });
1616
+ });
1617
+
1618
+ describe('function addTemplateDataToWidgetOptions', () => {
1619
+ let widget;
1620
+ let template;
1621
+
1622
+ beforeEach(() => {
1623
+ widget = lodash.cloneDeep(widgets[0]);
1624
+ template = lodash.cloneDeep(lodash.find(tables, { id: widget.template_id }));
1625
+ });
1626
+
1627
+ it('should fill pivot options', () => {
1628
+ const uniqFields = lodash.uniqBy(lodash.concat(widget.rows, widget.cols, widget.filters, widget.vals), 'name');
1629
+ const uniqFieldsWithoutFilters = lodash.uniqBy(lodash.concat(widget.rows, widget.cols, widget.vals), 'name');
1630
+ const filtersWithoutFields = lodash.differenceBy(widget.filters, uniqFieldsWithoutFilters, 'name');
1631
+
1632
+ highchartsRenderer.addTemplateDataToWidgetOptions(template, widget, false);
1633
+
1634
+ expect(widget.pivot).toBeTruthy();
1635
+ expect(widget.pivot.calculatedValues.length).toBe(widget.calculated_values.length);
1636
+ expect(widget.pivot.fieldsArray.length).toBe(template.fields.length - uniqFields.length);
1637
+ expect(widget.pivot.axisArray.length).toBe(widget.cols.length);
1638
+ expect(widget.pivot.legendArray.length).toBe(widget.rows.length);
1639
+ expect(widget.pivot.valuesArray.length).toBe(widget.vals.length);
1640
+ expect(widget.pivot.filtersArray.length).toBe(filtersWithoutFields.length);
1641
+ expect(widget.pivot.filterIncludes).toBeDefined();
1642
+ expect(widget.pivot.chartType).toBe(widget.chart_type);
1643
+ expect(widget.pivot.chartOptions).toEqual(widget.options);
1644
+ expect(widget.pivot.chartRender).not.toBe(null);
1645
+ });
1646
+
1647
+ it('should not exclude filters if doNotRemoveFilters enabled', () => {
1648
+ const uniqFields = lodash.uniqBy(lodash.concat(widget.rows, widget.cols, widget.vals), 'name');
1649
+
1650
+ highchartsRenderer.addTemplateDataToWidgetOptions(template, widget, true);
1651
+
1652
+ expect(widget.pivot.fieldsArray.length).toBe(template.fields.length - uniqFields.length);
1653
+ });
1654
+
1655
+ it('should take old row data on second time', () => {
1656
+ const rowData = { rowData: '123' };
1657
+ const sorters = { sorters: '123' };
1658
+ highchartsRenderer.addTemplateDataToWidgetOptions(template, widget, false);
1659
+ widget.pivot.rowData = rowData;
1660
+ widget.pivot.sorters = sorters;
1661
+ highchartsRenderer.addTemplateDataToWidgetOptions(template, widget, false);
1662
+ expect(widget.pivot.rowData).toBe(rowData);
1663
+ expect(widget.pivot.sorters).toBe(sorters);
1664
+ });
1665
+ });
1666
+
1667
+ describe('function addFilterDataToField', () => {
1668
+ let filterObj, fieldOb, includes;
1669
+
1670
+ beforeEach(() => {
1671
+ filterObj = {
1672
+ values: ['value1', 'value2'],
1673
+ is_excluded: false,
1674
+ show_in_graph: true,
1675
+ override_global_filter: true,
1676
+ allow_nulls: true
1677
+ };
1678
+ fieldOb = {
1679
+ name: 'fieldName',
1680
+ values: []
1681
+ };
1682
+ includes = {};
1683
+ });
1684
+
1685
+ it('should set includes array for field when filter is not excluded', () => {
1686
+ highchartsRenderer.addFilterDataToField(filterObj, fieldOb, includes);
1687
+
1688
+ expect(fieldOb.includes).toEqual(['value1', 'value2']);
1689
+ expect(fieldOb.excludes).toBeUndefined();
1690
+ expect(includes).toEqual({
1691
+ fieldName: ['value1', 'value2']
1692
+ });
1693
+ expect(fieldOb.show_in_graph).toBe(true);
1694
+ expect(fieldOb.override_global_filter).toBe(true);
1695
+ expect(fieldOb.allow_nulls).toBe(true);
1696
+ });
1697
+
1698
+ it('should set excludes array for field when filter is excluded', () => {
1699
+ filterObj.is_excluded = true;
1700
+
1701
+ highchartsRenderer.addFilterDataToField(filterObj, fieldOb, includes);
1702
+
1703
+ expect(fieldOb.includes).toBeUndefined();
1704
+ expect(fieldOb.excludes).toEqual(['value1', 'value2']);
1705
+ expect(includes).toEqual({
1706
+ fieldName: []
1707
+ });
1708
+ expect(fieldOb.show_in_graph).toBe(true);
1709
+ expect(fieldOb.override_global_filter).toBe(true);
1710
+ expect(fieldOb.allow_nulls).toBe(true);
1711
+ });
1712
+
1713
+ it('should set values on field when datetype is not list', () => {
1714
+ filterObj.values = {
1715
+ datetype: {
1716
+ type: 'not list'
1717
+ }
1718
+ };
1719
+
1720
+ highchartsRenderer.addFilterDataToField(filterObj, fieldOb, includes);
1721
+
1722
+ expect(fieldOb.includes).toBeUndefined();
1723
+ expect(fieldOb.excludes).toBeUndefined();
1724
+ expect(fieldOb.values).toEqual(filterObj.values);
1725
+ expect(fieldOb.show_in_graph).toBe(true);
1726
+ expect(fieldOb.override_global_filter).toBe(true);
1727
+ expect(fieldOb.allow_nulls).toBe(true);
1728
+ });
1729
+
1730
+ it('should set values.val on filterObj when datetype is list', () => {
1731
+ const values = ['list value 1', 'list value 2'];
1732
+ filterObj.values = {
1733
+ datetype: 'list',
1734
+ val: values
1735
+ };
1736
+
1737
+ highchartsRenderer.addFilterDataToField(filterObj, fieldOb, includes);
1738
+
1739
+ expect(fieldOb.includes).toEqual(values);
1740
+ expect(fieldOb.excludes).toBeUndefined();
1741
+ expect(filterObj.values).toEqual(values);
1742
+ expect(fieldOb.show_in_graph).toBe(true);
1743
+ expect(fieldOb.override_global_filter).toBe(true);
1744
+ expect(fieldOb.allow_nulls).toBe(true);
1745
+ });
1746
+
1747
+ it('should set values on field when type is advanced', () => {
1748
+ filterObj.values = {
1749
+ type: 'advanced'
1750
+ };
1751
+ filterObj.values.type = 'advanced';
1752
+
1753
+ highchartsRenderer.addFilterDataToField(filterObj, fieldOb, includes);
1754
+
1755
+ expect(fieldOb.includes).toBeUndefined();
1756
+ expect(fieldOb.excludes).toBeUndefined();
1757
+ expect(fieldOb.values).toEqual(filterObj.values);
1758
+ expect(fieldOb.show_in_graph).toBe(true);
1759
+ expect(fieldOb.override_global_filter).toBe(true);
1760
+ expect(fieldOb.allow_nulls).toBe(true);
1761
+ });
1762
+
1763
+ it('should set show_in_graph to false on field when filterObj.show_in_graph is false', () => {
1764
+ filterObj.show_in_graph = false;
1765
+ highchartsRenderer.addFilterDataToField(filterObj, fieldOb, includes);
1766
+
1767
+ expect(fieldOb.show_in_graph).toBeUndefined();
1768
+ expect(fieldOb.override_global_filter).toBe(true);
1769
+ expect(fieldOb.allow_nulls).toBe(true);
1770
+ });
1771
+
1772
+ it('should set override_global_filter to false on field when filterObj.override_global_filter is false', () => {
1773
+ filterObj.override_global_filter = false;
1774
+
1775
+ highchartsRenderer.addFilterDataToField(filterObj, fieldOb, includes);
1776
+
1777
+ expect(fieldOb.show_in_graph).toBe(true);
1778
+ expect(fieldOb.override_global_filter).toBeUndefined();
1779
+ expect(fieldOb.allow_nulls).toBe(true);
1780
+ });
1781
+
1782
+
1783
+ it('should set allow_nulls to false on field when filterObj.allow_nulls is false', () => {
1784
+ filterObj.allow_nulls = false;
1785
+ highchartsRenderer.addFilterDataToField(filterObj, fieldOb, includes);
1786
+
1787
+ expect(fieldOb.show_in_graph).toBe(true);
1788
+ expect(fieldOb.override_global_filter).toBe(true);
1789
+ expect(fieldOb.allow_nulls).toBeUndefined();
1790
+ });
1791
+ });
1792
+
1566
1793
  describe('function getChartOptionsBySubType', () => {
1567
1794
  it('returns null for rich_text subtype', () => {
1568
1795
  const result = highchartsRenderer.getChartOptionsBySubType('rich_text');
@@ -1735,6 +1962,7 @@ describe('highcharts_renderer', () => {
1735
1962
  });
1736
1963
 
1737
1964
  it('Formats must be filled and uniq', () => {
1965
+ highchartsRenderer.enabledNewWidgetValueFormatting = false;
1738
1966
  aggregatorObject.push({Profit: 123, formats: ['####', '####', '#,###']});
1739
1967
  expect(aggregatorObject.formats).toEqual(['####', '#,###']);
1740
1968
  });
@@ -1781,6 +2009,21 @@ describe('highcharts_renderer', () => {
1781
2009
  aggregatorObject.push({Profit: 20, 'Region average': 'Central', Region: 'Region average'});
1782
2010
  expect(aggregatorObject.ignoreValue).toBe(true);
1783
2011
  });
2012
+
2013
+ it('if FF enabledNewWidgetValueFormatting is and some of secondaryAxis is true widget values format must be from seriesOptions', () => {
2014
+ highchartsRenderer.enabledNewWidgetValueFormatting = true;
2015
+ const options = {
2016
+ comboOptions: {
2017
+ seriesOptions: [
2018
+ {series: 'Profit', format: '\"$\"#,###.###' , secondaryAxis: true},
2019
+ ]
2020
+ }
2021
+ }
2022
+ aggregator = highchartsRenderer.rhPivotAggregatorSum(arg, widget_values_format, is_graph, options, calculated_info);
2023
+ aggregatorObject = aggregator({}, ['Profit'], '');
2024
+ aggregatorObject.push({ DR_Values: 'Profit', Profit: 123 });
2025
+ expect(aggregatorObject.formats).toEqual(['\"$\"#,###.###']);
2026
+ });
1784
2027
  });
1785
2028
 
1786
2029
  describe('Value method', () => {
@@ -1831,6 +2074,22 @@ describe('highcharts_renderer', () => {
1831
2074
  aggregatorObject = aggregator({}, ['Region average'], '');
1832
2075
  expect(aggregatorObject.format(1123.45678, false)).toBe('112345.68%');
1833
2076
  });
2077
+
2078
+ it('if FF enabledNewWidgetValueFormatting is and some of secondaryAxis is true widget values format must be from seriesOptions and widget_value_format to equal first seriesOptions format', () => {
2079
+ highchartsRenderer.enabledNewWidgetValueFormatting = true;
2080
+ widget_values_format = '\"$\"#,###.###';
2081
+ const options = {
2082
+ comboOptions: {
2083
+ seriesOptions: [
2084
+ {series: 'Profit', format: '\"$\"#,###.###' , secondaryAxis: true},
2085
+ ]
2086
+ }
2087
+ }
2088
+ aggregator = highchartsRenderer.rhPivotAggregatorSum(arg, widget_values_format, is_graph, options, calculated_info);
2089
+ aggregatorObject = aggregator({}, ['Profit'], '');
2090
+ aggregatorObject.push({ DR_Values: 'Profit', Profit: 123 });
2091
+ expect(aggregatorObject.format(1123.45678, false)).toBe('$1,123.457');
2092
+ });
1834
2093
  });
1835
2094
  });
1836
2095
 
@@ -1912,6 +2171,7 @@ describe('highcharts_renderer', () => {
1912
2171
  });
1913
2172
 
1914
2173
  it('Formats must be filled and uniq', () => {
2174
+ highchartsRenderer.enabledNewWidgetValueFormatting = false;
1915
2175
  aggregatorObject.push({Profit: 123, formats: ['####', '####', '#,###']});
1916
2176
  expect(aggregatorObject.formats).toEqual(['####', '#,###']);
1917
2177
  });
@@ -1958,6 +2218,21 @@ describe('highcharts_renderer', () => {
1958
2218
  aggregatorObject.push({Profit: 20, 'Region average': 'Central', Region: 'Region average'});
1959
2219
  expect(aggregatorObject.ignoreValue).toBe(true);
1960
2220
  });
2221
+
2222
+ it('if FF enabledNewWidgetValueFormatting is and some of secondaryAxis is true widget values format must be from seriesOptions', () => {
2223
+ highchartsRenderer.enabledNewWidgetValueFormatting = true;
2224
+ const options = {
2225
+ comboOptions: {
2226
+ seriesOptions: [
2227
+ {series: 'Profit', format: '\"$\"#,###.###' , secondaryAxis: true},
2228
+ ]
2229
+ }
2230
+ }
2231
+ aggregator = highchartsRenderer.rhPivotCount(arg, widget_values_format, is_graph, options, calculated_info);
2232
+ aggregatorObject = aggregator({}, ['Profit'], '');
2233
+ aggregatorObject.push({ DR_Values: 'Profit', Profit: 123 });
2234
+ expect(aggregatorObject.formats).toEqual(['\"$\"#,###.###']);
2235
+ });
1961
2236
  });
1962
2237
 
1963
2238
  describe('Value method', () => {
@@ -2008,6 +2283,22 @@ describe('highcharts_renderer', () => {
2008
2283
  aggregatorObject = aggregator({}, ['Region average'], '');
2009
2284
  expect(aggregatorObject.format(1123.45678, false)).toBe('112345.68%');
2010
2285
  });
2286
+
2287
+ it('if FF enabledNewWidgetValueFormatting is and some of secondaryAxis is true widget values format must be from seriesOptions and widget_value_format to equal first seriesOptions format', () => {
2288
+ highchartsRenderer.enabledNewWidgetValueFormatting = true;
2289
+ widget_values_format = '\"$\"#,###.###';
2290
+ const options = {
2291
+ comboOptions: {
2292
+ seriesOptions: [
2293
+ {series: 'Profit', format: '\"$\"#,###.###' , secondaryAxis: true},
2294
+ ]
2295
+ }
2296
+ }
2297
+ aggregator = highchartsRenderer.rhPivotCount(arg, widget_values_format, is_graph, options, calculated_info);
2298
+ aggregatorObject = aggregator({}, ['Profit'], '');
2299
+ aggregatorObject.push({ DR_Values: 'Profit', Profit: 123 });
2300
+ expect(aggregatorObject.format(1123.45678, false)).toBe('$1,123.457');
2301
+ });
2011
2302
  });
2012
2303
  });
2013
2304
 
@@ -2243,6 +2534,7 @@ describe('highcharts_renderer', () => {
2243
2534
  });
2244
2535
 
2245
2536
  it('Formats must be filled and uniq', () => {
2537
+ highchartsRenderer.enabledNewWidgetValueFormatting = false;
2246
2538
  aggregatorObject.push({Profit: 123, formats: ['####', '####', '#,###']});
2247
2539
  expect(aggregatorObject.formats).toEqual(['####', '#,###']);
2248
2540
  });
@@ -2291,6 +2583,21 @@ describe('highcharts_renderer', () => {
2291
2583
  aggregatorObject.push({Profit: 20, 'Region average': 'Central', Region: 'Region average'});
2292
2584
  expect(aggregatorObject.ignoreValue).toBe(true);
2293
2585
  });
2586
+
2587
+ it('if FF enabledNewWidgetValueFormatting is and some of secondaryAxis is true widget values format must be from seriesOptions', () => {
2588
+ highchartsRenderer.enabledNewWidgetValueFormatting = true;
2589
+ const options = {
2590
+ comboOptions: {
2591
+ seriesOptions: [
2592
+ {series: 'Profit', format: '\"$\"#,###.###' , secondaryAxis: true},
2593
+ ]
2594
+ }
2595
+ }
2596
+ aggregator = highchartsRenderer.rhPivotAggregatorAverage(arg, widget_values_format, is_graph, options, calculated_info);
2597
+ aggregatorObject = aggregator({}, ['Profit'], '');
2598
+ aggregatorObject.push({ DR_Values: 'Profit', Profit: 123 });
2599
+ expect(aggregatorObject.formats).toEqual(['\"$\"#,###.###']);
2600
+ });
2294
2601
  });
2295
2602
 
2296
2603
  describe('Value method', () => {
@@ -2350,6 +2657,22 @@ describe('highcharts_renderer', () => {
2350
2657
  aggregatorObject = aggregator({}, ['Region average'], '');
2351
2658
  expect(aggregatorObject.format(1123.45678, false)).toBe('112345.68%');
2352
2659
  });
2660
+
2661
+ it('if FF enabledNewWidgetValueFormatting is and some of secondaryAxis is true widget values format must be from seriesOptions and widget_value_format to equal first seriesOptions format', () => {
2662
+ highchartsRenderer.enabledNewWidgetValueFormatting = true;
2663
+ widget_values_format = '\"$\"#,###.###';
2664
+ const options = {
2665
+ comboOptions: {
2666
+ seriesOptions: [
2667
+ {series: 'Profit', format: '\"$\"#,###.###' , secondaryAxis: true},
2668
+ ]
2669
+ }
2670
+ }
2671
+ aggregator = highchartsRenderer.rhPivotAggregatorAverage(arg, widget_values_format, is_graph, options, calculated_info);
2672
+ aggregatorObject = aggregator({}, ['Profit'], '');
2673
+ aggregatorObject.push({ DR_Values: 'Profit', Profit: 123 });
2674
+ expect(aggregatorObject.format(1123.45678, false)).toBe('$1,123.457');
2675
+ });
2353
2676
  });
2354
2677
  });
2355
2678
 
@@ -2431,6 +2754,7 @@ describe('highcharts_renderer', () => {
2431
2754
  });
2432
2755
 
2433
2756
  it('Formats must be filled and uniq', () => {
2757
+ highchartsRenderer.enabledNewWidgetValueFormatting = false;
2434
2758
  aggregatorObject.push({Profit: 123, formats: ['####', '####', '#,###']});
2435
2759
  expect(aggregatorObject.formats).toEqual(['####', '#,###']);
2436
2760
  });
@@ -2477,6 +2801,21 @@ describe('highcharts_renderer', () => {
2477
2801
  aggregatorObject.push({Profit: 20, 'Region average': 'Central', Region: 'Region average'});
2478
2802
  expect(aggregatorObject.ignoreValue).toBe(true);
2479
2803
  });
2804
+
2805
+ it('if FF enabledNewWidgetValueFormatting is and some of secondaryAxis is true widget values format must be from seriesOptions', () => {
2806
+ highchartsRenderer.enabledNewWidgetValueFormatting = true;
2807
+ const options = {
2808
+ comboOptions: {
2809
+ seriesOptions: [
2810
+ {series: 'Profit', format: '\"$\"#,###.###' , secondaryAxis: true},
2811
+ ]
2812
+ }
2813
+ }
2814
+ aggregator = highchartsRenderer.rhPivotAggregatorMin(arg, widget_values_format, is_graph, options, calculated_info);
2815
+ aggregatorObject = aggregator({}, ['Profit'], '');
2816
+ aggregatorObject.push({ DR_Values: 'Profit', Profit: 123 });
2817
+ expect(aggregatorObject.formats).toEqual(['\"$\"#,###.###']);
2818
+ });
2480
2819
  });
2481
2820
 
2482
2821
  describe('Value method', () => {
@@ -2528,6 +2867,22 @@ describe('highcharts_renderer', () => {
2528
2867
  aggregatorObject = aggregator({}, ['Region average'], '');
2529
2868
  expect(aggregatorObject.format(1123.45678, false)).toBe('112345.68%');
2530
2869
  });
2870
+
2871
+ it('if FF enabledNewWidgetValueFormatting is and some of secondaryAxis is true widget values format must be from seriesOptions and widget_value_format to equal first seriesOptions format', () => {
2872
+ highchartsRenderer.enabledNewWidgetValueFormatting = true;
2873
+ widget_values_format = '\"$\"#,###.###';
2874
+ const options = {
2875
+ comboOptions: {
2876
+ seriesOptions: [
2877
+ {series: 'Profit', format: '\"$\"#,###.###' , secondaryAxis: true},
2878
+ ]
2879
+ }
2880
+ }
2881
+ aggregator = highchartsRenderer.rhPivotAggregatorMin(arg, widget_values_format, is_graph, options, calculated_info);
2882
+ aggregatorObject = aggregator({}, ['Profit'], '');
2883
+ aggregatorObject.push({ DR_Values: 'Profit', Profit: 123 });
2884
+ expect(aggregatorObject.format(1123.45678, false)).toBe('$1,123.457');
2885
+ });
2531
2886
  });
2532
2887
  });
2533
2888
 
@@ -2609,6 +2964,7 @@ describe('highcharts_renderer', () => {
2609
2964
  });
2610
2965
 
2611
2966
  it('Formats must be filled and uniq', () => {
2967
+ highchartsRenderer.enabledNewWidgetValueFormatting = false;
2612
2968
  aggregatorObject.push({Profit: 123, formats: ['####', '####', '#,###']});
2613
2969
  expect(aggregatorObject.formats).toEqual(['####', '#,###']);
2614
2970
  });
@@ -2655,6 +3011,21 @@ describe('highcharts_renderer', () => {
2655
3011
  aggregatorObject.push({Profit: 20, 'Region average': 'Central', Region: 'Region average'});
2656
3012
  expect(aggregatorObject.ignoreValue).toBe(true);
2657
3013
  });
3014
+
3015
+ it('if FF enabledNewWidgetValueFormatting is and some of secondaryAxis is true widget values format must be from seriesOptions', () => {
3016
+ highchartsRenderer.enabledNewWidgetValueFormatting = true;
3017
+ const options = {
3018
+ comboOptions: {
3019
+ seriesOptions: [
3020
+ {series: 'Profit', format: '\"$\"#,###.###' , secondaryAxis: true},
3021
+ ]
3022
+ }
3023
+ }
3024
+ aggregator = highchartsRenderer.rhPivotAggregatorMax(arg, widget_values_format, is_graph, options, calculated_info);
3025
+ aggregatorObject = aggregator({}, ['Profit'], '');
3026
+ aggregatorObject.push({ DR_Values: 'Profit', Profit: 123 });
3027
+ expect(aggregatorObject.formats).toEqual(['\"$\"#,###.###']);
3028
+ });
2658
3029
  });
2659
3030
 
2660
3031
  describe('Value method', () => {
@@ -2706,6 +3077,22 @@ describe('highcharts_renderer', () => {
2706
3077
  aggregatorObject = aggregator({}, ['Region average'], '');
2707
3078
  expect(aggregatorObject.format(1123.45678, false)).toBe('112345.68%');
2708
3079
  });
3080
+
3081
+ it('if FF enabledNewWidgetValueFormatting is and some of secondaryAxis is true widget values format must be from seriesOptions and widget_value_format to equal first seriesOptions format', () => {
3082
+ highchartsRenderer.enabledNewWidgetValueFormatting = true;
3083
+ widget_values_format = '\"$\"#,###.###';
3084
+ const options = {
3085
+ comboOptions: {
3086
+ seriesOptions: [
3087
+ {series: 'Profit', format: '\"$\"#,###.###' , secondaryAxis: true},
3088
+ ]
3089
+ }
3090
+ }
3091
+ aggregator = highchartsRenderer.rhPivotAggregatorMax(arg, widget_values_format, is_graph, options, calculated_info);
3092
+ aggregatorObject = aggregator({}, ['Profit'], '');
3093
+ aggregatorObject.push({ DR_Values: 'Profit', Profit: 123 });
3094
+ expect(aggregatorObject.format(1123.45678, false)).toBe('$1,123.457');
3095
+ });
2709
3096
  });
2710
3097
  });
2711
3098
  });
@@ -4291,4 +4678,144 @@ describe('highcharts_renderer', () => {
4291
4678
  expect(highchartsRenderer.getTrendSeriesName(series)).toBe(expectedName);
4292
4679
  });
4293
4680
  });
4681
+
4682
+ describe('function checkFormats', () => {
4683
+ it('should correctly detect if any series is on secondary axis', () => {
4684
+ const render_options = {
4685
+ comboOptions: {
4686
+ seriesOptions: [
4687
+ { secondaryAxis: false },
4688
+ { secondaryAxis: true },
4689
+ { secondaryAxis: false },
4690
+ ],
4691
+ },
4692
+ };
4693
+ const widget_values_format = '#,###';
4694
+ const result = highchartsRenderer.checkFormats(render_options, widget_values_format);
4695
+ expect(result.isSecondaryAxis).toBe(true);
4696
+ });
4697
+
4698
+ it('should correctly detect if all series are on primary axis', () => {
4699
+ const render_options = {
4700
+ comboOptions: {
4701
+ seriesOptions: [
4702
+ { secondaryAxis: false },
4703
+ { secondaryAxis: false },
4704
+ { secondaryAxis: false },
4705
+ ],
4706
+ },
4707
+ };
4708
+ const widget_values_format = '#,###';
4709
+ const result = highchartsRenderer.checkFormats(render_options, widget_values_format);
4710
+ expect(result.isSecondaryAxis).toBe(false);
4711
+ });
4712
+
4713
+ it('should correctly detect if the given format is custom', () => {
4714
+ const render_options = {
4715
+ comboOptions: {
4716
+ seriesOptions: [
4717
+ { format: '#,###' },
4718
+ { format: '#,###' },
4719
+ { format: '#,###' },
4720
+ ],
4721
+ },
4722
+ };
4723
+ const widget_values_format = '$#,###.###';
4724
+ const result = highchartsRenderer.checkFormats(render_options, widget_values_format);
4725
+ expect(result.isCustomFormat).toBe(true);
4726
+ });
4727
+
4728
+ it('should correctly detect if the given format is not custom', () => {
4729
+ const render_options = {
4730
+ comboOptions: {
4731
+ seriesOptions: [
4732
+ { format: '$#,###' },
4733
+ { format: '$#,###.#' },
4734
+ { format: '$#,###.##' },
4735
+ ],
4736
+ },
4737
+ };
4738
+ const widget_values_format = '$#,###';
4739
+ const result = highchartsRenderer.checkFormats(render_options, widget_values_format);
4740
+ expect(result.isCustomFormat).toBe(false);
4741
+ });
4742
+ });
4743
+
4744
+ describe('function isCustomValuesFormat', () => {
4745
+ const render_options = {
4746
+ comboOptions: {
4747
+ seriesOptions: [
4748
+ { series: 'Profit', format: '#,###', secondaryAxis: false },
4749
+ { series: 'Sales', format: '#,###', secondaryAxis: true },
4750
+ ]
4751
+ }
4752
+ };
4753
+
4754
+ it('should return true if new widget value formatting is enabled and the format is custom or there is no secondary axis', () => {
4755
+ const widget_values_format = '$####.##';
4756
+
4757
+ highchartsRenderer.enabledNewWidgetValueFormatting = true;
4758
+
4759
+ const expectedValue = true;
4760
+
4761
+ const result = highchartsRenderer.isCustomValuesFormat(render_options, widget_values_format);
4762
+
4763
+ expect(result).toEqual(expectedValue);
4764
+ });
4765
+
4766
+ it('should return false if new widget value formatting is disabled', () => {
4767
+ const widget_values_format = '#,###';
4768
+
4769
+ highchartsRenderer.enabledNewWidgetValueFormatting = false;
4770
+
4771
+ const expectedValue = false;
4772
+
4773
+ const result = highchartsRenderer.isCustomValuesFormat(render_options, widget_values_format);
4774
+
4775
+ expect(result).toEqual(expectedValue);
4776
+ });
4777
+
4778
+ it('should return false if the format is not custom and there is a secondary axis', () => {
4779
+ const widget_values_format = '#,###';
4780
+
4781
+ highchartsRenderer.enabledNewWidgetValueFormatting = true;
4782
+
4783
+ const expectedValue = false;
4784
+
4785
+ const result = highchartsRenderer.isCustomValuesFormat(render_options, widget_values_format);
4786
+
4787
+ expect(result).toEqual(expectedValue);
4788
+ });
4789
+ });
4790
+
4791
+ describe('getRecordFormats', () => {
4792
+ const render_options = {
4793
+ comboOptions: {
4794
+ seriesOptions: [
4795
+ { series: 'Profit', format: '$####.#', secondaryAxis: false },
4796
+ { series: 'Sales', format: '$####.##', secondaryAxis: true },
4797
+ ]
4798
+ }
4799
+ };
4800
+
4801
+ it('should return an array of formats for the given record name', () => {
4802
+ const recordName = 'Profit';
4803
+
4804
+ const expectedValue = ['$####.#'];
4805
+
4806
+ const result = highchartsRenderer.getRecordFormats(render_options, recordName);
4807
+
4808
+ expect(result).toEqual(expectedValue);
4809
+ });
4810
+
4811
+ it('should return an empty array if there are no matching records', () => {
4812
+ const recordName = 'Any';
4813
+
4814
+ const expectedValue = [];
4815
+
4816
+ const result = highchartsRenderer.getRecordFormats(render_options, recordName);
4817
+
4818
+ expect(result).toEqual(expectedValue);
4819
+ });
4820
+ });
4294
4821
  });