@datarailsshared/dr_renderer 1.2.318-rocket → 1.2.321

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.
@@ -483,6 +483,7 @@ describe('highcharts_renderer', () => {
483
483
  let opts;
484
484
 
485
485
  beforeEach(() => {
486
+ highchartsRenderer.enabledNewWidgetValueFormatting = false;
486
487
  funcContext = { y: '12345.678' };
487
488
  opts = {}
488
489
  });
@@ -1323,6 +1324,264 @@ describe('highcharts_renderer', () => {
1323
1324
  });
1324
1325
  });
1325
1326
 
1327
+ describe("function updateBackwardCompatibleWidgetOptions", () => {
1328
+ it("should delete chart 'hideLegends' option if exists and true", () => {
1329
+ const options = {
1330
+ chartOptions: {
1331
+ chart: {
1332
+ hideLegends: true
1333
+ }
1334
+ },
1335
+ comboOptions: {}
1336
+ };
1337
+ highchartsRenderer.updateBackwardCompatibleWidgetOptions(options, 'line-chart')
1338
+ expect(options.chartOptions.legends_position.value).toBe('none');
1339
+ expect(options.chartOptions.chart.hideLegends).toBe(undefined);
1340
+ });
1341
+
1342
+ it("should move error_policy chart option to advanced chart option", () => {
1343
+ const error_policy = 'test_policy';
1344
+ const options = {
1345
+ chartOptions: {
1346
+ error_policy: {
1347
+ error_policy: error_policy
1348
+ }
1349
+ },
1350
+ comboOptions: {}
1351
+ };
1352
+ highchartsRenderer.updateBackwardCompatibleWidgetOptions(options, 'line-chart')
1353
+ expect(options.chartOptions.advanced.from_latest).toBe('');
1354
+ expect(options.chartOptions.advanced.error_policy).toBe(error_policy);
1355
+ expect(options.chartOptions.error_policy).toBe(undefined);
1356
+ expect(options.chartOptions.from_version).toBe(undefined);
1357
+ });
1358
+
1359
+ it("should move from_version chart option to advanced chart option", () => {
1360
+ const from_version = 'from_version';
1361
+ const options = {
1362
+ chartOptions: {
1363
+ from_version: {
1364
+ value: from_version
1365
+ }
1366
+ },
1367
+ comboOptions: {}
1368
+ };
1369
+ highchartsRenderer.updateBackwardCompatibleWidgetOptions(options, 'line-chart')
1370
+ expect(options.chartOptions.advanced.from_latest).toBe(from_version);
1371
+ expect(options.chartOptions.advanced.error_policy).toBe('None');
1372
+ expect(options.chartOptions.error_policy).toBe(undefined);
1373
+ expect(options.chartOptions.from_version).toBe(undefined);
1374
+ });
1375
+
1376
+ it("should remove chart label style option", () => {
1377
+ const options = {
1378
+ chartOptions: {
1379
+ label: {
1380
+ style: 'color: red;'
1381
+ }
1382
+ },
1383
+ comboOptions: {}
1384
+ };
1385
+ highchartsRenderer.updateBackwardCompatibleWidgetOptions(options, 'line-chart')
1386
+ expect(options.chartOptions.label.style).toBe(undefined);
1387
+ });
1388
+
1389
+ it("should remove chart label_pie style option", () => {
1390
+ const options = {
1391
+ chartOptions: {
1392
+ label_pie: {
1393
+ style: 'color: red;'
1394
+ }
1395
+ },
1396
+ comboOptions: {}
1397
+ };
1398
+ highchartsRenderer.updateBackwardCompatibleWidgetOptions(options, 'line-chart')
1399
+ expect(options.chartOptions.label_pie.style).toBe(undefined);
1400
+ });
1401
+
1402
+ it("update pie-chart label options if only_value", () => {
1403
+ const options = {
1404
+ chartOptions: {
1405
+ label: {
1406
+ only_value: true
1407
+ }
1408
+ },
1409
+ comboOptions: {}
1410
+ };
1411
+ highchartsRenderer.updateBackwardCompatibleWidgetOptions(options, 'pie-chart')
1412
+ expect(options.chartOptions.label_pie).toEqual({
1413
+ show_percentage_in_labels: false,
1414
+ show_value_in_labels: true
1415
+ });
1416
+ expect(options.chartOptions.label).toBe(undefined);
1417
+ });
1418
+
1419
+ it("update pie-chart label options if only_percentage", () => {
1420
+ const options = {
1421
+ chartOptions: {
1422
+ label: {
1423
+ only_percentage: true
1424
+ }
1425
+ },
1426
+ comboOptions: {}
1427
+ };
1428
+ highchartsRenderer.updateBackwardCompatibleWidgetOptions(options, 'pie-chart')
1429
+ expect(options.chartOptions.label_pie).toEqual({
1430
+ show_percentage_in_labels: true,
1431
+ show_value_in_labels: false
1432
+ });
1433
+ expect(options.chartOptions.label).toBe(undefined);
1434
+ });
1435
+
1436
+ it("update pie-chart label options if show", () => {
1437
+ const options = {
1438
+ chartOptions: {
1439
+ label: {
1440
+ show: true
1441
+ }
1442
+ },
1443
+ comboOptions: {}
1444
+ };
1445
+ highchartsRenderer.updateBackwardCompatibleWidgetOptions(options, 'pie-chart');
1446
+ expect(options.chartOptions.label_pie).toEqual({
1447
+ show: true,
1448
+ show_percentage_in_labels: true,
1449
+ show_value_in_labels: true
1450
+ });
1451
+ expect(options.chartOptions.label).toBe(undefined);
1452
+ });
1453
+
1454
+ it("should do nothing if pie chart without 'only_percentage/only_value/show'", () => {
1455
+ const options1 = {
1456
+ chartOptions: { label: { } }, comboOptions: {}
1457
+ };
1458
+ const options2 = {
1459
+ chartOptions: { }, comboOptions: {}
1460
+ };
1461
+
1462
+ highchartsRenderer.updateBackwardCompatibleWidgetOptions(options1, 'pie-chart');
1463
+ expect(options1).toEqual({
1464
+ chartOptions: { label_pie: {} }, comboOptions: {}
1465
+ });
1466
+ highchartsRenderer.updateBackwardCompatibleWidgetOptions(options2, 'pie-chart');
1467
+ expect(options2).toEqual({
1468
+ chartOptions: { }, comboOptions: {}
1469
+ });
1470
+ });
1471
+
1472
+ it("should create comboOptions for different series types", () => {
1473
+ const options = {
1474
+ chartOptions: {
1475
+ delta_column: {
1476
+ field: 'series',
1477
+ name: 'TEST_test',
1478
+ same_yaxis: true,
1479
+ is_percentage: true,
1480
+ }
1481
+ }
1482
+ };
1483
+
1484
+ const seriesTypes = ['line', 'spline', 'area', 'areaspline', 'scatter', 'column', 'default'];
1485
+ const seriesTypesMap = ['line-chart', 'line-chart-smooth', 'area-chart', 'area-chart-smooth', 'scatter-chart', 'column-chart', 'scatter-chart'];
1486
+
1487
+ seriesTypes.forEach((type, index) => {
1488
+ const currentOptions = lodash.cloneDeep(options);
1489
+ currentOptions.chartOptions.delta_column.chart = type;
1490
+ highchartsRenderer.updateBackwardCompatibleWidgetOptions(currentOptions, null);
1491
+ expect(currentOptions.comboOptions).toEqual({
1492
+ secondaryAxisSettings: {
1493
+ name: 'TESTtest',
1494
+ max: null,
1495
+ min: null,
1496
+ is_percentage: true
1497
+ },
1498
+ seriesOptions: [{
1499
+ series: 'TEST_test',
1500
+ secondaryAxis: false,
1501
+ chartType: seriesTypesMap[index]
1502
+ }]
1503
+ });
1504
+ });
1505
+ });
1506
+
1507
+ it("should create comboOptions without series options if no delta_column field", () => {
1508
+ const options = {};
1509
+ highchartsRenderer.updateBackwardCompatibleWidgetOptions(options, null);
1510
+ expect(options).toEqual({
1511
+ comboOptions :{
1512
+ secondaryAxisSettings: {
1513
+ name: 'Secondary Axis',
1514
+ max: null,
1515
+ min: null,
1516
+ is_percentage: false,
1517
+ },
1518
+ seriesOptions: []
1519
+ }
1520
+ });
1521
+ });
1522
+ });
1523
+
1524
+ describe("function setMissingWidgetOptions", () => {
1525
+ it("should return do nothing if there are no chartOptions", () => {
1526
+ const options = { testProp: true };
1527
+ highchartsRenderer.setMissingWidgetOptions(options, null)
1528
+ expect(options).toEqual({ testProp: true });
1529
+ });
1530
+
1531
+ it("should merge current chart options with default", () => {
1532
+ spyOn(highchartsRenderer, 'getDefaultValueForChart').and.returnValue({
1533
+ array: [1, 3, 5],
1534
+ newProp: 'defaultNew',
1535
+ existingProp: 'defaultExist',
1536
+ obj: {
1537
+ newProp: 'defaultNew',
1538
+ existingProp: 'defaultExist',
1539
+ },
1540
+ newObj: {
1541
+ newProp: 'defaultNew',
1542
+ }
1543
+ });
1544
+ const options = {
1545
+ chartOptions: {
1546
+ array: [2, 5, 6],
1547
+ existingProp: 'exist',
1548
+ obj: {
1549
+ existingProp: 'exist',
1550
+ }
1551
+ }
1552
+ };
1553
+ highchartsRenderer.setMissingWidgetOptions(options, 'line-chart')
1554
+ expect(options.chartOptions).toEqual({
1555
+ array: [2, 5, 6],
1556
+ existingProp: "exist",
1557
+ newObj: { newProp: "defaultNew" },
1558
+ newProp: "defaultNew",
1559
+ obj: {
1560
+ existingProp: "exist",
1561
+ newProp: "defaultNew"
1562
+ }
1563
+ });
1564
+ });
1565
+ });
1566
+
1567
+ describe('function getChartOptionsBySubType', () => {
1568
+ it('returns null for rich_text subtype', () => {
1569
+ const result = highchartsRenderer.getChartOptionsBySubType('rich_text');
1570
+ expect(result).toBe(highchartsRenderer.richTextSubType);
1571
+ });
1572
+
1573
+ it('returns chart options for existing subtype', () => {
1574
+ const result = highchartsRenderer.getChartOptionsBySubType('line-chart');
1575
+ expect(result.type).toEqual('line-chart');
1576
+ expect(result.suboptions.length).toEqual(highchartsRenderer.chartsData[0].subtypes[0].suboptions.length);
1577
+ });
1578
+
1579
+ it('returns null for non-existing subtype', () => {
1580
+ const result = highchartsRenderer.getChartOptionsBySubType('nonExistingType');
1581
+ expect(result).toBe(null);
1582
+ });
1583
+ });
1584
+
1326
1585
  describe('function aggregators', () => {
1327
1586
  const aggregatorsIds = ['SUM', 'COUNT', 'COUNT_UNIQUE', 'UNIQUE_VALUES', 'AVG', 'MIN', 'MAX'];
1328
1587
 
@@ -1477,6 +1736,7 @@ describe('highcharts_renderer', () => {
1477
1736
  });
1478
1737
 
1479
1738
  it('Formats must be filled and uniq', () => {
1739
+ highchartsRenderer.enabledNewWidgetValueFormatting = false;
1480
1740
  aggregatorObject.push({Profit: 123, formats: ['####', '####', '#,###']});
1481
1741
  expect(aggregatorObject.formats).toEqual(['####', '#,###']);
1482
1742
  });
@@ -1523,6 +1783,21 @@ describe('highcharts_renderer', () => {
1523
1783
  aggregatorObject.push({Profit: 20, 'Region average': 'Central', Region: 'Region average'});
1524
1784
  expect(aggregatorObject.ignoreValue).toBe(true);
1525
1785
  });
1786
+
1787
+ it('if FF enabledNewWidgetValueFormatting is and some of secondaryAxis is true widget values format must be from seriesOptions', () => {
1788
+ highchartsRenderer.enabledNewWidgetValueFormatting = true;
1789
+ const options = {
1790
+ comboOptions: {
1791
+ seriesOptions: [
1792
+ {series: 'Profit', format: '\"$\"#,###.###' , secondaryAxis: true},
1793
+ ]
1794
+ }
1795
+ }
1796
+ aggregator = highchartsRenderer.rhPivotAggregatorSum(arg, widget_values_format, is_graph, options, calculated_info);
1797
+ aggregatorObject = aggregator({}, ['Profit'], '');
1798
+ aggregatorObject.push({ DR_Values: 'Profit', Profit: 123 });
1799
+ expect(aggregatorObject.formats).toEqual(['\"$\"#,###.###']);
1800
+ });
1526
1801
  });
