@datarailsshared/dr_renderer 1.2.295 → 1.2.297

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.
@@ -1,6 +1,6 @@
1
1
  import * as JQuery from "jquery";
2
2
  import * as lodash from 'lodash';
3
- import * as moment from 'moment';
3
+ import moment from 'moment/min/moment.min';
4
4
  import tables from './mock/tables.json';
5
5
  import initPivotTable from "../src/pivottable";
6
6
  import initDRPivotTable from "../src/dr_pivottable";
@@ -380,19 +380,117 @@ describe('highcharts_renderer', () => {
380
380
  });
381
381
  });
382
382
 
383
- describe('function isSystemField', () => {
384
- it('system name', () => {
385
- const field = {
386
- name: 'Doc_ID'
383
+ describe('function defaultValueLabelsFormatter', () => {
384
+ let funcContext;
385
+
386
+ beforeEach(() => {
387
+ funcContext = { value: '12345.678' };
388
+ });
389
+
390
+ it('should return formatted number by aggregator', () => {
391
+ const format = '"$"#,###.##';
392
+ let pivotData = {
393
+ getAggregator: () => {
394
+ let aggregator = highchartsRenderer.rhPivotAggregatorSum([''], format, true, {}, {});
395
+ return aggregator({}, '', '');
396
+ }
387
397
  };
388
- expect(highchartsRenderer.isSystemField(field)).toBe(true);
398
+ let defaultValueLabelsFormatterFn = highchartsRenderer.defaultValueLabelsFormatter(pivotData, {})
399
+ let result = defaultValueLabelsFormatterFn.call(funcContext)
400
+ expect(result).toBe('$12,345.68');
389
401
  });
390
402
 
391
- it('not system name', () => {
392
- const field = {
393
- name: 'field name'
403
+ it('should return local string if there are no pivotData', () => {
404
+ let defaultValueLabelsFormatterFn = highchartsRenderer.defaultValueLabelsFormatter(null, {})
405
+ let result = defaultValueLabelsFormatterFn.call(funcContext)
406
+ expect(result).toBe('12,345.678');
407
+ });
408
+ });
409
+
410
+ describe('function persantageValueLabelsFormatter', () => {
411
+ it('should return local string with %', () => {
412
+ let funcContext = { value: '12345.678' };
413
+ let persantageValueLabelsFormatterFn = highchartsRenderer.persantageValueLabelsFormatter(null, {})
414
+ let result = persantageValueLabelsFormatterFn.call(funcContext)
415
+ expect(result).toBe('1,234,567.8%');
416
+ });
417
+ });
418
+
419
+ describe('function pieDataLabelFormatter', () => {
420
+ let funcContext;
421
+ let opts;
422
+
423
+ beforeEach(() => {
424
+ spyOn(highchartsRenderer, 'defaultDataLabelFormatter').and.returnValue(function() { return this.value })
425
+ funcContext = {
426
+ value: '12345.678',
427
+ point: {
428
+ color: 'red',
429
+ name: 'test',
430
+ percentage: 12.3456,
431
+ }
394
432
  };
395
- expect(highchartsRenderer.isSystemField(field)).toBe(false);
433
+ opts = {
434
+ chartOptions: {
435
+ label_pie: {
436
+ use_area_color: false,
437
+ show_percentage_in_labels: false,
438
+ show_value_in_labels: false,
439
+ }
440
+ }
441
+ }
442
+ });
443
+
444
+ it('should return null if value is nor defined', () => {
445
+ highchartsRenderer.defaultDataLabelFormatter.and.returnValue(() => null);
446
+ let func = highchartsRenderer.pieDataLabelFormatter(null, opts);
447
+ let result = func.call(funcContext);
448
+ expect(result).toBe(null);
449
+ });
450
+
451
+ it('should present only name with area color if only use_area_color option enabled', () => {
452
+ opts.chartOptions.label_pie.use_area_color = true;
453
+ let func = highchartsRenderer.pieDataLabelFormatter(null, opts);
454
+ let result = func.call(funcContext);
455
+ expect(result).toBe('<b><span style="color: red;">test</span><span>\u200E: </span></b>');
456
+ });
457
+
458
+ it('should present only name and value if only show_value_in_labels option enabled', () => {
459
+ opts.chartOptions.label_pie.show_value_in_labels = true;
460
+ let func = highchartsRenderer.pieDataLabelFormatter(null, opts);
461
+ let result = func.call(funcContext);
462
+ expect(result).toBe('<b><span >test</span><span>\u200E: 12345.678</span></b>');
463
+ });
464
+
465
+ it('should present only name and percentage if only show_percentage_in_labels option enabled', () => {
466
+ opts.chartOptions.label_pie.show_percentage_in_labels = true;
467
+ let func = highchartsRenderer.pieDataLabelFormatter(null, opts);
468
+ let result = func.call(funcContext);
469
+ expect(result).toBe('<b><span >test</span><span>\u200E: (12.35%)</span></b>');
470
+ });
471
+
472
+ it('should present vale + name + percentage if only % and value options enabled', () => {
473
+ opts.chartOptions.label_pie.show_percentage_in_labels = true;
474
+ opts.chartOptions.label_pie.show_value_in_labels = true;
475
+ let func = highchartsRenderer.pieDataLabelFormatter(null, opts);
476
+ let result = func.call(funcContext);
477
+ expect(result).toBe('12345.678<br><b><span >test</span><span>\u200E: (12.35%)</span></b>');
478
+ });
479
+ });
480
+
481
+ describe('function defaultDataLabelFormatter', () => {
482
+ let funcContext;
483
+ let opts;
484
+
485
+ beforeEach(() => {
486
+ funcContext = { y: '12345.678' };
487
+ opts = {}
488
+ });
489
+
490
+ it('should return local string if there are no pivotData', () => {
491
+ let fn = highchartsRenderer.defaultDataLabelFormatter(null, {})
492
+ let result = fn.call(funcContext)
493
+ expect(result).toBe('12,345.678');
396
494
  });
397
495
  });
398
496
 
@@ -1042,6 +1140,22 @@ describe('highcharts_renderer', () => {
1042
1140
  });
1043
1141
  });
1044
1142
 
1143
+ describe('function isSystemField', () => {
1144
+ it('system name', () => {
1145
+ const field = {
1146
+ name: 'Doc_ID'
1147
+ };
1148
+ expect(highchartsRenderer.isSystemField(field)).toBe(true);
1149
+ });
1150
+
1151
+ it('not system name', () => {
1152
+ const field = {
1153
+ name: 'field name'
1154
+ };
1155
+ expect(highchartsRenderer.isSystemField(field)).toBe(false);
1156
+ });
1157
+ });
1158
+
1045
1159
  describe('function getFieldColorClass', () => {
1046
1160
  it('should return "green_field" if field is not a system field and not mandatory', () => {
1047
1161
  const field = {
@@ -1197,7 +1311,7 @@ describe('highcharts_renderer', () => {
1197
1311
  });
1198
1312
  });
1199
1313
 
1200
- describe('aggregators', () => {
1314
+ describe('function aggregators', () => {
1201
1315
  const aggregatorsIds = ['SUM', 'COUNT', 'COUNT_UNIQUE', 'UNIQUE_VALUES', 'AVG', 'MIN', 'MAX'];
1202
1316
 
1203
1317
  it('Count and names', () => {
@@ -2326,4 +2440,1201 @@ describe('highcharts_renderer', () => {
2326
2440
  });
2327
2441
  });
2328
2442
  });
2443
+
2444
+ describe('function getChartAxisLabel', () => {
2445
+ it('should return default value', () => {
2446
+ expect(highchartsRenderer.getChartAxisLabel('invalidType')).toBe('Axis (Category)')
2447
+ });
2448
+
2449
+ it('should return chart type axisName', () => {
2450
+ expect(highchartsRenderer.getChartAxisLabel(highchartsRenderer.CHART_TYPES.COLUMN_CHART)).toBe('X - Axis')
2451
+ });
2452
+ });
2453
+
2454
+ describe('function getChartLegendLabel', () => {
2455
+ it('should return default value', () => {
2456
+ expect(highchartsRenderer.getChartLegendLabel('invalidType')).toBe('Legend (Series)')
2457
+ });
2458
+
2459
+ it('should return chart type legendName ', () => {
2460
+ expect(highchartsRenderer.getChartLegendLabel(highchartsRenderer.CHART_TYPES.COLUMN_CHART)).toBe('Data series')
2461
+ });
2462
+ });
2463
+
2464
+ describe('Function getFilterLabel', () => {
2465
+ describe('Should present template name', () => {
2466
+ let fieldFilter;
2467
+ let showTemplateName;
2468
+
2469
+ beforeEach(() => {
2470
+ fieldFilter = {
2471
+ name: 'RH_DIM_test',
2472
+ datetypevalues: { datetype: 'range' }
2473
+ };
2474
+ showTemplateName = false;
2475
+ });
2476
+
2477
+ it('should return fieldFilter.new_name without "RH_DIM_" if it exists', () => {
2478
+ fieldFilter.new_name = 'RH_DIM_test_new_name';
2479
+ const result = highchartsRenderer.getFilterLabel(fieldFilter, showTemplateName);
2480
+ expect(result).toEqual({
2481
+ label: 'test_new_name (All)',
2482
+ tooltip: 'test_new_name (All)'
2483
+ });
2484
+ });
2485
+
2486
+ it('should return highchartsRenderer.getFieldName(fieldFilter.name) without "RH_DIM_" if fieldFilter.new_name is falsy', () => {
2487
+ spyOn(highchartsRenderer, 'getFieldName').and.returnValue('RH_DIM_test_fieldName');
2488
+ const result = highchartsRenderer.getFilterLabel(fieldFilter, showTemplateName);
2489
+ expect(highchartsRenderer.getFieldName).toHaveBeenCalledWith('RH_DIM_test');
2490
+ expect(result).toEqual({
2491
+ label: 'test_fieldName (All)',
2492
+ tooltip: 'test_fieldName (All)'
2493
+ });
2494
+ });
2495
+
2496
+ it('should append template_name to displayname if showTemplateName is true and fieldFilter.template_name is truthy', () => {
2497
+ fieldFilter.new_name = null;
2498
+ fieldFilter.template_name = 'templateName';
2499
+ showTemplateName = true;
2500
+ const result = highchartsRenderer.getFilterLabel(fieldFilter, showTemplateName);
2501
+ expect(result).toEqual({
2502
+ label: 'templateName - test (range)',
2503
+ tooltip: 'templateName - test (range)'
2504
+ });
2505
+ });
2506
+
2507
+ it('should append template_name to displayname if showTemplateName is true and fieldFilter.template_name is truthy', () => {
2508
+ fieldFilter.new_name = null;
2509
+ fieldFilter.template_name = 'templateName';
2510
+ showTemplateName = true;
2511
+ const result = highchartsRenderer.getFilterLabel(fieldFilter, showTemplateName);
2512
+ expect(result).toEqual({
2513
+ label: 'templateName - test (range)',
2514
+ tooltip: 'templateName - test (range)'
2515
+ });
2516
+ });
2517
+
2518
+ it('should return label and tooltip with datetypevalues.datetype if datetypevalues is truthy and datetype is "range" or "frame"', () => {
2519
+ fieldFilter.new_name = null;
2520
+ fieldFilter.template_name = 'templateName';
2521
+ fieldFilter.datetypevalues.datetype = 'frame';
2522
+ const result = highchartsRenderer.getFilterLabel(fieldFilter, showTemplateName);
2523
+ expect(result).toEqual({
2524
+ label: 'test (frame)',
2525
+ tooltip: 'test (frame)'
2526
+ });
2527
+ });
2528
+ });
2529
+
2530
+ describe('Should present includes/excludes names', () => {
2531
+ let fieldFilter;
2532
+
2533
+ beforeEach(() => {
2534
+ fieldFilter = {
2535
+ name: 'test',
2536
+ includes: null,
2537
+ excludes: null,
2538
+ type: 'Text',
2539
+ };
2540
+ });
2541
+
2542
+ it('Should return "none" label when excludes empty', () => {
2543
+ fieldFilter.includes = [];
2544
+ const res = highchartsRenderer.getFilterLabel(fieldFilter, false);
2545
+ expect(res.label).toEqual('test (none)');
2546
+ expect(res.tooltip).toEqual('test (none)');
2547
+ });
2548
+
2549
+ it('Should return "All" label when excludes empty', () => {
2550
+ fieldFilter.excludes = [];
2551
+ const res = highchartsRenderer.getFilterLabel(fieldFilter, false);
2552
+ expect(res.label).toEqual('test (All)');
2553
+ expect(res.tooltip).toEqual('test (All)');
2554
+ });
2555
+
2556
+ it('Should return "many" label when includes/excludes has more than MAX_SELECTED_ITEMS_IN_LABEL items', () => {
2557
+ fieldFilter.includes = new Array(highchartsRenderer.MAX_SELECTED_ITEMS_IN_LABEL).fill('val');
2558
+ let res = highchartsRenderer.getFilterLabel(fieldFilter, false);
2559
+ expect(res.label).toEqual('test (many)');
2560
+ expect(res.tooltip).toEqual('test (' + fieldFilter.includes.join(', ') + ')');
2561
+
2562
+ fieldFilter.excludes = fieldFilter.includes;
2563
+ delete fieldFilter.includes;
2564
+ res = highchartsRenderer.getFilterLabel(fieldFilter, false);
2565
+ expect(res.label).toEqual('test (Exclusions many)');
2566
+ expect(res.tooltip).toEqual('test (Exclusions: ' + fieldFilter.excludes.join(', ') + ')');
2567
+ });
2568
+
2569
+ it('Should return "many" in label when includes has label length more than MAX_SELECTED_ITEMS_CHARECHTERS_IN_LABEL', () => {
2570
+ fieldFilter.includes = ['[null]', 'long long long value 2', 'long long long value 3'];
2571
+ let res = highchartsRenderer.getFilterLabel(fieldFilter, false);
2572
+ expect(res.label).toEqual('test (many)');
2573
+ expect(res.tooltip).toEqual('test (' + fieldFilter.includes.join(',') + ')');
2574
+ });
2575
+
2576
+ it('Should return "many" in label when excludes has label length more than MAX_SELECTED_ITEMS_CHARECHTERS_IN_LABEL', () => {
2577
+ fieldFilter.excludes = ['[null]', 'long long long value 2', 'long long long value 3'];
2578
+ let res = highchartsRenderer.getFilterLabel(fieldFilter, false);
2579
+ expect(res.label).toEqual('test (Exclusions: many)');
2580
+ expect(res.tooltip).toEqual('test (Exclusions: ' + fieldFilter.excludes.join(',') + ')');
2581
+ });
2582
+
2583
+ it('Should exclude "[null]" from includes if allow_nulls enabled', () => {
2584
+ fieldFilter.allow_nulls = true;
2585
+ fieldFilter.includes = ['value 1', '[null]'];
2586
+ let res = highchartsRenderer.getFilterLabel(fieldFilter, false);
2587
+ expect(res.label).toEqual('test (value 1)');
2588
+ expect(res.tooltip).toEqual('test (' + fieldFilter.includes[0] + ')');
2589
+ });
2590
+
2591
+ it('Should exclude "[null]" from excludes if allow_nulls enabled', () => {
2592
+ fieldFilter.allow_nulls = true;
2593
+ fieldFilter.excludes = ['value 1', '[null]'];
2594
+ let res = highchartsRenderer.getFilterLabel(fieldFilter, false);
2595
+ expect(res.label).toEqual('test (Exclusions: value 1)');
2596
+ expect(res.tooltip).toEqual('test (Exclusions: ' + fieldFilter.excludes[0] + ')');
2597
+ });
2598
+
2599
+ it('Should present formatted dates in includes. Get formatted value from invertValueFormatMap object if exist ', () => {
2600
+ fieldFilter.includes = [1682063884, 1682060884, 1682013884];
2601
+ fieldFilter.type = 'Date';
2602
+ fieldFilter.valueFormatMap = {
2603
+ 'April 21, 2023': 1682063884
2604
+ };
2605
+ let res = highchartsRenderer.getFilterLabel(fieldFilter, false);
2606
+ expect(res.label).toEqual('test (April 21, 2023,04/21/2023,04/20/2023)');
2607
+ expect(res.tooltip).toEqual('test (April 21, 2023,04/21/2023,04/20/2023)');
2608
+ });
2609
+
2610
+ it('Should present formatted dates in excludes. Get formatted value from invertValueFormatMap object if exist ', () => {
2611
+ fieldFilter.excludes = [1682063884, 1682060884];
2612
+ fieldFilter.type = 'Date';
2613
+ fieldFilter.valueFormatMap = {
2614
+ 'April 21, 2023': 1682063884
2615
+ };
2616
+ let res = highchartsRenderer.getFilterLabel(fieldFilter, false);
2617
+ expect(res.label).toEqual('test (Exclusions: April 21, 2023,04/21/2023)');
2618
+ expect(res.tooltip).toEqual('test (Exclusions: April 21, 2023,04/21/2023)');
2619
+ });
2620
+ });
2621
+
2622
+ describe('Should present date range or frame selection', () => {
2623
+ let fieldFilter;
2624
+
2625
+ beforeEach(() => {
2626
+ fieldFilter = {
2627
+ name: 'test',
2628
+ includes: null,
2629
+ excludes: null,
2630
+ type: 'Date',
2631
+ };
2632
+ });
2633
+
2634
+ it('Should return "range" label when datetype is range', () => {
2635
+ fieldFilter.datetypevalues = {
2636
+ datetype: 'range',
2637
+ val: {
2638
+ fromdate: 1682060884,
2639
+ todate: 1682063884,
2640
+ }
2641
+ };
2642
+ const res = highchartsRenderer.getFilterLabel(fieldFilter, false);
2643
+ expect(res.label).toEqual('test (4/21/2023-4/21/2023)');
2644
+ expect(res.tooltip).toEqual('test (4/21/2023-4/21/2023)');
2645
+ });
2646
+
2647
+ it('Should return "frame" label when datetype is frame', () => {
2648
+ fieldFilter.datetypevalues = {
2649
+ datetype: 'frame',
2650
+ val: {
2651
+ timeframe: 'xday'
2652
+ }
2653
+ };
2654
+ const res = highchartsRenderer.getFilterLabel(fieldFilter, false);
2655
+ expect(res.label).toEqual('test (xday)');
2656
+ expect(res.tooltip).toEqual('test (xday)');
2657
+ });
2658
+
2659
+ it('Should return "All" label when datetype is not selected', () => {
2660
+ fieldFilter.datetypevalues = {};
2661
+ const res = highchartsRenderer.getFilterLabel(fieldFilter, false);
2662
+ expect(res.label).toEqual('test (All)');
2663
+ expect(res.tooltip).toEqual('test (All)');
2664
+ });
2665
+ });
2666
+
2667
+ describe('Should present advanced filter selection', () => {
2668
+ it('Should return "Advanced" label when advanced type in values', () => {
2669
+ const res = highchartsRenderer.getFilterLabel({ name: 'test', values: { type: 'advanced'} }, false);
2670
+ expect(res.label).toEqual('test (Advanced)');
2671
+ expect(res.tooltip).toEqual('test (Advanced)');
2672
+ });
2673
+
2674
+ it('Should return "Advanced" label when advanced type in datetypevalues', () => {
2675
+ const res = highchartsRenderer.getFilterLabel({ name: 'test', datetypevalues: { type: 'advanced'} }, false);
2676
+ expect(res.label).toEqual('test (Advanced)');
2677
+ expect(res.tooltip).toEqual('test (Advanced)');
2678
+ });
2679
+ });
2680
+
2681
+ describe('Should present All if nothing selected', () => {
2682
+ it('Should return "All" label when nothing selected', () => {
2683
+ const res = highchartsRenderer.getFilterLabel({ name: 'test'}, false);
2684
+ expect(res.label).toEqual('test (All)');
2685
+ expect(res.tooltip).toEqual('test (All)');
2686
+ });
2687
+ });
2688
+ });
2689
+
2690
+ describe('function getRelevantFilters', () => {
2691
+ it('should return an empty array if given an empty array', () => {
2692
+ const filters = highchartsRenderer.getRelevantFilters([]);
2693
+ expect(filters).toEqual([]);
2694
+ });
2695
+
2696
+ it('should filter out elements that do not have includes, excludes, or datetypevalues properties', () => {
2697
+ const filters = [
2698
+ {fields: ['field1'], otherProperty: 'value'},
2699
+ {fields: ['field2'], includes: [1, 2, 3]},
2700
+ {fields: ['field3'], excludes: ['abc']},
2701
+ {fields: ['field4'], datetypevalues: {datetype: 'date', start: '2022-01-01', end: '2022-01-31'}}
2702
+ ];
2703
+ const relevantFilters = highchartsRenderer.getRelevantFilters(filters);
2704
+ expect(relevantFilters.length).toEqual(3);
2705
+ expect(relevantFilters).toContainEqual({
2706
+ fields: ['field2'],
2707
+ values: [1, 2, 3],
2708
+ is_excluded: false,
2709
+ allow_nulls: false,
2710
+ inject_only: false
2711
+ });
2712
+ expect(relevantFilters).toContainEqual({
2713
+ fields: ['field3'],
2714
+ values: ['abc'],
2715
+ is_excluded: true,
2716
+ allow_nulls: false,
2717
+ inject_only: false
2718
+ });
2719
+ expect(relevantFilters).toContainEqual({
2720
+ fields: ['field4'],
2721
+ values: {datetype: 'date', start: '2022-01-01', end: '2022-01-31'},
2722
+ is_excluded: false,
2723
+ allow_nulls: false,
2724
+ inject_only: false
2725
+ });
2726
+ });
2727
+
2728
+ it('should handle empty includes and excludes properties by returning an empty values array', () => {
2729
+ const filters = [
2730
+ {fields: ['field1'], includes: []},
2731
+ {fields: ['field2'], includes: [1, 2, 3], excludes: []},
2732
+ {fields: ['field3'], excludes: ['abc']}
2733
+ ];
2734
+ const relevantFilters = highchartsRenderer.getRelevantFilters(filters);
2735
+ expect(relevantFilters.length).toEqual(3);
2736
+ expect(relevantFilters[0].values).toEqual([]);
2737
+ expect(relevantFilters[1].values).toEqual([1, 2, 3]);
2738
+ expect(relevantFilters[2].values).toEqual(['abc']);
2739
+ });
2740
+
2741
+ it('should set is_excluded to true for elements that have an excludes property', () => {
2742
+ const filters = [
2743
+ {fields: ['field1'], includes: [1, 2, 3]},
2744
+ {fields: ['field2'], excludes: ['abc']},
2745
+ {fields: ['field3'], excludes: [null]}
2746
+ ];
2747
+ const relevantFilters = highchartsRenderer.getRelevantFilters(filters);
2748
+ expect(relevantFilters.length).toEqual(3);
2749
+ expect(relevantFilters[0].is_excluded).toBe(false);
2750
+ expect(relevantFilters[1].is_excluded).toBe(true);
2751
+ expect(relevantFilters[2].is_excluded).toBe(true);
2752
+ });
2753
+
2754
+ it('should handle datetypevalues', () => {
2755
+ const filtersList = [
2756
+ {
2757
+ fields: ['date'],
2758
+ datetypevalues: {
2759
+ datetype: 'last_month',
2760
+ from: null,
2761
+ to: null
2762
+ }
2763
+ }
2764
+ ];
2765
+
2766
+ const expected = [
2767
+ {
2768
+ fields: ['date'],
2769
+ values: {
2770
+ datetype: 'last_month',
2771
+ from: null,
2772
+ to: null
2773
+ },
2774
+ is_excluded: false,
2775
+ allow_nulls: false,
2776
+ inject_only: false
2777
+ }
2778
+ ];
2779
+
2780
+ expect(highchartsRenderer.getRelevantFilters(filtersList)).toEqual(expected);
2781
+ });
2782
+ });
2783
+
2784
+ describe('function parseOptionsToObject', () => {
2785
+ it('should return an object when given an object', () => {
2786
+ const obj = { key: 'value' };
2787
+ const result = highchartsRenderer.parseOptionsToObject(obj);
2788
+ expect(result).toEqual(obj);
2789
+ });
2790
+
2791
+ it('should return an empty object when given empty string', () => {
2792
+ let result = highchartsRenderer.parseOptionsToObject('');
2793
+ expect(result).toEqual({});
2794
+ });
2795
+
2796
+ it('should parse a JSON string into an object', () => {
2797
+ const str = '{ "key": "value" }';
2798
+ const result = highchartsRenderer.parseOptionsToObject(str);
2799
+ expect(result).toEqual({ key: 'value' });
2800
+ });
2801
+
2802
+ it('should remove line breaks from the JSON string before parsing', () => {
2803
+ const str = '{\n "key": "value"\n}';
2804
+ const result = highchartsRenderer.parseOptionsToObject(str);
2805
+ expect(result).toEqual({ key: 'value' });
2806
+ });
2807
+
2808
+ it('should throw an error if given an invalid JSON string', () => {
2809
+ const str = '{ "key": "value" ';
2810
+ expect(() => highchartsRenderer.parseOptionsToObject(str)).toThrow();
2811
+ });
2812
+ });
2813
+
2814
+ describe('function getDashboardOverrideValues', () => {
2815
+ let dataModel;
2816
+ let graph;
2817
+ let localCurrentDashboard;
2818
+
2819
+ beforeEach(() => {
2820
+ dataModel = {
2821
+ current_dashboard: {
2822
+ fields_selectors: [
2823
+ {
2824
+ value: 'field1',
2825
+ fields_selector: {
2826
+ default_field: { id: 'field1', name: 'Field 1' },
2827
+ other_fields: [
2828
+ { id: 'field1', name: 'Field 1' },
2829
+ { id: 'field2', name: 'Field 2' },
2830
+ ]
2831
+ }
2832
+ },
2833
+ {
2834
+ value: 'field2',
2835
+ fields_selector: {
2836
+ default_field: { id: 'field2', name: 'Field 2' },
2837
+ other_fields: [
2838
+ { id: 'field1', name: 'Field 1' },
2839
+ { id: 'field2', name: 'Field 2' },
2840
+ ]
2841
+ }
2842
+ }
2843
+ ]
2844
+ },
2845
+ ebmedded_override_value_ids: []
2846
+ };
2847
+
2848
+ graph = {
2849
+ vals: [{ field: 'field1' }]
2850
+ };
2851
+
2852
+ localCurrentDashboard = {
2853
+ fields_selectors: [
2854
+ {
2855
+ value: 'field2',
2856
+ fields_selector: {
2857
+ default_field: { id: 'field1', name: 'Field 1' },
2858
+ other_fields: [
2859
+ { id: 'field1', name: 'Field 1' },
2860
+ { id: 'field2', name: 'Field 2' },
2861
+ ]
2862
+ }
2863
+ }
2864
+ ]
2865
+ };
2866
+ });
2867
+
2868
+ it('should return empty array when no conditions met', () => {
2869
+ expect(highchartsRenderer.getDashboardOverrideValues({}, {}, {})).toEqual([]);
2870
+ });
2871
+
2872
+ it('should return array of value objects when ebmedded_override_value_ids exist', () => {
2873
+ dataModel.ebmedded_override_value_ids = [1, 2, 3]
2874
+ expect(highchartsRenderer.getDashboardOverrideValues(dataModel, {}, {})).toEqual([
2875
+ { id: 1 },
2876
+ { id: 2 },
2877
+ { id: 3 }
2878
+ ]);
2879
+ });
2880
+
2881
+ it('should return empty array when local_current_dashboard undefined', () => {
2882
+ expect(highchartsRenderer.getDashboardOverrideValues({}, graph, undefined)).toEqual([]);
2883
+ });
2884
+
2885
+ it('should return empty array when graph undefined', () => {
2886
+ expect(highchartsRenderer.getDashboardOverrideValues(dataModel, undefined, localCurrentDashboard)).toEqual([]);
2887
+ });
2888
+
2889
+ it('should return empty array when graph vals empty', () => {
2890
+ expect(highchartsRenderer.getDashboardOverrideValues(dataModel, { vals: [] }, localCurrentDashboard)).toEqual([]);
2891
+ });
2892
+
2893
+ it('should return empty array when graph vals length > 1', () => {
2894
+ expect(highchartsRenderer.getDashboardOverrideValues(dataModel, { vals: [{ field: 'field1' }, { field: 'field2' }] }, localCurrentDashboard)).toEqual([]);
2895
+ });
2896
+
2897
+ it('should return empty array when no matching field selector', () => {
2898
+ expect(highchartsRenderer.getDashboardOverrideValues(dataModel, { vals: [{ field: 'field3' }] }, localCurrentDashboard)).toEqual([]);
2899
+ });
2900
+
2901
+ it('should return value object when selector value != graph val field', () => {
2902
+ expect(highchartsRenderer.getDashboardOverrideValues(dataModel, graph, localCurrentDashboard)).toEqual([{ id: 'field2', name: 'Field 2' }]);
2903
+ });
2904
+ });
2905
+
2906
+ describe('function getDashboardFilters', () => {
2907
+ let data_model;
2908
+ let remove_filters_from_global;
2909
+
2910
+ beforeEach(() => {
2911
+ data_model = {
2912
+ current_dashboard: {
2913
+ filters: [
2914
+ {
2915
+ fields: [{id: '1', name: 'Field 1'}],
2916
+ includes: ['value 1']
2917
+ },
2918
+ {
2919
+ fields: [{id: '2', name: 'Field 2'}],
2920
+ includes: ['value 2']
2921
+ }
2922
+ ]
2923
+ },
2924
+ ebmedded_filters: []
2925
+ };
2926
+ remove_filters_from_global = [{id: '2', name: 'Field 2'}];
2927
+ });
2928
+
2929
+ it('should return an empty array when no relevant filters found', () => {
2930
+ const local_current_dashboard = {
2931
+ fields_selectors: [{value: '1', fields_selector: {default_field: {id: '1'}}}]
2932
+ };
2933
+ const result = highchartsRenderer.getDashboardFilters({}, [], local_current_dashboard);
2934
+ expect(result).toEqual([]);
2935
+ });
2936
+
2937
+ it('should return an array of relevant filters from the current dashboard', () => {
2938
+ const result = highchartsRenderer.getDashboardFilters(data_model, [], data_model.current_dashboard);
2939
+ expect(result.length).toEqual(2);
2940
+ });
2941
+
2942
+ it('should return an array of relevant filters from the current dashboard and embedded filters', () => {
2943
+ data_model.ebmedded_filters = [{
2944
+ fields: [{id: '3', name: 'Field 3'}],
2945
+ includes: ['value 3']
2946
+ }];
2947
+ const result = highchartsRenderer.getDashboardFilters(data_model, [], data_model.current_dashboard);
2948
+ expect(result.length).toEqual(3);
2949
+ });
2950
+
2951
+ it('should remove specified fields from the returned filters array', () => {
2952
+ const result = highchartsRenderer.getDashboardFilters(data_model, remove_filters_from_global, data_model.current_dashboard);
2953
+ expect(result.length).toEqual(1);
2954
+ });
2955
+
2956
+ it('should add "[null]" to values array for filters with "allow_nulls" flag', () => {
2957
+ const currentDashboardWithNull = {
2958
+ filters: [
2959
+ {
2960
+ fields: [{ id: 'field1', name: 'Field 1' }],
2961
+ includes: ['value1', 'value2'],
2962
+ allow_nulls: false,
2963
+ },
2964
+ ],
2965
+ };
2966
+ const dataModelWithNull = { current_dashboard: currentDashboardWithNull };
2967
+ const result = highchartsRenderer.getDashboardFilters(dataModelWithNull);
2968
+ expect(result[0].values).toEqual(['value1', 'value2']);
2969
+ });
2970
+
2971
+ it('should not add "[null]" to values array if it is already present', () => {
2972
+ const currentDashboardWithNull = {
2973
+ filters: [
2974
+ {
2975
+ fields: [{ id: 'field1', name: 'Field 1' }],
2976
+ includes: ['value1'],
2977
+ allow_nulls: true,
2978
+ },
2979
+ ],
2980
+ };
2981
+ const dataModelWithNull = { current_dashboard: currentDashboardWithNull };
2982
+ const result = highchartsRenderer.getDashboardFilters(dataModelWithNull);
2983
+ expect(result[0].values).toEqual(['value1', '[null]']);
2984
+ });
2985
+ });
2986
+
2987
+ describe('function getPresentationTagType', () => {
2988
+ it('should return "date_tags" if local_current_dashboard has date tags', () => {
2989
+ const data_model = {
2990
+ current_dashboard: {
2991
+ date_tags: [{ id: 1, name: 'Date Tag 1' }]
2992
+ }
2993
+ };
2994
+ const result = highchartsRenderer.getPresentationTagType(data_model, data_model.current_dashboard);
2995
+ expect(result).toBe('date_tags');
2996
+ });
2997
+
2998
+ it('should return "plan_tags" if local_current_dashboard has plan tags', () => {
2999
+ const data_model = {
3000
+ current_dashboard: {
3001
+ plan_tags: [{ id: 1, name: 'Plan Tag 1' }]
3002
+ }
3003
+ };
3004
+ const result = highchartsRenderer.getPresentationTagType(data_model, data_model.current_dashboard);
3005
+ expect(result).toBe('plan_tags');
3006
+ });
3007
+
3008
+ it('should return undefined if local_current_dashboard has no tags', () => {
3009
+ const data_model = {
3010
+ current_dashboard: {}
3011
+ };
3012
+ const result = highchartsRenderer.getPresentationTagType(data_model);
3013
+ expect(result).toBeUndefined();
3014
+ });
3015
+
3016
+ it('should return "date_tags" if local_current_dashboard is undefined but data_model has date tags', () => {
3017
+ const data_model = {
3018
+ current_dashboard: {
3019
+ date_tags: [{ id: 1, name: 'Date Tag 1' }]
3020
+ }
3021
+ };
3022
+ const result = highchartsRenderer.getPresentationTagType(data_model);
3023
+ expect(result).toBe('date_tags');
3024
+ });
3025
+
3026
+ it('should return "plan_tags" if local_current_dashboard is undefined but data_model has plan tags', () => {
3027
+ const data_model = {
3028
+ current_dashboard: {
3029
+ plan_tags: [{ id: 1, name: 'Plan Tag 1' }]
3030
+ }
3031
+ };
3032
+ const result = highchartsRenderer.getPresentationTagType(data_model);
3033
+ expect(result).toBe('plan_tags');
3034
+ });
3035
+ });
3036
+
3037
+ describe('function getPresentationDataTag', () => {
3038
+ const data_model = { current_dashboard: { presentation_data_tag_object: { value: 'foo' } } };
3039
+ const dataKeyTag = 'date_tags';
3040
+
3041
+ it('returns presentation_data_tag_object value if local_current_dashboard is undefined', () => {
3042
+ const result = highchartsRenderer.getPresentationDataTag(data_model, undefined, dataKeyTag);
3043
+ expect(result).toBe('foo');
3044
+ });
3045
+
3046
+ it('returns presentation_data_tag_object value if local_current_dashboard has presentation_data_tag_object', () => {
3047
+ const local_current_dashboard = { presentation_data_tag_object: { value: 'bar' } };
3048
+ const result = highchartsRenderer.getPresentationDataTag(data_model, local_current_dashboard, dataKeyTag);
3049
+ expect(result).toBe('bar');
3050
+ });
3051
+
3052
+ it('returns value of highest dataKeyTag value in local_current_dashboard', () => {
3053
+ const local_current_dashboard = {
3054
+ date_tags: [
3055
+ { value: '2022-01-01' },
3056
+ { value: '2021-01-01' },
3057
+ { value: '2023-01-01' },
3058
+ ],
3059
+ };
3060
+ const result = highchartsRenderer.getPresentationDataTag(data_model, local_current_dashboard, dataKeyTag);
3061
+ expect(result).toBe('2023-01-01');
3062
+ });
3063
+
3064
+ it('returns null if local_current_dashboard has no presentation_data_tag_object or dataKeyTag values', () => {
3065
+ const local_current_dashboard = {};
3066
+ const result = highchartsRenderer.getPresentationDataTag(data_model, local_current_dashboard, dataKeyTag);
3067
+ expect(result).toBeNull();
3068
+ });
3069
+
3070
+ it('returns null if local_current_dashboard has empty dataKeyTag array', () => {
3071
+ const local_current_dashboard = { date_tags: [] };
3072
+ const result = highchartsRenderer.getPresentationDataTag(data_model, local_current_dashboard, dataKeyTag);
3073
+ expect(result).toBeNull();
3074
+ });
3075
+ });
3076
+
3077
+ describe('function getDashboardApplyScenarios', () => {
3078
+ let data_model;
3079
+ let graph;
3080
+
3081
+ beforeEach(() => {
3082
+ graph = { vals: [{ field: 'field1' }] };
3083
+ data_model = {
3084
+ current_dashboard: {
3085
+ scenario_models: [
3086
+ {
3087
+ value: 1,
3088
+ scenario_model: { source_fields: ['field1'], scenarios: [{ id: 1 }, { id: 2 }] },
3089
+ },
3090
+ {
3091
+ value: 2,
3092
+ scenario_model: { source_fields: ['field2'], scenarios: [{ id: 3 }, { id: 4 }] },
3093
+ },
3094
+ ],
3095
+ },
3096
+ ebmedded_apply_scenario_ids: [],
3097
+ };
3098
+ });
3099
+
3100
+ it('returns ebmedded_apply_scenario_ids if data_model has it', () => {
3101
+ data_model.ebmedded_apply_scenario_ids = [5, 6];
3102
+ const local_current_dashboard = { foo: 'bar' };
3103
+ const result = highchartsRenderer.getDashboardApplyScenarios(data_model, graph, local_current_dashboard);
3104
+ expect(result).toEqual([5, 6]);
3105
+ });
3106
+
3107
+ it('returns empty array if scenario_models in local_current_dashboard are not provided', () => {
3108
+ const result = highchartsRenderer.getDashboardApplyScenarios(data_model, {vals: [null]}, {});
3109
+ expect(result).toEqual([]);
3110
+ });
3111
+
3112
+ it('returns empty array if graph has no vals', () => {
3113
+ const result = highchartsRenderer.getDashboardApplyScenarios(data_model, {});
3114
+ expect(result).toEqual([]);
3115
+ });
3116
+
3117
+ it('returns empty array if graph has more than one val', () => {
3118
+ const graph = { vals: [{ field: 'field1' }, { field: 'field2' }] };
3119
+ const result = highchartsRenderer.getDashboardApplyScenarios(data_model, graph, {});
3120
+ expect(result).toEqual([]);
3121
+ });
3122
+
3123
+ it('returns array of selected scenario ids', () => {
3124
+ const result = highchartsRenderer.getDashboardApplyScenarios(data_model, graph, data_model.current_dashboard);
3125
+ expect(result).toEqual([1]);
3126
+ });
3127
+
3128
+ it('returns empty array if no matching scenario is found', () => {
3129
+ const graph = { vals: [{ field: 'field3' }] };
3130
+ const result = highchartsRenderer.getDashboardApplyScenarios(data_model, graph, data_model.current_dashboard);
3131
+ expect(result).toEqual([]);
3132
+ });
3133
+ });
3134
+
3135
+ describe('function isDate', () => {
3136
+ it('returns true for valid date string', () => {
3137
+ expect(highchartsRenderer.isDate('2022-01-01')).toBe(true);
3138
+ });
3139
+
3140
+ it('returns false for invalid date string', () => {
3141
+ expect(highchartsRenderer.isDate('not a date')).toBe(false);
3142
+ });
3143
+
3144
+ it('returns false for undefined input', () => {
3145
+ expect(highchartsRenderer.isDate(undefined)).toBe(false);
3146
+ });
3147
+
3148
+ it('returns false for empty string input', () => {
3149
+ expect(highchartsRenderer.isDate('')).toBe(false);
3150
+ });
3151
+ });
3152
+
3153
+ describe('function isDateFormat', () => {
3154
+ it('returns true for valid date string and format', () => {
3155
+ expect(highchartsRenderer.isDateFormat('2022-01-01', 'YYYY-MM-DD')).toBe(true);
3156
+ });
3157
+
3158
+ it('returns false for invalid date string', () => {
3159
+ expect(highchartsRenderer.isDateFormat('not a date', 'YYYY-MM-DD')).toBe(false);
3160
+ });
3161
+
3162
+ it('returns false for null input', () => {
3163
+ expect(highchartsRenderer.isDateFormat(null, 'YYYY-MM-DD')).toBe(false);
3164
+ });
3165
+
3166
+ it('returns false for undefined input', () => {
3167
+ expect(highchartsRenderer.isDateFormat(undefined, 'YYYY-MM-DD')).toBe(false);
3168
+ });
3169
+
3170
+ it('returns false for non-string input', () => {
3171
+ expect(highchartsRenderer.isDateFormat(123, 'YYYY-MM-DD')).toBe(false);
3172
+ });
3173
+
3174
+ it('returns false for empty string input', () => {
3175
+ expect(highchartsRenderer.isDateFormat('', 'YYYY-MM-DD')).toBe(false);
3176
+ });
3177
+
3178
+ it('returns false for invalid format', () => {
3179
+ expect(highchartsRenderer.isDateFormat('2022-01-01', 'invalid format')).toBe(false);
3180
+ });
3181
+ });
3182
+
3183
+ describe('function containsIgnoreCase', () => {
3184
+ it('should return true when str contains it, ignoring case', () => {
3185
+ const str = 'The quick brown fox jumps over the lazy dog';
3186
+ const it = 'brown';
3187
+ expect(highchartsRenderer.containsIgnoreCase(str, it)).toBe(true);
3188
+ });
3189
+
3190
+ it('should return true when str contains it, with different case', () => {
3191
+ const str = 'The quick brown fox jumps over the lazy dog';
3192
+ const it = 'BROWN';
3193
+ expect(highchartsRenderer.containsIgnoreCase(str, it)).toBe(true);
3194
+ });
3195
+
3196
+ it('should return false when str does not contain it, ignoring case', () => {
3197
+ const str = 'The quick brown fox jumps over the lazy dog';
3198
+ const it = 'cat';
3199
+ expect(highchartsRenderer.containsIgnoreCase(str, it)).toBe(false);
3200
+ });
3201
+
3202
+ it('should return false when str is empty', () => {
3203
+ const str = '';
3204
+ const it = 'dog';
3205
+ expect(highchartsRenderer.containsIgnoreCase(str, it)).toBe(false);
3206
+ });
3207
+ });
3208
+
3209
+ describe('function generateTableFormula', () => {
3210
+ it('pivotUtilities.getPivotTableFormula should be called', () => {
3211
+ spyOn($.pivotUtilities, 'getPivotTableFormula').and.callFake(() => null);
3212
+ highchartsRenderer.generateTableFormula(1,2,3,4,5,6, 7);
3213
+ expect($.pivotUtilities.getPivotTableFormula).lastCalledWith(1, 2, 3, 4, 5, 6, 7);
3214
+ });
3215
+ });
3216
+
3217
+ describe('function updateSelectedOverrideValues', () => {
3218
+ const widget = {
3219
+ vals: [{ name: 'selected_name' }]
3220
+ };
3221
+
3222
+ const overrideValues = [{ name: 'override_name' }];
3223
+
3224
+ it('should update selected values in res object', () => {
3225
+ const res = [
3226
+ { override_name: 'value1', selected_name: 'valueA' },
3227
+ { override_name: 'value2', selected_name: 'valueB' }
3228
+ ];
3229
+ const expectedRes = [
3230
+ { override_name: 'value1', selected_name: 'value1' },
3231
+ { override_name: 'value2', selected_name: 'value2' }
3232
+ ];
3233
+ expect(highchartsRenderer.updateSelectedOverrideValues(widget, overrideValues, res)).toEqual(expectedRes);
3234
+ });
3235
+
3236
+ it('should not update res object if override_values array is empty', () => {
3237
+ const res = [
3238
+ { override_name: 'value1', selected_name: 'valueA' },
3239
+ { override_name: 'value2', selected_name: 'valueB' }
3240
+ ];
3241
+ expect(highchartsRenderer.updateSelectedOverrideValues(widget, [], res)).toEqual(res);
3242
+ });
3243
+
3244
+ it('should not update res object if name_to_find is no_name_for_selected', () => {
3245
+ const res = [
3246
+ { override_name: 'value1', selected_name: 'valueA' },
3247
+ { override_name: 'value2', selected_name: 'valueB' }
3248
+ ];
3249
+ const overrideValues = [{ name: 'no_name_for_selected' }];
3250
+ expect(highchartsRenderer.updateSelectedOverrideValues(widget, overrideValues, res)).toEqual(res);
3251
+ });
3252
+
3253
+ it('should not update res object if name_to_set is null', () => {
3254
+ const widget = { vals: [] };
3255
+ const res = [
3256
+ { override_name: 'value1', selected_name: 'valueA' },
3257
+ { override_name: 'value2', selected_name: 'valueB' }
3258
+ ];
3259
+ expect(highchartsRenderer.updateSelectedOverrideValues(widget, overrideValues, res)).toEqual(res);
3260
+ });
3261
+ });
3262
+
3263
+ describe('function convertUniqueDateValues', () => {
3264
+ const widget = {
3265
+ template_id: 'template1',
3266
+ vals: [
3267
+ {field: 'field1', aggregator: 'UNIQUE_VALUES'},
3268
+ {field: 'field2', aggregator: 'COUNT'}
3269
+ ]
3270
+ };
3271
+
3272
+ const templates = [
3273
+ {id: 'template1', fields: [{id: 'field1', name: 'date_field', type: 'Date'}]},
3274
+ {id: 'template2', fields: [{id: 'field3', name: 'string_field', type: 'String'}]}
3275
+ ];
3276
+
3277
+ it('should convert unique date values in res object', () => {
3278
+ const res = [
3279
+ {date_field: [1640995200, 1641081600], string_field: 'value1'},
3280
+ {date_field: [1641168000], string_field: 'value2'}
3281
+ ];
3282
+ const expectedRes = [
3283
+ {date_field: ['01/01/2022', '01/02/2022'], string_field: 'value1'},
3284
+ {date_field: ['01/03/2022'], string_field: 'value2'}
3285
+ ];
3286
+ expect(highchartsRenderer.convertUniqueDateValues(widget, templates, res)).toEqual(expectedRes);
3287
+ });
3288
+
3289
+ it('should not convert date values if fields_to_convert is empty', () => {
3290
+ const widget = {
3291
+ template_id: 'template2',
3292
+ vals: [
3293
+ {field: 'field1', aggregator: 'SUM'},
3294
+ {field: 'field2', aggregator: 'AVG'}
3295
+ ]
3296
+ };
3297
+ const res = [
3298
+ {date_field: ['2022-01-01', '2022-01-02'], string_field: 'value1'},
3299
+ {date_field: ['2022-01-03'], string_field: 'value2'}
3300
+ ];
3301
+ expect(highchartsRenderer.convertUniqueDateValues(widget, templates, res)).toEqual(res);
3302
+ });
3303
+
3304
+ it('should not convert date values if res is empty', () => {
3305
+ const res = [];
3306
+ expect(highchartsRenderer.convertUniqueDateValues(widget, templates, res)).toEqual(res);
3307
+ });
3308
+
3309
+ it('should not convert date values if widget is null', () => {
3310
+ const res = [
3311
+ {date_field: ['2022-01-01', '2022-01-02'], string_field: 'value1'},
3312
+ {date_field: ['2022-01-03'], string_field: 'value2'}
3313
+ ];
3314
+ expect(highchartsRenderer.convertUniqueDateValues(null, templates, res)).toEqual(res);
3315
+ });
3316
+
3317
+ it('should not convert date values if widget.vals is null', () => {
3318
+ const widget = {template_id: 'template1'};
3319
+ const res = [
3320
+ {date_field: ['2022-01-01', '2022-01-02'], string_field: 'value1'},
3321
+ {date_field: ['2022-01-03'], string_field: 'value2'}
3322
+ ];
3323
+ expect(highchartsRenderer.convertUniqueDateValues(widget, templates, res)).toEqual(res);
3324
+ });
3325
+ });
3326
+
3327
+ describe('function setNewFieldNames', () => {
3328
+ beforeEach(() => {
3329
+ highchartsRenderer.useTotalsCalculation = false;
3330
+ });
3331
+
3332
+ it('should return the input if useTotalsCalculation is true', () => {
3333
+ const res = [{ DR_Values: 'value1' }, { DR_Values: 'value2' }];
3334
+ highchartsRenderer.useTotalsCalculation = true;
3335
+ const result = highchartsRenderer.setNewFieldNames(res);
3336
+
3337
+ expect(result).toEqual(res);
3338
+ });
3339
+
3340
+ it('should update DR_Values field names', () => {
3341
+ const res = [{ DR_Values: 'DR_Values' }, { DR_Values: 'value2' }];
3342
+ const expected = [{ DR_Values: 'Values' }, { DR_Values: 'value2' }];
3343
+ const result = highchartsRenderer.setNewFieldNames(res);
3344
+
3345
+ expect(result).toEqual(expected);
3346
+ });
3347
+
3348
+ it('should handle empty input', () => {
3349
+ const res = null;
3350
+ const expected = null;
3351
+ const result = highchartsRenderer.setNewFieldNames(res);
3352
+
3353
+ expect(result).toEqual(expected);
3354
+ });
3355
+
3356
+ it('should handle empty DR_Values array in input', () => {
3357
+ const res = [{}];
3358
+ const expected = [{ DR_Values: undefined }];
3359
+ const result = highchartsRenderer.setNewFieldNames(res);
3360
+
3361
+ expect(result).toEqual(expected);
3362
+ });
3363
+ });
3364
+
3365
+ describe('function getOptionsForLegends', () => {
3366
+ const rowAttrsLength = 1;
3367
+ let additionOptions;
3368
+
3369
+ beforeEach(() => {
3370
+ highchartsRenderer.isMobile = false;
3371
+ additionOptions = {
3372
+ legends_position: {value: null},
3373
+ hideChartHeader: false,
3374
+ subtitle: {subtitle: null}
3375
+ };
3376
+ });
3377
+
3378
+ it('should return topPosition for mobile devices and legends_position is not set to none', () => {
3379
+ highchartsRenderer.isMobile = true;
3380
+ const result = highchartsRenderer.getOptionsForLegends(additionOptions, rowAttrsLength, false, false);
3381
+ expect(result.align).toEqual('left');
3382
+ expect(result.verticalAlign).toEqual('top');
3383
+ expect(result.layout).toEqual('horizontal');
3384
+ });
3385
+
3386
+ it('should return topPosition when legends_position is not set and not line/pie chart', () => {
3387
+ const result = highchartsRenderer.getOptionsForLegends(additionOptions, rowAttrsLength, false, false);
3388
+ expect(result.align).toEqual('left');
3389
+ expect(result.verticalAlign).toEqual('top');
3390
+ expect(result.layout).toEqual('horizontal');
3391
+ });
3392
+
3393
+ it('should return leftPosition when legends_position is not set and line chart', () => {
3394
+ const result = highchartsRenderer.getOptionsForLegends(additionOptions, rowAttrsLength, true, false);
3395
+ expect(result.align).toEqual('left');
3396
+ expect(result.verticalAlign).toEqual('top');
3397
+ expect(result.layout).toEqual('vertical');
3398
+ });
3399
+
3400
+ it('should return rightPosition when legends_position is not set and pie chart', () => {
3401
+ const result = highchartsRenderer.getOptionsForLegends(additionOptions, rowAttrsLength, false, true);
3402
+ expect(result.align).toEqual('right');
3403
+ expect(result.verticalAlign).toEqual('top');
3404
+ expect(result.layout).toEqual('vertical');
3405
+ });
3406
+
3407
+ it('should return topPosition when legends_position is set to top', () => {
3408
+ additionOptions.legends_position.value = 'top';
3409
+ const result = highchartsRenderer.getOptionsForLegends(additionOptions, rowAttrsLength, false, false);
3410
+ expect(result.align).toEqual('left');
3411
+ expect(result.verticalAlign).toEqual('top');
3412
+ expect(result.layout).toEqual('horizontal');
3413
+ });
3414
+
3415
+ it('should return bottomPosition when legends_position is set to bottom', () => {
3416
+ additionOptions.legends_position.value = 'bottom';
3417
+ const result = highchartsRenderer.getOptionsForLegends(additionOptions, rowAttrsLength, false, false);
3418
+ expect(result.maxHeight).toEqual(37);
3419
+ });
3420
+
3421
+ it('should return leftPosition when legends_position is set to left', () => {
3422
+ additionOptions.legends_position.value = 'left';
3423
+ const result = highchartsRenderer.getOptionsForLegends(additionOptions, rowAttrsLength, false, false);
3424
+ expect(result.align).toEqual('left');
3425
+ expect(result.verticalAlign).toEqual('top');
3426
+ expect(result.layout).toEqual('vertical');
3427
+ });
3428
+
3429
+ it('should return rightPosition when legends_position is set to right', () => {
3430
+ additionOptions.legends_position.value = 'right';
3431
+ const result = highchartsRenderer.getOptionsForLegends(additionOptions, rowAttrsLength, false, false);
3432
+ expect(result.align).toEqual('right');
3433
+ expect(result.verticalAlign).toEqual('top');
3434
+ expect(result.layout).toEqual('vertical');
3435
+ });
3436
+
3437
+ it('should return disabled state when legends_position is set to none', () => {
3438
+ additionOptions.legends_position.value = 'none';
3439
+ const result = highchartsRenderer.getOptionsForLegends(additionOptions, rowAttrsLength, false, false);
3440
+ expect(result.enabled).toEqual(false);
3441
+ });
3442
+ });
3443
+
3444
+ describe('function setYAxisMinMax', () => {
3445
+ let yAxis;
3446
+
3447
+ beforeEach(() => {
3448
+ yAxis = { min: null, max: null };
3449
+ });
3450
+
3451
+ it('should set the minimum and maximum values of the yAxis if the axisYOptions is defined and has valid values', () => {
3452
+ const axisYOptions = { min: '10', max: '20' };
3453
+ highchartsRenderer.setYAxisMinMax(yAxis, axisYOptions);
3454
+ expect(yAxis.min).toEqual(10);
3455
+ expect(yAxis.max).toEqual(20);
3456
+ });
3457
+
3458
+ it('should set the minimum value of the yAxis to null if the axisYOptions has an invalid minimum value', () => {
3459
+ const axisYOptions = { min: 'invalid', max: '20' };
3460
+ highchartsRenderer.setYAxisMinMax(yAxis, axisYOptions);
3461
+ expect(yAxis.min).toBeNull();
3462
+ expect(yAxis.max).toEqual(20);
3463
+ });
3464
+
3465
+ it('should set the maximum value of the yAxis to null if the axisYOptions has an invalid maximum value', () => {
3466
+ const axisYOptions = { min: '10', max: 'invalid' };
3467
+ highchartsRenderer.setYAxisMinMax(yAxis, axisYOptions);
3468
+ expect(yAxis.min).toEqual(10);
3469
+ expect(yAxis.max).toBeNull();
3470
+ });
3471
+
3472
+ it('should set the minimum and maximum values of the yAxis to null if the axisYOptions is not defined', () => {
3473
+ highchartsRenderer.setYAxisMinMax(yAxis);
3474
+ expect(yAxis.min).toBeNull();
3475
+ expect(yAxis.max).toBeNull();
3476
+ });
3477
+ });
3478
+
3479
+ describe('function getDateFieldFormat', () => {
3480
+ let widget;
3481
+ let dateField;
3482
+
3483
+ beforeEach(() => {
3484
+ widget = {
3485
+ options: {
3486
+ date_aggregation_configs: [
3487
+ {
3488
+ field_id: 1,
3489
+ aggregate_by: 'quarter',
3490
+ is_formatting_by_aggregation_method: true,
3491
+ }
3492
+ ],
3493
+ },
3494
+ };
3495
+
3496
+ dateField = {
3497
+ id: 1,
3498
+ format: '%Y-%m-%d',
3499
+ };
3500
+ });
3501
+
3502
+ it('returns format as is when there is no aggregation config', () => {
3503
+ widget.options.date_aggregation_configs = [];
3504
+ const result = highchartsRenderer.getDateFieldFormat(widget, dateField);
3505
+ expect(result).toEqual('%Y-%m-%d');
3506
+ });
3507
+
3508
+ it('returns format by time frame when there is an aggregation config', () => {
3509
+ const result = highchartsRenderer.getDateFieldFormat(widget, dateField);
3510
+ expect(result).toEqual('[Q]Q-YY');
3511
+ });
3512
+
3513
+ it('returns format as is when there is an aggregation config but no time frame specified', () => {
3514
+ widget.options.date_aggregation_configs[0].aggregate_by = null;
3515
+ const result = highchartsRenderer.getDateFieldFormat(widget, dateField);
3516
+ expect(result).toEqual('%Y-%m-%d');
3517
+ });
3518
+ });
3519
+
3520
+ describe('function getDateFormatByTimeframe', () => {
3521
+ it('should return the correct date format for "month" timeframe', () => {
3522
+ const result = highchartsRenderer.getDateFormatByTimeframe('month', 'YYYY-MM-DD');
3523
+ expect(result).toBe('MMM-YY');
3524
+ });
3525
+
3526
+ it('should return the correct date format for "year" timeframe', () => {
3527
+ const result = highchartsRenderer.getDateFormatByTimeframe('year', 'YYYY-MM-DD');
3528
+ expect(result).toBe('YYYY');
3529
+ });
3530
+
3531
+ it('should return the correct date format for "quarter" timeframe', () => {
3532
+ const result = highchartsRenderer.getDateFormatByTimeframe('quarter', 'YYYY-MM-DD');
3533
+ expect(result).toBe('[Q]Q-YY');
3534
+ });
3535
+
3536
+ it('should return the default date format for unrecognized timeframe', () => {
3537
+ expect(highchartsRenderer.getDateFormatByTimeframe('day', 'YYYY-MM-DD')).toBe('YYYY-MM-DD');
3538
+ expect(highchartsRenderer.getDateFormatByTimeframe('week', 'YYYY-MM-DD')).toBe('YYYY-MM-DD');
3539
+ });
3540
+ });
3541
+
3542
+ describe('function getOthersName', () => {
3543
+ it('returns the filtered out field name when it exists in options', () => {
3544
+ const options = {
3545
+ total_value_options: {
3546
+ filter_options: {
3547
+ filteredOutFieldName: 'Excluded'
3548
+ }
3549
+ }
3550
+ };
3551
+ const othersName = highchartsRenderer.getOthersName(options);
3552
+ expect(othersName).toBe('Excluded');
3553
+ });
3554
+
3555
+ it('returns "Others" when the filtered out field name does not exist in options', () => {
3556
+ const options = {};
3557
+ const othersName = highchartsRenderer.getOthersName(options);
3558
+ expect(othersName).toBe('Others');
3559
+ });
3560
+ });
3561
+
3562
+ describe('function transformRowsAndColsForBreakdown', () => {
3563
+ let point;
3564
+ let opts;
3565
+
3566
+ beforeEach(() => {
3567
+ point = {
3568
+ options: {},
3569
+ colKeys: ["Col1", "Col2", "Others"],
3570
+ };
3571
+
3572
+ opts = {
3573
+ total_value_options: {
3574
+ filter_options: {
3575
+ filteredOutFieldName: "Others",
3576
+ },
3577
+ },
3578
+ };
3579
+ });
3580
+
3581
+ it("should replace Others with DR_Others in cols and return rows as cols when point is not total", () => {
3582
+ const rows = ["Row1", "Row2"];
3583
+ const cols = ["Col1", "Col2", "Others"];
3584
+ const expectedResult = {
3585
+ rows: cols,
3586
+ cols: [point.colKeys[0]],
3587
+ };
3588
+
3589
+ const result = highchartsRenderer.transformRowsAndColsForBreakdown(rows, cols, point, opts);
3590
+ expect(result).toEqual(expectedResult);
3591
+ });
3592
+
3593
+ it("should set rows to empty array when point is total", () => {
3594
+ const rows = ["Row1", "Row2"];
3595
+ const cols = ["Col1", "Col2", "Not_Others"];
3596
+ point.options.isTotal = true;
3597
+ const expectedResult = {
3598
+ rows: [],
3599
+ cols: cols,
3600
+ };
3601
+
3602
+ const result = highchartsRenderer.transformRowsAndColsForBreakdown(rows, cols, point, opts);
3603
+ expect(result).toEqual(expectedResult);
3604
+ });
3605
+ });
3606
+
3607
+ describe('function getBreakdownXAxisLabelFormatter', () => {
3608
+ it('returns correct formatter function', () => {
3609
+ const chartSeries = [{
3610
+ data: [
3611
+ { name: 'Label1', isTotal: true },
3612
+ { name: 'Label2', isTotal: false }
3613
+ ]
3614
+ }];
3615
+ const formatter = highchartsRenderer.getBreakdownXAxisLabelFormatter(chartSeries);
3616
+
3617
+ const totalResult = formatter.apply({ value: 'Label1' });
3618
+ expect(totalResult).toEqual('<span style=\"\">Label1</span>');
3619
+
3620
+ const normalResult = formatter.apply({ value: 'Label2' });
3621
+ expect(normalResult).toEqual('<span style="font-weight: normal; color: #51566f;">Label2</span>');
3622
+ });
3623
+ });
3624
+
3625
+ describe('function getTrendSeriesName', () => {
3626
+ it('returns expected name when name is present in the series object', () => {
3627
+ const series = {
3628
+ name: 'Sales'
3629
+ };
3630
+ const expectedName = 'Trend Line (Sales)';
3631
+ expect(highchartsRenderer.getTrendSeriesName(series)).toBe(expectedName);
3632
+ });
3633
+
3634
+ it('returns expected name when no name is present in the series object', () => {
3635
+ const series = {};
3636
+ const expectedName = 'Trend Line';
3637
+ expect(highchartsRenderer.getTrendSeriesName(series)).toBe(expectedName);
3638
+ });
3639
+ });
2329
3640
  });