@datarailsshared/dr_renderer 1.2.309 → 1.2.311
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.
package/package.json
CHANGED
@@ -1323,6 +1323,264 @@ describe('highcharts_renderer', () => {
|
|
1323
1323
|
});
|
1324
1324
|
});
|
1325
1325
|
|
1326
|
+
describe("function updateBackwardCompatibleWidgetOptions", () => {
|
1327
|
+
it("should delete chart 'hideLegends' option if exists and true", () => {
|
1328
|
+
const options = {
|
1329
|
+
chartOptions: {
|
1330
|
+
chart: {
|
1331
|
+
hideLegends: true
|
1332
|
+
}
|
1333
|
+
},
|
1334
|
+
comboOptions: {}
|
1335
|
+
};
|
1336
|
+
highchartsRenderer.updateBackwardCompatibleWidgetOptions(options, 'line-chart')
|
1337
|
+
expect(options.chartOptions.legends_position.value).toBe('none');
|
1338
|
+
expect(options.chartOptions.chart.hideLegends).toBe(undefined);
|
1339
|
+
});
|
1340
|
+
|
1341
|
+
it("should move error_policy chart option to advanced chart option", () => {
|
1342
|
+
const error_policy = 'test_policy';
|
1343
|
+
const options = {
|
1344
|
+
chartOptions: {
|
1345
|
+
error_policy: {
|
1346
|
+
error_policy: error_policy
|
1347
|
+
}
|
1348
|
+
},
|
1349
|
+
comboOptions: {}
|
1350
|
+
};
|
1351
|
+
highchartsRenderer.updateBackwardCompatibleWidgetOptions(options, 'line-chart')
|
1352
|
+
expect(options.chartOptions.advanced.from_latest).toBe('');
|
1353
|
+
expect(options.chartOptions.advanced.error_policy).toBe(error_policy);
|
1354
|
+
expect(options.chartOptions.error_policy).toBe(undefined);
|
1355
|
+
expect(options.chartOptions.from_version).toBe(undefined);
|
1356
|
+
});
|
1357
|
+
|
1358
|
+
it("should move from_version chart option to advanced chart option", () => {
|
1359
|
+
const from_version = 'from_version';
|
1360
|
+
const options = {
|
1361
|
+
chartOptions: {
|
1362
|
+
from_version: {
|
1363
|
+
value: from_version
|
1364
|
+
}
|
1365
|
+
},
|
1366
|
+
comboOptions: {}
|
1367
|
+
};
|
1368
|
+
highchartsRenderer.updateBackwardCompatibleWidgetOptions(options, 'line-chart')
|
1369
|
+
expect(options.chartOptions.advanced.from_latest).toBe(from_version);
|
1370
|
+
expect(options.chartOptions.advanced.error_policy).toBe('None');
|
1371
|
+
expect(options.chartOptions.error_policy).toBe(undefined);
|
1372
|
+
expect(options.chartOptions.from_version).toBe(undefined);
|
1373
|
+
});
|
1374
|
+
|
1375
|
+
it("should remove chart label style option", () => {
|
1376
|
+
const options = {
|
1377
|
+
chartOptions: {
|
1378
|
+
label: {
|
1379
|
+
style: 'color: red;'
|
1380
|
+
}
|
1381
|
+
},
|
1382
|
+
comboOptions: {}
|
1383
|
+
};
|
1384
|
+
highchartsRenderer.updateBackwardCompatibleWidgetOptions(options, 'line-chart')
|
1385
|
+
expect(options.chartOptions.label.style).toBe(undefined);
|
1386
|
+
});
|
1387
|
+
|
1388
|
+
it("should remove chart label_pie style option", () => {
|
1389
|
+
const options = {
|
1390
|
+
chartOptions: {
|
1391
|
+
label_pie: {
|
1392
|
+
style: 'color: red;'
|
1393
|
+
}
|
1394
|
+
},
|
1395
|
+
comboOptions: {}
|
1396
|
+
};
|
1397
|
+
highchartsRenderer.updateBackwardCompatibleWidgetOptions(options, 'line-chart')
|
1398
|
+
expect(options.chartOptions.label_pie.style).toBe(undefined);
|
1399
|
+
});
|
1400
|
+
|
1401
|
+
it("update pie-chart label options if only_value", () => {
|
1402
|
+
const options = {
|
1403
|
+
chartOptions: {
|
1404
|
+
label: {
|
1405
|
+
only_value: true
|
1406
|
+
}
|
1407
|
+
},
|
1408
|
+
comboOptions: {}
|
1409
|
+
};
|
1410
|
+
highchartsRenderer.updateBackwardCompatibleWidgetOptions(options, 'pie-chart')
|
1411
|
+
expect(options.chartOptions.label_pie).toEqual({
|
1412
|
+
show_percentage_in_labels: false,
|
1413
|
+
show_value_in_labels: true
|
1414
|
+
});
|
1415
|
+
expect(options.chartOptions.label).toBe(undefined);
|
1416
|
+
});
|
1417
|
+
|
1418
|
+
it("update pie-chart label options if only_percentage", () => {
|
1419
|
+
const options = {
|
1420
|
+
chartOptions: {
|
1421
|
+
label: {
|
1422
|
+
only_percentage: true
|
1423
|
+
}
|
1424
|
+
},
|
1425
|
+
comboOptions: {}
|
1426
|
+
};
|
1427
|
+
highchartsRenderer.updateBackwardCompatibleWidgetOptions(options, 'pie-chart')
|
1428
|
+
expect(options.chartOptions.label_pie).toEqual({
|
1429
|
+
show_percentage_in_labels: true,
|
1430
|
+
show_value_in_labels: false
|
1431
|
+
});
|
1432
|
+
expect(options.chartOptions.label).toBe(undefined);
|
1433
|
+
});
|
1434
|
+
|
1435
|
+
it("update pie-chart label options if show", () => {
|
1436
|
+
const options = {
|
1437
|
+
chartOptions: {
|
1438
|
+
label: {
|
1439
|
+
show: true
|
1440
|
+
}
|
1441
|
+
},
|
1442
|
+
comboOptions: {}
|
1443
|
+
};
|
1444
|
+
highchartsRenderer.updateBackwardCompatibleWidgetOptions(options, 'pie-chart');
|
1445
|
+
expect(options.chartOptions.label_pie).toEqual({
|
1446
|
+
show: true,
|
1447
|
+
show_percentage_in_labels: true,
|
1448
|
+
show_value_in_labels: true
|
1449
|
+
});
|
1450
|
+
expect(options.chartOptions.label).toBe(undefined);
|
1451
|
+
});
|
1452
|
+
|
1453
|
+
it("should do nothing if pie chart without 'only_percentage/only_value/show'", () => {
|
1454
|
+
const options1 = {
|
1455
|
+
chartOptions: { label: { } }, comboOptions: {}
|
1456
|
+
};
|
1457
|
+
const options2 = {
|
1458
|
+
chartOptions: { }, comboOptions: {}
|
1459
|
+
};
|
1460
|
+
|
1461
|
+
highchartsRenderer.updateBackwardCompatibleWidgetOptions(options1, 'pie-chart');
|
1462
|
+
expect(options1).toEqual({
|
1463
|
+
chartOptions: { label_pie: {} }, comboOptions: {}
|
1464
|
+
});
|
1465
|
+
highchartsRenderer.updateBackwardCompatibleWidgetOptions(options2, 'pie-chart');
|
1466
|
+
expect(options2).toEqual({
|
1467
|
+
chartOptions: { }, comboOptions: {}
|
1468
|
+
});
|
1469
|
+
});
|
1470
|
+
|
1471
|
+
it("should create comboOptions for different series types", () => {
|
1472
|
+
const options = {
|
1473
|
+
chartOptions: {
|
1474
|
+
delta_column: {
|
1475
|
+
field: 'series',
|
1476
|
+
name: 'TEST_test',
|
1477
|
+
same_yaxis: true,
|
1478
|
+
is_percentage: true,
|
1479
|
+
}
|
1480
|
+
}
|
1481
|
+
};
|
1482
|
+
|
1483
|
+
const seriesTypes = ['line', 'spline', 'area', 'areaspline', 'scatter', 'column', 'default'];
|
1484
|
+
const seriesTypesMap = ['line-chart', 'line-chart-smooth', 'area-chart', 'area-chart-smooth', 'scatter-chart', 'column-chart', 'scatter-chart'];
|
1485
|
+
|
1486
|
+
seriesTypes.forEach((type, index) => {
|
1487
|
+
const currentOptions = lodash.cloneDeep(options);
|
1488
|
+
currentOptions.chartOptions.delta_column.chart = type;
|
1489
|
+
highchartsRenderer.updateBackwardCompatibleWidgetOptions(currentOptions, null);
|
1490
|
+
expect(currentOptions.comboOptions).toEqual({
|
1491
|
+
secondaryAxisSettings: {
|
1492
|
+
name: 'TESTtest',
|
1493
|
+
max: null,
|
1494
|
+
min: null,
|
1495
|
+
is_percentage: true
|
1496
|
+
},
|
1497
|
+
seriesOptions: [{
|
1498
|
+
series: 'TEST_test',
|
1499
|
+
secondaryAxis: false,
|
1500
|
+
chartType: seriesTypesMap[index]
|
1501
|
+
}]
|
1502
|
+
});
|
1503
|
+
});
|
1504
|
+
});
|
1505
|
+
|
1506
|
+
it("should create comboOptions without series options if no delta_column field", () => {
|
1507
|
+
const options = {};
|
1508
|
+
highchartsRenderer.updateBackwardCompatibleWidgetOptions(options, null);
|
1509
|
+
expect(options).toEqual({
|
1510
|
+
comboOptions :{
|
1511
|
+
secondaryAxisSettings: {
|
1512
|
+
name: 'Secondary Axis',
|
1513
|
+
max: null,
|
1514
|
+
min: null,
|
1515
|
+
is_percentage: false,
|
1516
|
+
},
|
1517
|
+
seriesOptions: []
|
1518
|
+
}
|
1519
|
+
});
|
1520
|
+
});
|
1521
|
+
});
|
1522
|
+
|
1523
|
+
describe("function setMissingWidgetOptions", () => {
|
1524
|
+
it("should return do nothing if there are no chartOptions", () => {
|
1525
|
+
const options = { testProp: true };
|
1526
|
+
highchartsRenderer.setMissingWidgetOptions(options, null)
|
1527
|
+
expect(options).toEqual({ testProp: true });
|
1528
|
+
});
|
1529
|
+
|
1530
|
+
it("should merge current chart options with default", () => {
|
1531
|
+
spyOn(highchartsRenderer, 'getDefaultValueForChart').and.returnValue({
|
1532
|
+
array: [1, 3, 5],
|
1533
|
+
newProp: 'defaultNew',
|
1534
|
+
existingProp: 'defaultExist',
|
1535
|
+
obj: {
|
1536
|
+
newProp: 'defaultNew',
|
1537
|
+
existingProp: 'defaultExist',
|
1538
|
+
},
|
1539
|
+
newObj: {
|
1540
|
+
newProp: 'defaultNew',
|
1541
|
+
}
|
1542
|
+
});
|
1543
|
+
const options = {
|
1544
|
+
chartOptions: {
|
1545
|
+
array: [2, 5, 6],
|
1546
|
+
existingProp: 'exist',
|
1547
|
+
obj: {
|
1548
|
+
existingProp: 'exist',
|
1549
|
+
}
|
1550
|
+
}
|
1551
|
+
};
|
1552
|
+
highchartsRenderer.setMissingWidgetOptions(options, 'line-chart')
|
1553
|
+
expect(options.chartOptions).toEqual({
|
1554
|
+
array: [2, 5, 6],
|
1555
|
+
existingProp: "exist",
|
1556
|
+
newObj: { newProp: "defaultNew" },
|
1557
|
+
newProp: "defaultNew",
|
1558
|
+
obj: {
|
1559
|
+
existingProp: "exist",
|
1560
|
+
newProp: "defaultNew"
|
1561
|
+
}
|
1562
|
+
});
|
1563
|
+
});
|
1564
|
+
});
|
1565
|
+
|
1566
|
+
describe('function getChartOptionsBySubType', () => {
|
1567
|
+
it('returns null for rich_text subtype', () => {
|
1568
|
+
const result = highchartsRenderer.getChartOptionsBySubType('rich_text');
|
1569
|
+
expect(result).toBe(highchartsRenderer.richTextSubType);
|
1570
|
+
});
|
1571
|
+
|
1572
|
+
it('returns chart options for existing subtype', () => {
|
1573
|
+
const result = highchartsRenderer.getChartOptionsBySubType('line-chart');
|
1574
|
+
expect(result.type).toEqual('line-chart');
|
1575
|
+
expect(result.suboptions.length).toEqual(highchartsRenderer.chartsData[0].subtypes[0].suboptions.length);
|
1576
|
+
});
|
1577
|
+
|
1578
|
+
it('returns null for non-existing subtype', () => {
|
1579
|
+
const result = highchartsRenderer.getChartOptionsBySubType('nonExistingType');
|
1580
|
+
expect(result).toBe(null);
|
1581
|
+
});
|
1582
|
+
});
|
1583
|
+
|
1326
1584
|
describe('function aggregators', () => {
|
1327
1585
|
const aggregatorsIds = ['SUM', 'COUNT', 'COUNT_UNIQUE', 'UNIQUE_VALUES', 'AVG', 'MIN', 'MAX'];
|
1328
1586
|
|
@@ -2453,6 +2711,390 @@ describe('highcharts_renderer', () => {
|
|
2453
2711
|
});
|
2454
2712
|
});
|
2455
2713
|
|
2714
|
+
describe('function getDefaultValueForChart', () => {
|
2715
|
+
it('should return empty value for rich_text type', () => {
|
2716
|
+
expect(highchartsRenderer.getDefaultValueForChart('rich_text', {})).toEqual({});
|
2717
|
+
});
|
2718
|
+
|
2719
|
+
it('should return default value for line-chart type if existing options are empty', () => {
|
2720
|
+
const res = highchartsRenderer.getDefaultValueForChart('line-chart', {});
|
2721
|
+
expect(Object.keys(res).length).toEqual(highchartsRenderer.chartsData[0].subtypes[0].suboptions.length);
|
2722
|
+
});
|
2723
|
+
});
|
2724
|
+
|
2725
|
+
describe('function getCommonChartOptions', () => {
|
2726
|
+
const TOOLTIP_DEFAULT_OPTIONS = {
|
2727
|
+
borderColor: '#fff',
|
2728
|
+
shadow: {
|
2729
|
+
color: '#9199b4',
|
2730
|
+
width: 10,
|
2731
|
+
opacity: 0.05
|
2732
|
+
},
|
2733
|
+
style: {
|
2734
|
+
fontSize: '12',
|
2735
|
+
fontFamily: 'Poppins',
|
2736
|
+
color: '#545a6b',
|
2737
|
+
},
|
2738
|
+
enabled: true,
|
2739
|
+
};
|
2740
|
+
|
2741
|
+
it('should return empty object if additionalOptions is null or undefined', () => {
|
2742
|
+
expect(highchartsRenderer.getCommonChartOptions(null)).toEqual({});
|
2743
|
+
expect(highchartsRenderer.getCommonChartOptions(undefined)).toEqual({});
|
2744
|
+
});
|
2745
|
+
|
2746
|
+
it('should return empty tooltip if additionalOptions has no tooltips', () => {
|
2747
|
+
const additionalOptions = { };
|
2748
|
+
expect(highchartsRenderer.getCommonChartOptions(additionalOptions)).toEqual({});
|
2749
|
+
});
|
2750
|
+
|
2751
|
+
it('should return tooltip with default options if tooltips.show is not defined', () => {
|
2752
|
+
const additionalOptions = { tooltips: {} };
|
2753
|
+
const expected = { tooltip: TOOLTIP_DEFAULT_OPTIONS };
|
2754
|
+
expect(highchartsRenderer.getCommonChartOptions(additionalOptions)).toEqual(expected);
|
2755
|
+
});
|
2756
|
+
|
2757
|
+
it('should return tooltip with custom style options', () => {
|
2758
|
+
const additionalOptions = {
|
2759
|
+
tooltips: {
|
2760
|
+
show: true,
|
2761
|
+
font_size: 14,
|
2762
|
+
font_style: 'Arial',
|
2763
|
+
font_color: '#333',
|
2764
|
+
}
|
2765
|
+
};
|
2766
|
+
const expected = {
|
2767
|
+
tooltip: {
|
2768
|
+
borderColor: '#fff',
|
2769
|
+
shadow: {
|
2770
|
+
color: '#9199b4',
|
2771
|
+
width: 10,
|
2772
|
+
opacity: 0.05
|
2773
|
+
},
|
2774
|
+
style: {
|
2775
|
+
fontSize: 14,
|
2776
|
+
fontFamily: 'Arial',
|
2777
|
+
color: '#333',
|
2778
|
+
},
|
2779
|
+
enabled: true,
|
2780
|
+
}
|
2781
|
+
};
|
2782
|
+
expect(highchartsRenderer.getCommonChartOptions(additionalOptions)).toEqual(expected);
|
2783
|
+
});
|
2784
|
+
|
2785
|
+
it('should return tooltip with custom style options and show set to false', () => {
|
2786
|
+
const additionalOptions = {
|
2787
|
+
tooltips: {
|
2788
|
+
show: false,
|
2789
|
+
font_size: 14,
|
2790
|
+
font_style: 'Arial',
|
2791
|
+
font_color: '#333',
|
2792
|
+
}
|
2793
|
+
};
|
2794
|
+
const expected = {
|
2795
|
+
tooltip: {
|
2796
|
+
borderColor: '#fff',
|
2797
|
+
shadow: {
|
2798
|
+
color: '#9199b4',
|
2799
|
+
width: 10,
|
2800
|
+
opacity: 0.05
|
2801
|
+
},
|
2802
|
+
style: {
|
2803
|
+
fontSize: 14,
|
2804
|
+
fontFamily: 'Arial',
|
2805
|
+
color: '#333',
|
2806
|
+
},
|
2807
|
+
enabled: false,
|
2808
|
+
}
|
2809
|
+
};
|
2810
|
+
expect(highchartsRenderer.getCommonChartOptions(additionalOptions)).toEqual(expected);
|
2811
|
+
});
|
2812
|
+
});
|
2813
|
+
|
2814
|
+
describe('function getDataLabelsStyle', () => {
|
2815
|
+
it('returns default style if additionalOptions is empty', () => {
|
2816
|
+
const additionalOptions = {};
|
2817
|
+
const defaultStyle = { color: '#333', fontWeight: 'bold' };
|
2818
|
+
const expected = defaultStyle;
|
2819
|
+
const actual = highchartsRenderer.getDataLabelsStyle(additionalOptions, defaultStyle);
|
2820
|
+
expect(actual).toEqual(expected);
|
2821
|
+
});
|
2822
|
+
|
2823
|
+
it('returns default style if additionalOptions does not contain a label option key', () => {
|
2824
|
+
const additionalOptions = { backgroundColor: '#fff' };
|
2825
|
+
const defaultStyle = { color: '#333', fontWeight: 'bold' };
|
2826
|
+
const expected = defaultStyle;
|
2827
|
+
const actual = highchartsRenderer.getDataLabelsStyle(additionalOptions, defaultStyle);
|
2828
|
+
expect(actual).toEqual(expected);
|
2829
|
+
});
|
2830
|
+
|
2831
|
+
it('returns style merged with defaultStyle if both exist', () => {
|
2832
|
+
const additionalOptions = { label_1: { font_size: '16px' } };
|
2833
|
+
const defaultStyle = { color: '#333', fontWeight: 'bold' };
|
2834
|
+
const expected = { color: '#333', fontWeight: 'bold', fontSize: '16px' };
|
2835
|
+
const actual = highchartsRenderer.getDataLabelsStyle(additionalOptions, defaultStyle);
|
2836
|
+
expect(actual).toEqual(expected);
|
2837
|
+
});
|
2838
|
+
|
2839
|
+
it('returns style with font size and font family if they exist', () => {
|
2840
|
+
const additionalOptions = { label_1: { font_size: '16px', font_style: 'Helvetica' } };
|
2841
|
+
const defaultStyle = { color: '#333', fontWeight: 'bold' };
|
2842
|
+
const expected = { color: '#333', fontWeight: 'bold', fontSize: '16px', fontFamily: 'Helvetica' };
|
2843
|
+
const actual = highchartsRenderer.getDataLabelsStyle(additionalOptions, defaultStyle);
|
2844
|
+
expect(actual).toEqual(expected);
|
2845
|
+
});
|
2846
|
+
|
2847
|
+
it('returns style only with font size and font family if defaultStyle has wrong format', () => {
|
2848
|
+
const additionalOptions = { label_1: { font_size: '16px', font_style: 'Helvetica' } };
|
2849
|
+
const defaultStyle = "{ color: '#333', fontWeight: 'bold' }";
|
2850
|
+
const expected = { fontSize: '16px', fontFamily: 'Helvetica' };
|
2851
|
+
const actual = highchartsRenderer.getDataLabelsStyle(additionalOptions, defaultStyle);
|
2852
|
+
expect(actual).toEqual(expected);
|
2853
|
+
});
|
2854
|
+
|
2855
|
+
it('returns style only with font size and font family if defaultStyle is null', () => {
|
2856
|
+
const additionalOptions = { label_1: { font_size: '16px', font_style: 'Helvetica' } };
|
2857
|
+
const defaultStyle = null;
|
2858
|
+
const expected = { fontSize: '16px', fontFamily: 'Helvetica' };
|
2859
|
+
const actual = highchartsRenderer.getDataLabelsStyle(additionalOptions, defaultStyle);
|
2860
|
+
expect(actual).toEqual(expected);
|
2861
|
+
});
|
2862
|
+
});
|
2863
|
+
|
2864
|
+
describe('function getDataLabelsOptions', () => {
|
2865
|
+
const defaultDataLabels = {
|
2866
|
+
color: "#151a41",
|
2867
|
+
enabled: true,
|
2868
|
+
style: {
|
2869
|
+
fontFamily: "Poppins",
|
2870
|
+
fontSize: "12px",
|
2871
|
+
fontWeight: "bold"
|
2872
|
+
}
|
2873
|
+
};
|
2874
|
+
|
2875
|
+
it('should return chartOptions with default data label options if additionalOptions is not defined', () => {
|
2876
|
+
const chartOptions = {
|
2877
|
+
dataLabels: {
|
2878
|
+
enabled: true,
|
2879
|
+
style: {
|
2880
|
+
fontSize: '12px',
|
2881
|
+
fontWeight: 'bold',
|
2882
|
+
},
|
2883
|
+
},
|
2884
|
+
};
|
2885
|
+
const result = highchartsRenderer.getDataLabelsOptions(undefined, chartOptions);
|
2886
|
+
expect(result).toEqual(chartOptions);
|
2887
|
+
expect(result.dataLabels).toEqual(defaultDataLabels);
|
2888
|
+
});
|
2889
|
+
|
2890
|
+
it('should return chartOptions with merged data label options if additionalOptions does not contain a label key', () => {
|
2891
|
+
const additionalOptions = {
|
2892
|
+
option1: 'value1',
|
2893
|
+
option2: 'value2',
|
2894
|
+
option3: 'value3',
|
2895
|
+
};
|
2896
|
+
const chartOptions = {
|
2897
|
+
dataLabels: {
|
2898
|
+
enabled: true,
|
2899
|
+
style: {
|
2900
|
+
fontSize: '13px',
|
2901
|
+
fontWeight: 'normal',
|
2902
|
+
},
|
2903
|
+
},
|
2904
|
+
};
|
2905
|
+
const expected = {
|
2906
|
+
dataLabels: {
|
2907
|
+
color: "#151a41",
|
2908
|
+
enabled: true,
|
2909
|
+
style: {
|
2910
|
+
fontFamily: "Poppins",
|
2911
|
+
fontSize: "13px",
|
2912
|
+
fontWeight: "normal"
|
2913
|
+
}
|
2914
|
+
}
|
2915
|
+
};
|
2916
|
+
const result = highchartsRenderer.getDataLabelsOptions(additionalOptions, chartOptions);
|
2917
|
+
expect(result).toEqual(expected);
|
2918
|
+
});
|
2919
|
+
|
2920
|
+
it('should return chartOptions with merged data label options if additionalOptions contains a label key', () => {
|
2921
|
+
const additionalOptions = {
|
2922
|
+
label_option: {
|
2923
|
+
font_color: 'red',
|
2924
|
+
},
|
2925
|
+
};
|
2926
|
+
const chartOptions = {
|
2927
|
+
dataLabels: {
|
2928
|
+
enabled: true,
|
2929
|
+
style: {
|
2930
|
+
fontSize: '15px',
|
2931
|
+
fontWeight: 'bold',
|
2932
|
+
},
|
2933
|
+
},
|
2934
|
+
};
|
2935
|
+
const expected = {
|
2936
|
+
dataLabels: {
|
2937
|
+
color: "red",
|
2938
|
+
enabled: true,
|
2939
|
+
style: {
|
2940
|
+
fontFamily: "Poppins",
|
2941
|
+
fontSize: "15px",
|
2942
|
+
fontWeight: "bold"
|
2943
|
+
}
|
2944
|
+
}
|
2945
|
+
};
|
2946
|
+
const result = highchartsRenderer.getDataLabelsOptions(additionalOptions, chartOptions);
|
2947
|
+
expect(result).toEqual(expected);
|
2948
|
+
});
|
2949
|
+
});
|
2950
|
+
|
2951
|
+
describe('function getLabelOptionKey', () => {
|
2952
|
+
it('should return null if additionalOptions is not defined', () => {
|
2953
|
+
const result = highchartsRenderer.getLabelOptionKey(undefined);
|
2954
|
+
expect(result).toBeNull();
|
2955
|
+
});
|
2956
|
+
|
2957
|
+
it('should return null if no label key is found in additionalOptions', () => {
|
2958
|
+
const additionalOptions = {
|
2959
|
+
option1: 'value1',
|
2960
|
+
option2: 'value2',
|
2961
|
+
option3: 'value3',
|
2962
|
+
};
|
2963
|
+
const result = highchartsRenderer.getLabelOptionKey(additionalOptions);
|
2964
|
+
expect(result).toBeNull();
|
2965
|
+
});
|
2966
|
+
|
2967
|
+
it('should return the label key if found in additionalOptions', () => {
|
2968
|
+
const additionalOptions = {
|
2969
|
+
option1: 'value1',
|
2970
|
+
label_option: 'value2',
|
2971
|
+
option3: 'value3',
|
2972
|
+
};
|
2973
|
+
const result = highchartsRenderer.getLabelOptionKey(additionalOptions);
|
2974
|
+
expect(result).toBe('label_option');
|
2975
|
+
});
|
2976
|
+
|
2977
|
+
it('should return the first label key if multiple label keys are found in additionalOptions', () => {
|
2978
|
+
const additionalOptions = {
|
2979
|
+
label_option1: 'value1',
|
2980
|
+
option1: 'value2',
|
2981
|
+
label_option2: 'value3',
|
2982
|
+
};
|
2983
|
+
const result = highchartsRenderer.getLabelOptionKey(additionalOptions);
|
2984
|
+
expect(result).toBe('label_option1');
|
2985
|
+
});
|
2986
|
+
});
|
2987
|
+
|
2988
|
+
describe('function getDefaultValueForSubOptions', () => {
|
2989
|
+
const suboptions = {
|
2990
|
+
option1: {
|
2991
|
+
category_type: 'type1',
|
2992
|
+
elements: [
|
2993
|
+
{
|
2994
|
+
value_name: 'value1',
|
2995
|
+
element_type: 'text',
|
2996
|
+
default_value: 'default1',
|
2997
|
+
},
|
2998
|
+
{
|
2999
|
+
value_name: 'value2',
|
3000
|
+
element_type: 'number',
|
3001
|
+
default_value: 42,
|
3002
|
+
},
|
3003
|
+
{
|
3004
|
+
value_name: 'value3',
|
3005
|
+
element_type: 'devider',
|
3006
|
+
},
|
3007
|
+
],
|
3008
|
+
},
|
3009
|
+
option2: {
|
3010
|
+
category_type: 'type2',
|
3011
|
+
elements: [
|
3012
|
+
{
|
3013
|
+
value_name: 'value1',
|
3014
|
+
element_type: 'text',
|
3015
|
+
default_value: 'default2',
|
3016
|
+
},
|
3017
|
+
{
|
3018
|
+
value_name: 'value2',
|
3019
|
+
element_type: 'number',
|
3020
|
+
default_value: 23,
|
3021
|
+
},
|
3022
|
+
{
|
3023
|
+
value_name: 'value3',
|
3024
|
+
element_type: 'devider',
|
3025
|
+
},
|
3026
|
+
],
|
3027
|
+
},
|
3028
|
+
option3: {
|
3029
|
+
category_type: 'type3',
|
3030
|
+
elements: [
|
3031
|
+
{
|
3032
|
+
value_name: 'value1',
|
3033
|
+
element_type: 'text',
|
3034
|
+
default_value: { val: 1 },
|
3035
|
+
}
|
3036
|
+
],
|
3037
|
+
},
|
3038
|
+
};
|
3039
|
+
let tempSubOptions = null;
|
3040
|
+
|
3041
|
+
beforeAll(() => {
|
3042
|
+
tempSubOptions = highchartsRenderer.suboptions;
|
3043
|
+
highchartsRenderer.suboptions = suboptions;
|
3044
|
+
});
|
3045
|
+
|
3046
|
+
afterAll(() => {
|
3047
|
+
highchartsRenderer.suboptions = tempSubOptions;
|
3048
|
+
});
|
3049
|
+
|
3050
|
+
it('should return an empty object if option type is not found', () => {
|
3051
|
+
const type = 'invalid_type';
|
3052
|
+
const existing_options = {};
|
3053
|
+
const result = highchartsRenderer.getDefaultValueForSubOptions(type, existing_options);
|
3054
|
+
expect(result).toEqual({});
|
3055
|
+
});
|
3056
|
+
|
3057
|
+
it('should return default values for all elements in suboption', () => {
|
3058
|
+
const type = 'type1';
|
3059
|
+
const existing_options = {};
|
3060
|
+
const result = highchartsRenderer.getDefaultValueForSubOptions(type, existing_options);
|
3061
|
+
expect(result).toEqual({
|
3062
|
+
value1: 'default1',
|
3063
|
+
value2: 42,
|
3064
|
+
});
|
3065
|
+
});
|
3066
|
+
|
3067
|
+
it('should use existing options if available', () => {
|
3068
|
+
const type = 'type1';
|
3069
|
+
const existing_options = {
|
3070
|
+
type1: {
|
3071
|
+
value1: 'existing1',
|
3072
|
+
value2: 99,
|
3073
|
+
},
|
3074
|
+
};
|
3075
|
+
const result = highchartsRenderer.getDefaultValueForSubOptions(type, existing_options);
|
3076
|
+
expect(result).toEqual({
|
3077
|
+
value1: 'existing1',
|
3078
|
+
value2: 99,
|
3079
|
+
});
|
3080
|
+
});
|
3081
|
+
|
3082
|
+
it('should ignore elements with type "devider"', () => {
|
3083
|
+
const type = 'type1';
|
3084
|
+
const existing_options = {};
|
3085
|
+
const result = highchartsRenderer.getDefaultValueForSubOptions(type, existing_options);
|
3086
|
+
expect(result).not.toHaveProperty('value3');
|
3087
|
+
});
|
3088
|
+
|
3089
|
+
it('should clone default value if it is an object', () => {
|
3090
|
+
const type = 'type3';
|
3091
|
+
const existing_options = {};
|
3092
|
+
const result = highchartsRenderer.getDefaultValueForSubOptions(type, existing_options);
|
3093
|
+
expect(result.value1).toEqual(suboptions.option3.elements[0].default_value);
|
3094
|
+
expect(result.value1).not.toBe(suboptions.option3.elements[0].default_value);
|
3095
|
+
});
|
3096
|
+
});
|
3097
|
+
|
2456
3098
|
describe('function getChartAxisLabel', () => {
|
2457
3099
|
it('should return default value', () => {
|
2458
3100
|
expect(highchartsRenderer.getChartAxisLabel('invalidType')).toBe('Axis (Category)')
|