1527
1802
 
1528
1803
  describe('Value method', () => {
@@ -1573,6 +1848,22 @@ describe('highcharts_renderer', () => {
1573
1848
  aggregatorObject = aggregator({}, ['Region average'], '');
1574
1849
  expect(aggregatorObject.format(1123.45678, false)).toBe('112345.68%');
1575
1850
  });
1851
+
1852
+ 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', () => {
1853
+ highchartsRenderer.enabledNewWidgetValueFormatting = true;
1854
+ widget_values_format = '\"$\"#,###.###';
1855
+ const options = {
1856
+ comboOptions: {
1857
+ seriesOptions: [
1858
+ {series: 'Profit', format: '\"$\"#,###.###' , secondaryAxis: true},
1859
+ ]
1860
+ }
1861
+ }
1862
+ aggregator = highchartsRenderer.rhPivotAggregatorSum(arg, widget_values_format, is_graph, options, calculated_info);
1863
+ aggregatorObject = aggregator({}, ['Profit'], '');
1864
+ aggregatorObject.push({ DR_Values: 'Profit', Profit: 123 });
1865
+ expect(aggregatorObject.format(1123.45678, false)).toBe('$1,123.457');
1866
+ });
1576
1867
  });
1577
1868
  });
1578
1869
 
@@ -1654,6 +1945,7 @@ describe('highcharts_renderer', () => {
1654
1945
  });
1655
1946
 
1656
1947
  it('Formats must be filled and uniq', () => {
1948
+ highchartsRenderer.enabledNewWidgetValueFormatting = false;
1657
1949
  aggregatorObject.push({Profit: 123, formats: ['####', '####', '#,###']});
1658
1950
  expect(aggregatorObject.formats).toEqual(['####', '#,###']);
1659
1951
  });
@@ -1700,6 +1992,21 @@ describe('highcharts_renderer', () => {
1700
1992
  aggregatorObject.push({Profit: 20, 'Region average': 'Central', Region: 'Region average'});
1701
1993
  expect(aggregatorObject.ignoreValue).toBe(true);
1702
1994
  });
1995
+
1996
+ it('if FF enabledNewWidgetValueFormatting is and some of secondaryAxis is true widget values format must be from seriesOptions', () => {
1997
+ highchartsRenderer.enabledNewWidgetValueFormatting = true;
1998
+ const options = {
1999
+ comboOptions: {
2000
+ seriesOptions: [
2001
+ {series: 'Profit', format: '\"$\"#,###.###' , secondaryAxis: true},
2002
+ ]
2003
+ }
2004
+ }
2005
+ aggregator = highchartsRenderer.rhPivotCount(arg, widget_values_format, is_graph, options, calculated_info);
2006
+ aggregatorObject = aggregator({}, ['Profit'], '');
2007
+ aggregatorObject.push({ DR_Values: 'Profit', Profit: 123 });
2008
+ expect(aggregatorObject.formats).toEqual(['\"$\"#,###.###']);
2009
+ });
1703
2010
  });
1704
2011
 
1705
2012
  describe('Value method', () => {
@@ -1750,6 +2057,22 @@ describe('highcharts_renderer', () => {
1750
2057
  aggregatorObject = aggregator({}, ['Region average'], '');
1751
2058
  expect(aggregatorObject.format(1123.45678, false)).toBe('112345.68%');
1752
2059
  });
2060
+
2061
+ 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', () => {
2062
+ highchartsRenderer.enabledNewWidgetValueFormatting = true;
2063
+ widget_values_format = '\"$\"#,###.###';
2064
+ const options = {
2065
+ comboOptions: {
2066
+ seriesOptions: [
2067
+ {series: 'Profit', format: '\"$\"#,###.###' , secondaryAxis: true},
2068
+ ]
2069
+ }
2070
+ }
2071
+ aggregator = highchartsRenderer.rhPivotCount(arg, widget_values_format, is_graph, options, calculated_info);
2072
+ aggregatorObject = aggregator({}, ['Profit'], '');
2073
+ aggregatorObject.push({ DR_Values: 'Profit', Profit: 123 });
2074
+ expect(aggregatorObject.format(1123.45678, false)).toBe('$1,123.457');
2075
+ });
1753
2076
  });
1754
2077
  });
1755
2078
 
@@ -1985,6 +2308,7 @@ describe('highcharts_renderer', () => {
1985
2308
  });
1986
2309
 
1987
2310
  it('Formats must be filled and uniq', () => {
2311
+ highchartsRenderer.enabledNewWidgetValueFormatting = false;
1988
2312
  aggregatorObject.push({Profit: 123, formats: ['####', '####', '#,###']});
1989
2313
  expect(aggregatorObject.formats).toEqual(['####', '#,###']);
1990
2314
  });
@@ -2033,6 +2357,21 @@ describe('highcharts_renderer', () => {
2033
2357
  aggregatorObject.push({Profit: 20, 'Region average': 'Central', Region: 'Region average'});
2034
2358
  expect(aggregatorObject.ignoreValue).toBe(true);
2035
2359
  });
2360
+
2361
+ it('if FF enabledNewWidgetValueFormatting is and some of secondaryAxis is true widget values format must be from seriesOptions', () => {
2362
+ highchartsRenderer.enabledNewWidgetValueFormatting = true;
2363
+ const options = {
2364
+ comboOptions: {
2365
+ seriesOptions: [
2366
+ {series: 'Profit', format: '\"$\"#,###.###' , secondaryAxis: true},
2367
+ ]
2368
+ }
2369
+ }
2370
+ aggregator = highchartsRenderer.rhPivotAggregatorAverage(arg, widget_values_format, is_graph, options, calculated_info);
2371
+ aggregatorObject = aggregator({}, ['Profit'], '');
2372
+ aggregatorObject.push({ DR_Values: 'Profit', Profit: 123 });
2373
+ expect(aggregatorObject.formats).toEqual(['\"$\"#,###.###']);
2374
+ });
2036
2375
  });
2037
2376
 
2038
2377
  describe('Value method', () => {
@@ -2092,6 +2431,22 @@ describe('highcharts_renderer', () => {
2092
2431
  aggregatorObject = aggregator({}, ['Region average'], '');
2093
2432
  expect(aggregatorObject.format(1123.45678, false)).toBe('112345.68%');
2094
2433
  });
2434
+
2435
+ 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', () => {
2436
+ highchartsRenderer.enabledNewWidgetValueFormatting = true;
2437
+ widget_values_format = '\"$\"#,###.###';
2438
+ const options = {
2439
+ comboOptions: {
2440
+ seriesOptions: [
2441
+ {series: 'Profit', format: '\"$\"#,###.###' , secondaryAxis: true},
2442
+ ]
2443
+ }
2444
+ }
2445
+ aggregator = highchartsRenderer.rhPivotAggregatorAverage(arg, widget_values_format, is_graph, options, calculated_info);
2446
+ aggregatorObject = aggregator({}, ['Profit'], '');
2447
+ aggregatorObject.push({ DR_Values: 'Profit', Profit: 123 });
2448
+ expect(aggregatorObject.format(1123.45678, false)).toBe('$1,123.457');
2449
+ });
2095
2450
  });
2096
2451
  });
2097
2452
 
@@ -2173,6 +2528,7 @@ describe('highcharts_renderer', () => {
2173
2528
  });
2174
2529
 
2175
2530
  it('Formats must be filled and uniq', () => {
2531
+ highchartsRenderer.enabledNewWidgetValueFormatting = false;
2176
2532
  aggregatorObject.push({Profit: 123, formats: ['####', '####', '#,###']});
2177
2533
  expect(aggregatorObject.formats).toEqual(['####', '#,###']);
2178
2534
  });
@@ -2219,6 +2575,21 @@ describe('highcharts_renderer', () => {
2219
2575
  aggregatorObject.push({Profit: 20, 'Region average': 'Central', Region: 'Region average'});
2220
2576
  expect(aggregatorObject.ignoreValue).toBe(true);
2221
2577
  });
2578
+
2579
+ it('if FF enabledNewWidgetValueFormatting is and some of secondaryAxis is true widget values format must be from seriesOptions', () => {
2580
+ highchartsRenderer.enabledNewWidgetValueFormatting = true;
2581
+ const options = {
2582
+ comboOptions: {
2583
+ seriesOptions: [
2584
+ {series: 'Profit', format: '\"$\"#,###.###' , secondaryAxis: true},
2585
+ ]
2586
+ }
2587
+ }
2588
+ aggregator = highchartsRenderer.rhPivotAggregatorMin(arg, widget_values_format, is_graph, options, calculated_info);
2589
+ aggregatorObject = aggregator({}, ['Profit'], '');
2590
+ aggregatorObject.push({ DR_Values: 'Profit', Profit: 123 });
2591
+ expect(aggregatorObject.formats).toEqual(['\"$\"#,###.###']);
2592
+ });
2222
2593
  });
2223
2594
 
2224
2595
  describe('Value method', () => {
@@ -2270,6 +2641,22 @@ describe('highcharts_renderer', () => {
2270
2641
  aggregatorObject = aggregator({}, ['Region average'], '');
2271
2642
  expect(aggregatorObject.format(1123.45678, false)).toBe('112345.68%');
2272
2643
  });
2644
+
2645
+ 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', () => {
2646
+ highchartsRenderer.enabledNewWidgetValueFormatting = true;
2647
+ widget_values_format = '\"$\"#,###.###';
2648
+ const options = {
2649
+ comboOptions: {
2650
+ seriesOptions: [
2651
+ {series: 'Profit', format: '\"$\"#,###.###' , secondaryAxis: true},
2652
+ ]
2653
+ }
2654
+ }
2655
+ aggregator = highchartsRenderer.rhPivotAggregatorMin(arg, widget_values_format, is_graph, options, calculated_info);
2656
+ aggregatorObject = aggregator({}, ['Profit'], '');
2657
+ aggregatorObject.push({ DR_Values: 'Profit', Profit: 123 });
2658
+ expect(aggregatorObject.format(1123.45678, false)).toBe('$1,123.457');
2659
+ });
2273
2660
  });
2274
2661
  });
2275
2662
 
@@ -2351,6 +2738,7 @@ describe('highcharts_renderer', () => {
2351
2738
  });
2352
2739
 
2353
2740
  it('Formats must be filled and uniq', () => {
2741
+ highchartsRenderer.enabledNewWidgetValueFormatting = false;
2354
2742
  aggregatorObject.push({Profit: 123, formats: ['####', '####', '#,###']});
2355
2743
  expect(aggregatorObject.formats).toEqual(['####', '#,###']);
2356
2744
  });
@@ -2397,6 +2785,21 @@ describe('highcharts_renderer', () => {
2397
2785
  aggregatorObject.push({Profit: 20, 'Region average': 'Central', Region: 'Region average'});
2398
2786
  expect(aggregatorObject.ignoreValue).toBe(true);
2399
2787
  });
2788
+
2789
+ it('if FF enabledNewWidgetValueFormatting is and some of secondaryAxis is true widget values format must be from seriesOptions', () => {
2790
+ highchartsRenderer.enabledNewWidgetValueFormatting = true;
2791
+ const options = {
2792
+ comboOptions: {
2793
+ seriesOptions: [
2794
+ {series: 'Profit', format: '\"$\"#,###.###' , secondaryAxis: true},
2795
+ ]
2796
+ }
2797
+ }
2798
+ aggregator = highchartsRenderer.rhPivotAggregatorMax(arg, widget_values_format, is_graph, options, calculated_info);
2799
+ aggregatorObject = aggregator({}, ['Profit'], '');
2800
+ aggregatorObject.push({ DR_Values: 'Profit', Profit: 123 });
2801
+ expect(aggregatorObject.formats).toEqual(['\"$\"#,###.###']);
2802
+ });
2400
2803
  });
2401
2804
 
2402
2805
  describe('Value method', () => {
@@ -2448,11 +2851,411 @@ describe('highcharts_renderer', () => {
2448
2851
  aggregatorObject = aggregator({}, ['Region average'], '');
2449
2852
  expect(aggregatorObject.format(1123.45678, false)).toBe('112345.68%');
2450
2853
  });
2854
+
2855
+ 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', () => {
2856
+ highchartsRenderer.enabledNewWidgetValueFormatting = true;
2857
+ widget_values_format = '\"$\"#,###.###';
2858
+ const options = {
2859
+ comboOptions: {
2860
+ seriesOptions: [
2861
+ {series: 'Profit', format: '\"$\"#,###.###' , secondaryAxis: true},
2862
+ ]
2863
+ }
2864
+ }
2865
+ aggregator = highchartsRenderer.rhPivotAggregatorMax(arg, widget_values_format, is_graph, options, calculated_info);
2866
+ aggregatorObject = aggregator({}, ['Profit'], '');
2867
+ aggregatorObject.push({ DR_Values: 'Profit', Profit: 123 });
2868
+ expect(aggregatorObject.format(1123.45678, false)).toBe('$1,123.457');
2869
+ });
2451
2870
  });
2452
2871
  });
2453
2872
  });
2454
2873
  });
2455
2874
 
2875
+ describe('function getDefaultValueForChart', () => {
2876
+ it('should return empty value for rich_text type', () => {
2877
+ expect(highchartsRenderer.getDefaultValueForChart('rich_text', {})).toEqual({});
2878
+ });
2879
+
2880
+ it('should return default value for line-chart type if existing options are empty', () => {
2881
+ const res = highchartsRenderer.getDefaultValueForChart('line-chart', {});
2882
+ expect(Object.keys(res).length).toEqual(highchartsRenderer.chartsData[0].subtypes[0].suboptions.length);
2883
+ });
2884
+ });
2885
+
2886
+ describe('function getCommonChartOptions', () => {
2887
+ const TOOLTIP_DEFAULT_OPTIONS = {
2888
+ borderColor: '#fff',
2889
+ shadow: {
2890
+ color: '#9199b4',
2891
+ width: 10,
2892
+ opacity: 0.05
2893
+ },
2894
+ style: {
2895
+ fontSize: '12',
2896
+ fontFamily: 'Poppins',
2897
+ color: '#545a6b',
2898
+ },
2899
+ enabled: true,
2900
+ };
2901
+
2902
+ it('should return empty object if additionalOptions is null or undefined', () => {
2903
+ expect(highchartsRenderer.getCommonChartOptions(null)).toEqual({});
2904
+ expect(highchartsRenderer.getCommonChartOptions(undefined)).toEqual({});
2905
+ });
2906
+
2907
+ it('should return empty tooltip if additionalOptions has no tooltips', () => {
2908
+ const additionalOptions = { };
2909
+ expect(highchartsRenderer.getCommonChartOptions(additionalOptions)).toEqual({});
2910
+ });
2911
+
2912
+ it('should return tooltip with default options if tooltips.show is not defined', () => {
2913
+ const additionalOptions = { tooltips: {} };
2914
+ const expected = { tooltip: TOOLTIP_DEFAULT_OPTIONS };
2915
+ expect(highchartsRenderer.getCommonChartOptions(additionalOptions)).toEqual(expected);
2916
+ });
2917
+
2918
+ it('should return tooltip with custom style options', () => {
2919
+ const additionalOptions = {
2920
+ tooltips: {
2921
+ show: true,
2922
+ font_size: 14,
2923
+ font_style: 'Arial',
2924
+ font_color: '#333',
2925
+ }
2926
+ };
2927
+ const expected = {
2928
+ tooltip: {
2929
+ borderColor: '#fff',
2930
+ shadow: {
2931
+ color: '#9199b4',
2932
+ width: 10,
2933
+ opacity: 0.05
2934
+ },
2935
+ style: {
2936
+ fontSize: 14,
2937
+ fontFamily: 'Arial',
2938
+ color: '#333',
2939
+ },
2940
+ enabled: true,
2941
+ }
2942
+ };
2943
+ expect(highchartsRenderer.getCommonChartOptions(additionalOptions)).toEqual(expected);
2944
+ });
2945
+
2946
+ it('should return tooltip with custom style options and show set to false', () => {
2947
+ const additionalOptions = {
2948
+ tooltips: {
2949
+ show: false,
2950
+ font_size: 14,
2951
+ font_style: 'Arial',
2952
+ font_color: '#333',
2953
+ }
2954
+ };
2955
+ const expected = {
2956
+ tooltip: {
2957
+ borderColor: '#fff',
2958
+ shadow: {
2959
+ color: '#9199b4',
2960
+ width: 10,
2961
+ opacity: 0.05
2962
+ },
2963
+ style: {
2964
+ fontSize: 14,
2965
+ fontFamily: 'Arial',
2966
+ color: '#333',
2967
+ },
2968
+ enabled: false,
2969
+ }
2970
+ };
2971
+ expect(highchartsRenderer.getCommonChartOptions(additionalOptions)).toEqual(expected);
2972
+ });
2973
+ });
2974
+
2975
+ describe('function getDataLabelsStyle', () => {
2976
+ it('returns default style if additionalOptions is empty', () => {
2977
+ const additionalOptions = {};
2978
+ const defaultStyle = { color: '#333', fontWeight: 'bold' };
2979
+ const expected = defaultStyle;
2980
+ const actual = highchartsRenderer.getDataLabelsStyle(additionalOptions, defaultStyle);
2981
+ expect(actual).toEqual(expected);
2982
+ });
2983
+
2984
+ it('returns default style if additionalOptions does not contain a label option key', () => {
2985
+ const additionalOptions = { backgroundColor: '#fff' };
2986
+ const defaultStyle = { color: '#333', fontWeight: 'bold' };
2987
+ const expected = defaultStyle;
2988
+ const actual = highchartsRenderer.getDataLabelsStyle(additionalOptions, defaultStyle);
2989
+ expect(actual).toEqual(expected);
2990
+ });
2991
+
2992
+ it('returns style merged with defaultStyle if both exist', () => {
2993
+ const additionalOptions = { label_1: { font_size: '16px' } };
2994
+ const defaultStyle = { color: '#333', fontWeight: 'bold' };
2995
+ const expected = { color: '#333', fontWeight: 'bold', fontSize: '16px' };
2996
+ const actual = highchartsRenderer.getDataLabelsStyle(additionalOptions, defaultStyle);
2997
+ expect(actual).toEqual(expected);
2998
+ });
2999
+
3000
+ it('returns style with font size and font family if they exist', () => {
3001
+ const additionalOptions = { label_1: { font_size: '16px', font_style: 'Helvetica' } };
3002
+ const defaultStyle = { color: '#333', fontWeight: 'bold' };
3003
+ const expected = { color: '#333', fontWeight: 'bold', fontSize: '16px', fontFamily: 'Helvetica' };
3004
+ const actual = highchartsRenderer.getDataLabelsStyle(additionalOptions, defaultStyle);
3005
+ expect(actual).toEqual(expected);
3006
+ });
3007
+
3008
+ it('returns style only with font size and font family if defaultStyle has wrong format', () => {
3009
+ const additionalOptions = { label_1: { font_size: '16px', font_style: 'Helvetica' } };
3010
+ const defaultStyle = "{ color: '#333', fontWeight: 'bold' }";
3011
+ const expected = { fontSize: '16px', fontFamily: 'Helvetica' };
3012
+ const actual = highchartsRenderer.getDataLabelsStyle(additionalOptions, defaultStyle);
3013
+ expect(actual).toEqual(expected);
3014
+ });
3015
+
3016
+ it('returns style only with font size and font family if defaultStyle is null', () => {
3017
+ const additionalOptions = { label_1: { font_size: '16px', font_style: 'Helvetica' } };
3018
+ const defaultStyle = null;
3019
+ const expected = { fontSize: '16px', fontFamily: 'Helvetica' };
3020
+ const actual = highchartsRenderer.getDataLabelsStyle(additionalOptions, defaultStyle);
3021
+ expect(actual).toEqual(expected);
3022
+ });
3023
+ });
3024
+
3025
+ describe('function getDataLabelsOptions', () => {
3026
+ const defaultDataLabels = {
3027
+ color: "#151a41",
3028
+ enabled: true,
3029
+ style: {
3030
+ fontFamily: "Poppins",
3031
+ fontSize: "12px",
3032
+ fontWeight: "bold"
3033
+ }
3034
+ };
3035
+
3036
+ it('should return chartOptions with default data label options if additionalOptions is not defined', () => {
3037
+ const chartOptions = {
3038
+ dataLabels: {
3039
+ enabled: true,
3040
+ style: {
3041
+ fontSize: '12px',
3042
+ fontWeight: 'bold',
3043
+ },
3044
+ },
3045
+ };
3046
+ const result = highchartsRenderer.getDataLabelsOptions(undefined, chartOptions);
3047
+ expect(result).toEqual(chartOptions);
3048
+ expect(result.dataLabels).toEqual(defaultDataLabels);
3049
+ });
3050
+
3051
+ it('should return chartOptions with merged data label options if additionalOptions does not contain a label key', () => {
3052
+ const additionalOptions = {
3053
+ option1: 'value1',
3054
+ option2: 'value2',
3055
+ option3: 'value3',
3056
+ };
3057
+ const chartOptions = {
3058
+ dataLabels: {
3059
+ enabled: true,
3060
+ style: {
3061
+ fontSize: '13px',
3062
+ fontWeight: 'normal',
3063
+ },
3064
+ },
3065
+ };
3066
+ const expected = {
3067
+ dataLabels: {
3068
+ color: "#151a41",
3069
+ enabled: true,
3070
+ style: {
3071
+ fontFamily: "Poppins",
3072
+ fontSize: "13px",
3073
+ fontWeight: "normal"
3074
+ }
3075
+ }
3076
+ };
3077
+ const result = highchartsRenderer.getDataLabelsOptions(additionalOptions, chartOptions);
3078
+ expect(result).toEqual(expected);
3079
+ });
3080
+
3081
+ it('should return chartOptions with merged data label options if additionalOptions contains a label key', () => {
3082
+ const additionalOptions = {
3083
+ label_option: {
3084
+ font_color: 'red',
3085
+ },
3086
+ };
3087
+ const chartOptions = {
3088
+ dataLabels: {
3089
+ enabled: true,
3090
+ style: {
3091
+ fontSize: '15px',
3092
+ fontWeight: 'bold',
3093
+ },
3094
+ },
3095
+ };
3096
+ const expected = {
3097
+ dataLabels: {
3098
+ color: "red",
3099
+ enabled: true,
3100
+ style: {
3101
+ fontFamily: "Poppins",
3102
+ fontSize: "15px",
3103
+ fontWeight: "bold"
3104
+ }
3105
+ }
3106
+ };
3107
+ const result = highchartsRenderer.getDataLabelsOptions(additionalOptions, chartOptions);
3108
+ expect(result).toEqual(expected);
3109
+ });
3110
+ });
3111
+
3112
+ describe('function getLabelOptionKey', () => {
3113
+ it('should return null if additionalOptions is not defined', () => {
3114
+ const result = highchartsRenderer.getLabelOptionKey(undefined);
3115
+ expect(result).toBeNull();
3116
+ });
3117
+
3118
+ it('should return null if no label key is found in additionalOptions', () => {
3119
+ const additionalOptions = {
3120
+ option1: 'value1',
3121
+ option2: 'value2',
3122
+ option3: 'value3',
3123
+ };
3124
+ const result = highchartsRenderer.getLabelOptionKey(additionalOptions);
3125
+ expect(result).toBeNull();
3126
+ });
3127
+
3128
+ it('should return the label key if found in additionalOptions', () => {
3129
+ const additionalOptions = {
3130
+ option1: 'value1',
3131
+ label_option: 'value2',
3132
+ option3: 'value3',
3133
+ };
3134
+ const result = highchartsRenderer.getLabelOptionKey(additionalOptions);
3135
+ expect(result).toBe('label_option');
3136
+ });
3137
+
3138
+ it('should return the first label key if multiple label keys are found in additionalOptions', () => {
3139
+ const additionalOptions = {
3140
+ label_option1: 'value1',
3141
+ option1: 'value2',
3142
+ label_option2: 'value3',
3143
+ };
3144
+ const result = highchartsRenderer.getLabelOptionKey(additionalOptions);
3145
+ expect(result).toBe('label_option1');
3146
+ });
3147
+ });
3148
+
3149
+ describe('function getDefaultValueForSubOptions', () => {
3150
+ const suboptions = {
3151
+ option1: {
3152
+ category_type: 'type1',
3153
+ elements: [
3154
+ {
3155
+ value_name: 'value1',
3156
+ element_type: 'text',
3157
+ default_value: 'default1',
3158
+ },
3159
+ {
3160
+ value_name: 'value2',
3161
+ element_type: 'number',
3162
+ default_value: 42,
3163
+ },
3164
+ {
3165
+ value_name: 'value3',
3166
+ element_type: 'devider',
3167
+ },
3168
+ ],
3169
+ },
3170
+ option2: {
3171
+ category_type: 'type2',
3172
+ elements: [
3173
+ {
3174
+ value_name: 'value1',
3175
+ element_type: 'text',
3176
+ default_value: 'default2',
3177
+ },
3178
+ {
3179
+ value_name: 'value2',
3180
+ element_type: 'number',
3181
+ default_value: 23,
3182
+ },
3183
+ {
3184
+ value_name: 'value3',
3185
+ element_type: 'devider',
3186
+ },
3187
+ ],
3188
+ },
3189
+ option3: {
3190
+ category_type: 'type3',
3191
+ elements: [
3192
+ {
3193
+ value_name: 'value1',
3194
+ element_type: 'text',
3195
+ default_value: { val: 1 },
3196
+ }
3197
+ ],
3198
+ },
3199
+ };
3200
+ let tempSubOptions = null;
3201
+
3202
+ beforeAll(() => {
3203
+ tempSubOptions = highchartsRenderer.suboptions;
3204
+ highchartsRenderer.suboptions = suboptions;
3205
+ });
3206
+
3207
+ afterAll(() => {
3208
+ highchartsRenderer.suboptions = tempSubOptions;
3209
+ });
3210
+
3211
+ it('should return an empty object if option type is not found', () => {
3212
+ const type = 'invalid_type';
3213
+ const existing_options = {};
3214
+ const result = highchartsRenderer.getDefaultValueForSubOptions(type, existing_options);
3215
+ expect(result).toEqual({});
3216
+ });
3217
+
3218
+ it('should return default values for all elements in suboption', () => {
3219
+ const type = 'type1';
3220
+ const existing_options = {};
3221
+ const result = highchartsRenderer.getDefaultValueForSubOptions(type, existing_options);
3222
+ expect(result).toEqual({
3223
+ value1: 'default1',
3224
+ value2: 42,
3225
+ });
3226
+ });
3227
+
3228
+ it('should use existing options if available', () => {
3229
+ const type = 'type1';
3230
+ const existing_options = {
3231
+ type1: {
3232
+ value1: 'existing1',
3233
+ value2: 99,
3234
+ },
3235
+ };
3236
+ const result = highchartsRenderer.getDefaultValueForSubOptions(type, existing_options);
3237
+ expect(result).toEqual({
3238
+ value1: 'existing1',
3239
+ value2: 99,
3240
+ });
3241
+ });
3242
+
3243
+ it('should ignore elements with type "devider"', () => {
3244
+ const type = 'type1';
3245
+ const existing_options = {};
3246
+ const result = highchartsRenderer.getDefaultValueForSubOptions(type, existing_options);
3247
+ expect(result).not.toHaveProperty('value3');
3248
+ });
3249
+
3250
+ it('should clone default value if it is an object', () => {
3251
+ const type = 'type3';
3252
+ const existing_options = {};
3253
+ const result = highchartsRenderer.getDefaultValueForSubOptions(type, existing_options);
3254
+ expect(result.value1).toEqual(suboptions.option3.elements[0].default_value);
3255
+ expect(result.value1).not.toBe(suboptions.option3.elements[0].default_value);
3256
+ });
3257
+ });
3258
+
2456
3259
  describe('function getChartAxisLabel', () => {
2457
3260
  it('should return default value', () => {
2458
3261
  expect(highchartsRenderer.getChartAxisLabel('invalidType')).toBe('Axis (Category)')
@@ -3649,4 +4452,144 @@ describe('highcharts_renderer', () => {
3649
4452
  expect(highchartsRenderer.getTrendSeriesName(series)).toBe(expectedName);
3650
4453
  });
3651
4454
  });
4455
+
4456
+ describe('function checkFormats', () => {
4457
+ it('should correctly detect if any series is on secondary axis', () => {
4458
+ const render_options = {
4459
+ comboOptions: {
4460
+ seriesOptions: [
4461
+ { secondaryAxis: false },
4462
+ { secondaryAxis: true },
4463
+ { secondaryAxis: false },
4464
+ ],
4465
+ },
4466
+ };
4467
+ const widget_values_format = '#,###';
4468
+ const result = highchartsRenderer.checkFormats(render_options, widget_values_format);
4469
+ expect(result.isSecondaryAxis).toBe(true);
4470
+ });
4471
+
4472
+ it('should correctly detect if all series are on primary axis', () => {
4473
+ const render_options = {
4474
+ comboOptions: {
4475
+ seriesOptions: [
4476
+ { secondaryAxis: false },
4477
+ { secondaryAxis: false },
4478
+ { secondaryAxis: false },
4479
+ ],
4480
+ },
4481
+ };
4482
+ const widget_values_format = '#,###';
4483
+ const result = highchartsRenderer.checkFormats(render_options, widget_values_format);
4484
+ expect(result.isSecondaryAxis).toBe(false);
4485
+ });
4486
+
4487
+ it('should correctly detect if the given format is custom', () => {
4488
+ const render_options = {
4489
+ comboOptions: {
4490
+ seriesOptions: [
4491
+ { format: '#,###' },
4492
+ { format: '#,###' },
4493
+ { format: '#,###' },
4494
+ ],
4495
+ },
4496
+ };
4497
+ const widget_values_format = '$#,###.###';
4498
+ const result = highchartsRenderer.checkFormats(render_options, widget_values_format);
4499
+ expect(result.isCustomFormat).toBe(true);
4500
+ });
4501
+
4502
+ it('should correctly detect if the given format is not custom', () => {
4503
+ const render_options = {
4504
+ comboOptions: {
4505
+ seriesOptions: [
4506
+ { format: '$#,###' },
4507
+ { format: '$#,###.#' },
4508
+ { format: '$#,###.##' },
4509
+ ],
4510
+ },
4511
+ };
4512
+ const widget_values_format = '$#,###';
4513
+ const result = highchartsRenderer.checkFormats(render_options, widget_values_format);
4514
+ expect(result.isCustomFormat).toBe(false);
4515
+ });
4516
+ });
4517
+
4518
+ describe('function isCustomValuesFormat', () => {
4519
+ const render_options = {
4520
+ comboOptions: {
4521
+ seriesOptions: [
4522
+ { series: 'Profit', format: '#,###', secondaryAxis: false },
4523
+ { series: 'Sales', format: '#,###', secondaryAxis: true },
4524
+ ]
4525
+ }
4526
+ };
4527
+
4528
+ it('should return true if new widget value formatting is enabled and the format is custom or there is no secondary axis', () => {
4529
+ const widget_values_format = '$####.##';
4530
+
4531
+ highchartsRenderer.enabledNewWidgetValueFormatting = true;
4532
+
4533
+ const expectedValue = true;
4534
+
4535
+ const result = highchartsRenderer.isCustomValuesFormat(render_options, widget_values_format);
4536
+
4537
+ expect(result).toEqual(expectedValue);
4538
+ });
4539
+
4540
+ it('should return false if new widget value formatting is disabled', () => {
4541
+ const widget_values_format = '#,###';
4542
+
4543
+ highchartsRenderer.enabledNewWidgetValueFormatting = false;
4544
+
4545
+ const expectedValue = false;
4546
+
4547
+ const result = highchartsRenderer.isCustomValuesFormat(render_options, widget_values_format);
4548
+
4549
+ expect(result).toEqual(expectedValue);
4550
+ });
4551
+
4552
+ it('should return false if the format is not custom and there is a secondary axis', () => {
4553
+ const widget_values_format = '#,###';
4554
+
4555
+ highchartsRenderer.enabledNewWidgetValueFormatting = true;
4556
+
4557
+ const expectedValue = false;
4558
+
4559
+ const result = highchartsRenderer.isCustomValuesFormat(render_options, widget_values_format);
4560
+
4561
+ expect(result).toEqual(expectedValue);
4562
+ });
4563
+ });
4564
+
4565
+ describe('getRecordFormats', () => {
4566
+ const render_options = {
4567
+ comboOptions: {
4568
+ seriesOptions: [
4569
+ { series: 'Profit', format: '$####.#', secondaryAxis: false },
4570
+ { series: 'Sales', format: '$####.##', secondaryAxis: true },
4571
+ ]
4572
+ }
4573
+ };
4574
+
4575
+ it('should return an array of formats for the given record name', () => {
4576
+ const recordName = 'Profit';
4577
+
4578
+ const expectedValue = ['$####.#'];
4579
+
4580
+ const result = highchartsRenderer.getRecordFormats(render_options, recordName);
4581
+
4582
+ expect(result).toEqual(expectedValue);
4583
+ });
4584
+
4585
+ it('should return an empty array if there are no matching records', () => {
4586
+ const recordName = 'Any';
4587
+
4588
+ const expectedValue = [];
4589
+
4590
+ const result = highchartsRenderer.getRecordFormats(render_options, recordName);
4591
+
4592
+ expect(result).toEqual(expectedValue);
4593
+ });
4594
+ });
3652
4595
  });