@datarailsshared/dr_renderer 1.2.295 → 1.2.296

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@datarailsshared/dr_renderer",
3
- "version": "1.2.295",
3
+ "version": "1.2.296",
4
4
  "description": "DataRails charts and tables renderer",
5
5
  "keywords": [
6
6
  "datarails",
@@ -687,8 +687,8 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
687
687
  stickOnContact: true,
688
688
  hideDelay: 1500,
689
689
  formatter: function () {
690
- const rowKey = pivotData.rowAttrs.length ? _.get(this.point, 'series.name') || "" : "";
691
- const colKey = _.get(this.point, 'name') || this.x.name[0] || "";
690
+ const rowKey = pivotData.rowAttrs.length ? lodash.get(this.point, 'series.name') || "" : "";
691
+ const colKey = lodash.get(this.point, 'name') || this.x.name[0] || "";
692
692
  const insight = pivotData.getInsight(colKey, rowKey) || {};
693
693
  setTimeout(() => {
694
694
  var aggr = highchartsRenderer.defaultFormatterToTooltip(pivotData, opts);
@@ -1598,7 +1598,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
1598
1598
  if (value.trend === 'total') {
1599
1599
  keys = value.key;
1600
1600
  } else {
1601
- _.forEach(value.key, (item) => {
1601
+ lodash.forEach(value.key, (item) => {
1602
1602
  const findKeyByValue = lodash.find(
1603
1603
  Object.keys(pivotData.dateValuesDictionary || {}),
1604
1604
  key => pivotData.dateValuesDictionary[key] === item
@@ -3579,7 +3579,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
3579
3579
  chartOptions.legend.useHTML = true;
3580
3580
  chartOptions.legend.labelFormatter = function() {
3581
3581
  const name = this.name;
3582
- const findTotal = _.find(this.options.data, {isTotal: true});
3582
+ const findTotal = lodash.find(this.options.data, {isTotal: true});
3583
3583
  const color = lodash.get(findTotal, 'color') ? findTotal.color : this.color;
3584
3584
  return `<span style="margin: 5px; vertical-align: middle; display:inline-block; background-color: ${color};
3585
3585
  width: 12px; height: 12px; border-radius: 50%"></span>
@@ -3699,7 +3699,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
3699
3699
  chartOptions.legend.useHTML = true;
3700
3700
  chartOptions.legend.labelFormatter = function() {
3701
3701
  const name = this.options.className ? 'Total': this.name;
3702
- const findTotal = _.find(this.options.data, {isTotal: true});
3702
+ const findTotal = lodash.find(this.options.data, {isTotal: true});
3703
3703
  const color = lodash.get(findTotal, 'color') ? findTotal.color : this.color;
3704
3704
  return '<span style="margin: 5px; vertical-align: middle; display:inline-block; background-color: '+ color + '; width: 12px; height: 12px; border-radius: 50%"></span><span style="color: #000; display: inline-block; margin: 5px; vertical-align: middle;">' + name + '</span>';
3705
3705
  }
@@ -4936,7 +4936,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
4936
4936
  }
4937
4937
 
4938
4938
  if (typeof (value) != 'number') {
4939
- const drAdditionalField = _.find($.pivotUtilities.additionalFieldsList, {key: value});
4939
+ const drAdditionalField = lodash.find($.pivotUtilities.additionalFieldsList, {key: value});
4940
4940
  if (drAdditionalField && drAdditionalField.key)
4941
4941
  return drAdditionalField.key;
4942
4942
 
@@ -8045,8 +8045,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
8045
8045
  };
8046
8046
  }
8047
8047
  } else {
8048
- if (fieldFilter && fieldFilter.type && fieldFilter.type === 'Date'
8049
- && fieldFilter.datetypevalues && fieldFilter.datetypevalues) {
8048
+ if (fieldFilter && fieldFilter.type && fieldFilter.type === 'Date' && fieldFilter.datetypevalues) {
8050
8049
  if (fieldFilter.datetypevalues.datetype === "frame") {
8051
8050
  displayname += ` (${fieldFilter.datetypevalues.val.timeframe})`;
8052
8051
  } else if (fieldFilter.datetypevalues.datetype === "range") {
@@ -8058,7 +8057,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
8058
8057
  // range timestamps currently are set presupposing that user selects UTC dates,
8059
8058
  // that is why for consistency we also should show in filters values which user selected
8060
8059
  // and not local dates, that can differ
8061
- _.forEach(Object.keys(dates), key => {
8060
+ lodash.forEach(Object.keys(dates), key => {
8062
8061
  const dateConfiguration = dates[key];
8063
8062
  const timestamp = dateConfiguration.timestamp;
8064
8063
  if (timestamp) {
@@ -8124,7 +8123,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
8124
8123
  highchartsRenderer.getDashboardOverrideValues = function (data_model, graph, local_current_dashboard) {
8125
8124
  let overrideValues = [];
8126
8125
 
8127
- if (!local_current_dashboard == undefined) {
8126
+ if (!local_current_dashboard) {
8128
8127
  local_current_dashboard = data_model.current_dashboard;
8129
8128
  }
8130
8129
 
@@ -8200,11 +8199,11 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
8200
8199
  local_current_dashboard = data_model.current_dashboard;
8201
8200
  }
8202
8201
 
8203
- if (local_current_dashboard.date_tags.length > 0) {
8202
+ if (local_current_dashboard.date_tags && local_current_dashboard.date_tags.length > 0) {
8204
8203
  return 'date_tags';
8205
8204
  }
8206
8205
 
8207
- if (local_current_dashboard.plan_tags.length > 0) {
8206
+ if (local_current_dashboard.plan_tags && local_current_dashboard.plan_tags.length > 0) {
8208
8207
  return 'plan_tags';
8209
8208
  }
8210
8209
  };
@@ -8230,7 +8229,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
8230
8229
  };
8231
8230
 
8232
8231
  highchartsRenderer.getDashboardApplyScenarios = function (data_model, graph, local_current_dashboard) {
8233
- if (!local_current_dashboard == undefined) {
8232
+ if (local_current_dashboard == undefined) {
8234
8233
  local_current_dashboard = data_model.current_dashboard;
8235
8234
  }
8236
8235
 
@@ -8256,7 +8255,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
8256
8255
  };
8257
8256
 
8258
8257
  highchartsRenderer.isDate = function (date) {
8259
- return ((new Date(date) !== "Invalid Date" && !isNaN(new Date(date))));
8258
+ return new Date(date) !== "Invalid Date" && !isNaN(new Date(date));
8260
8259
  };
8261
8260
 
8262
8261
  highchartsRenderer.isDateFormat = function (datestr, format) {
@@ -8264,7 +8263,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
8264
8263
  };
8265
8264
 
8266
8265
  highchartsRenderer.containsIgnoreCase = function (str, it) {
8267
- return str.toLowerCase().indexOf(it) != -1;
8266
+ return str.toLowerCase().indexOf(it.toLowerCase()) != -1;
8268
8267
  };
8269
8268
 
8270
8269
  highchartsRenderer.createDateTypeFromValue = function (fieldnametoFilter, format, colName) {
@@ -9100,7 +9099,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
9100
9099
 
9101
9100
  highchartsRenderer.getDateFieldFormat = function(widget, dateField) {
9102
9101
  const aggregationConfig = widget.options && widget.options.date_aggregation_configs
9103
- ? _.find(widget.options.date_aggregation_configs, { field_id: dateField.id })
9102
+ ? lodash.find(widget.options.date_aggregation_configs, { field_id: dateField.id })
9104
9103
  : null;
9105
9104
 
9106
9105
  if (aggregationConfig && aggregationConfig.aggregate_by && aggregationConfig.is_formatting_by_aggregation_method) {
@@ -9174,7 +9173,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
9174
9173
  rowData.splice(rowIndex, 1);
9175
9174
  } else {
9176
9175
  const totalRow = {};
9177
- _.forEach(categoryFields, (field, fieldKey) => {
9176
+ lodash.forEach(categoryFields, (field, fieldKey) => {
9178
9177
  totalRow[field.name] = value.key[fieldKey];
9179
9178
  });
9180
9179
  totalRow[valueField.name] = sum;
@@ -9232,7 +9231,6 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
9232
9231
  });
9233
9232
  }
9234
9233
 
9235
-
9236
9234
  highchartsRenderer.getFiscalYearMonthModifier = function() {
9237
9235
  return lodash.get(document, 'ReportHippo.user.organization.fiscal_year_starts_from', 1) - 1;
9238
9236
  }
@@ -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";
@@ -1197,7 +1197,7 @@ describe('highcharts_renderer', () => {
1197
1197
  });
1198
1198
  });
1199
1199
 
1200
- describe('aggregators', () => {
1200
+ describe('function aggregators', () => {
1201
1201
  const aggregatorsIds = ['SUM', 'COUNT', 'COUNT_UNIQUE', 'UNIQUE_VALUES', 'AVG', 'MIN', 'MAX'];
1202
1202
 
1203
1203
  it('Count and names', () => {
@@ -2326,4 +2326,1202 @@ describe('highcharts_renderer', () => {
2326
2326
  });
2327
2327
  });
2328
2328
  });
2329
+
2330
+
2331
+ describe('function getChartAxisLabel', () => {
2332
+ it('should return default value', () => {
2333
+ expect(highchartsRenderer.getChartAxisLabel('invalidType')).toBe('Axis (Category)')
2334
+ });
2335
+
2336
+ it('should return chart type axisName', () => {
2337
+ expect(highchartsRenderer.getChartAxisLabel(highchartsRenderer.CHART_TYPES.COLUMN_CHART)).toBe('X - Axis')
2338
+ });
2339
+ });
2340
+
2341
+ describe('function getChartLegendLabel', () => {
2342
+ it('should return default value', () => {
2343
+ expect(highchartsRenderer.getChartLegendLabel('invalidType')).toBe('Legend (Series)')
2344
+ });
2345
+
2346
+ it('should return chart type legendName ', () => {
2347
+ expect(highchartsRenderer.getChartLegendLabel(highchartsRenderer.CHART_TYPES.COLUMN_CHART)).toBe('Data series')
2348
+ });
2349
+ });
2350
+
2351
+ describe('Function getFilterLabel', () => {
2352
+ describe('Should present template name', () => {
2353
+ let fieldFilter;
2354
+ let showTemplateName;
2355
+
2356
+ beforeEach(() => {
2357
+ fieldFilter = {
2358
+ name: 'RH_DIM_test',
2359
+ datetypevalues: { datetype: 'range' }
2360
+ };
2361
+ showTemplateName = false;
2362
+ });
2363
+
2364
+ it('should return fieldFilter.new_name without "RH_DIM_" if it exists', () => {
2365
+ fieldFilter.new_name = 'RH_DIM_test_new_name';
2366
+ const result = highchartsRenderer.getFilterLabel(fieldFilter, showTemplateName);
2367
+ expect(result).toEqual({
2368
+ label: 'test_new_name (All)',
2369
+ tooltip: 'test_new_name (All)'
2370
+ });
2371
+ });
2372
+
2373
+ it('should return highchartsRenderer.getFieldName(fieldFilter.name) without "RH_DIM_" if fieldFilter.new_name is falsy', () => {
2374
+ spyOn(highchartsRenderer, 'getFieldName').and.returnValue('RH_DIM_test_fieldName');
2375
+ const result = highchartsRenderer.getFilterLabel(fieldFilter, showTemplateName);
2376
+ expect(highchartsRenderer.getFieldName).toHaveBeenCalledWith('RH_DIM_test');
2377
+ expect(result).toEqual({
2378
+ label: 'test_fieldName (All)',
2379
+ tooltip: 'test_fieldName (All)'
2380
+ });
2381
+ });
2382
+
2383
+ it('should append template_name to displayname if showTemplateName is true and fieldFilter.template_name is truthy', () => {
2384
+ fieldFilter.new_name = null;
2385
+ fieldFilter.template_name = 'templateName';
2386
+ showTemplateName = true;
2387
+ const result = highchartsRenderer.getFilterLabel(fieldFilter, showTemplateName);
2388
+ expect(result).toEqual({
2389
+ label: 'templateName - test (range)',
2390
+ tooltip: 'templateName - test (range)'
2391
+ });
2392
+ });
2393
+
2394
+ it('should append template_name to displayname if showTemplateName is true and fieldFilter.template_name is truthy', () => {
2395
+ fieldFilter.new_name = null;
2396
+ fieldFilter.template_name = 'templateName';
2397
+ showTemplateName = true;
2398
+ const result = highchartsRenderer.getFilterLabel(fieldFilter, showTemplateName);
2399
+ expect(result).toEqual({
2400
+ label: 'templateName - test (range)',
2401
+ tooltip: 'templateName - test (range)'
2402
+ });
2403
+ });
2404
+
2405
+ it('should return label and tooltip with datetypevalues.datetype if datetypevalues is truthy and datetype is "range" or "frame"', () => {
2406
+ fieldFilter.new_name = null;
2407
+ fieldFilter.template_name = 'templateName';
2408
+ fieldFilter.datetypevalues.datetype = 'frame';
2409
+ const result = highchartsRenderer.getFilterLabel(fieldFilter, showTemplateName);
2410
+ expect(result).toEqual({
2411
+ label: 'test (frame)',
2412
+ tooltip: 'test (frame)'
2413
+ });
2414
+ });
2415
+ });
2416
+
2417
+ describe('Should present includes/excludes names', () => {
2418
+ let fieldFilter;
2419
+
2420
+ beforeEach(() => {
2421
+ fieldFilter = {
2422
+ name: 'test',
2423
+ includes: null,
2424
+ excludes: null,
2425
+ type: 'Text',
2426
+ };
2427
+ });
2428
+
2429
+ it('Should return "none" label when excludes empty', () => {
2430
+ fieldFilter.includes = [];
2431
+ const res = highchartsRenderer.getFilterLabel(fieldFilter, false);
2432
+ expect(res.label).toEqual('test (none)');
2433
+ expect(res.tooltip).toEqual('test (none)');
2434
+ });
2435
+
2436
+ it('Should return "All" label when excludes empty', () => {
2437
+ fieldFilter.excludes = [];
2438
+ const res = highchartsRenderer.getFilterLabel(fieldFilter, false);
2439
+ expect(res.label).toEqual('test (All)');
2440
+ expect(res.tooltip).toEqual('test (All)');
2441
+ });
2442
+
2443
+ it('Should return "many" label when includes/excludes has more than MAX_SELECTED_ITEMS_IN_LABEL items', () => {
2444
+ fieldFilter.includes = new Array(highchartsRenderer.MAX_SELECTED_ITEMS_IN_LABEL).fill('val');
2445
+ let res = highchartsRenderer.getFilterLabel(fieldFilter, false);
2446
+ expect(res.label).toEqual('test (many)');
2447
+ expect(res.tooltip).toEqual('test (' + fieldFilter.includes.join(', ') + ')');
2448
+
2449
+ fieldFilter.excludes = fieldFilter.includes;
2450
+ delete fieldFilter.includes;
2451
+ res = highchartsRenderer.getFilterLabel(fieldFilter, false);
2452
+ expect(res.label).toEqual('test (Exclusions many)');
2453
+ expect(res.tooltip).toEqual('test (Exclusions: ' + fieldFilter.excludes.join(', ') + ')');
2454
+ });
2455
+
2456
+ it('Should return "many" in label when includes has label length more than MAX_SELECTED_ITEMS_CHARECHTERS_IN_LABEL', () => {
2457
+ fieldFilter.includes = ['[null]', 'long long long value 2', 'long long long value 3'];
2458
+ let res = highchartsRenderer.getFilterLabel(fieldFilter, false);
2459
+ expect(res.label).toEqual('test (many)');
2460
+ expect(res.tooltip).toEqual('test (' + fieldFilter.includes.join(',') + ')');
2461
+ });
2462
+
2463
+ it('Should return "many" in label when excludes has label length more than MAX_SELECTED_ITEMS_CHARECHTERS_IN_LABEL', () => {
2464
+ fieldFilter.excludes = ['[null]', 'long long long value 2', 'long long long value 3'];
2465
+ let res = highchartsRenderer.getFilterLabel(fieldFilter, false);
2466
+ expect(res.label).toEqual('test (Exclusions: many)');
2467
+ expect(res.tooltip).toEqual('test (Exclusions: ' + fieldFilter.excludes.join(',') + ')');
2468
+ });
2469
+
2470
+ it('Should exclude "[null]" from includes if allow_nulls enabled', () => {
2471
+ fieldFilter.allow_nulls = true;
2472
+ fieldFilter.includes = ['value 1', '[null]'];
2473
+ let res = highchartsRenderer.getFilterLabel(fieldFilter, false);
2474
+ expect(res.label).toEqual('test (value 1)');
2475
+ expect(res.tooltip).toEqual('test (' + fieldFilter.includes[0] + ')');
2476
+ });
2477
+
2478
+ it('Should exclude "[null]" from excludes if allow_nulls enabled', () => {
2479
+ fieldFilter.allow_nulls = true;
2480
+ fieldFilter.excludes = ['value 1', '[null]'];
2481
+ let res = highchartsRenderer.getFilterLabel(fieldFilter, false);
2482
+ expect(res.label).toEqual('test (Exclusions: value 1)');
2483
+ expect(res.tooltip).toEqual('test (Exclusions: ' + fieldFilter.excludes[0] + ')');
2484
+ });
2485
+
2486
+ it('Should present formatted dates in includes. Get formatted value from invertValueFormatMap object if exist ', () => {
2487
+ fieldFilter.includes = [1682063884, 1682060884, 1682013884];
2488
+ fieldFilter.type = 'Date';
2489
+ fieldFilter.valueFormatMap = {
2490
+ 'April 21, 2023': 1682063884
2491
+ };
2492
+ let res = highchartsRenderer.getFilterLabel(fieldFilter, false);
2493
+ expect(res.label).toEqual('test (April 21, 2023,04/21/2023,04/20/2023)');
2494
+ expect(res.tooltip).toEqual('test (April 21, 2023,04/21/2023,04/20/2023)');
2495
+ });
2496
+
2497
+ it('Should present formatted dates in excludes. Get formatted value from invertValueFormatMap object if exist ', () => {
2498
+ fieldFilter.excludes = [1682063884, 1682060884];
2499
+ fieldFilter.type = 'Date';
2500
+ fieldFilter.valueFormatMap = {
2501
+ 'April 21, 2023': 1682063884
2502
+ };
2503
+ let res = highchartsRenderer.getFilterLabel(fieldFilter, false);
2504
+ expect(res.label).toEqual('test (Exclusions: April 21, 2023,04/21/2023)');
2505
+ expect(res.tooltip).toEqual('test (Exclusions: April 21, 2023,04/21/2023)');
2506
+ });
2507
+ });
2508
+
2509
+ describe('Should present date range or frame selection', () => {
2510
+ let fieldFilter;
2511
+
2512
+ beforeEach(() => {
2513
+ fieldFilter = {
2514
+ name: 'test',
2515
+ includes: null,
2516
+ excludes: null,
2517
+ type: 'Date',
2518
+ };
2519
+ });
2520
+
2521
+ it('Should return "range" label when datetype is range', () => {
2522
+ fieldFilter.datetypevalues = {
2523
+ datetype: 'range',
2524
+ val: {
2525
+ fromdate: 1682060884,
2526
+ todate: 1682063884,
2527
+ }
2528
+ };
2529
+ const res = highchartsRenderer.getFilterLabel(fieldFilter, false);
2530
+ expect(res.label).toEqual('test (4/21/2023-4/21/2023)');
2531
+ expect(res.tooltip).toEqual('test (4/21/2023-4/21/2023)');
2532
+ });
2533
+
2534
+ it('Should return "frame" label when datetype is frame', () => {
2535
+ fieldFilter.datetypevalues = {
2536
+ datetype: 'frame',
2537
+ val: {
2538
+ timeframe: 'xday'
2539
+ }
2540
+ };
2541
+ const res = highchartsRenderer.getFilterLabel(fieldFilter, false);
2542
+ expect(res.label).toEqual('test (xday)');
2543
+ expect(res.tooltip).toEqual('test (xday)');
2544
+ });
2545
+
2546
+ it('Should return "All" label when datetype is not selected', () => {
2547
+ fieldFilter.datetypevalues = {};
2548
+ const res = highchartsRenderer.getFilterLabel(fieldFilter, false);
2549
+ expect(res.label).toEqual('test (All)');
2550
+ expect(res.tooltip).toEqual('test (All)');
2551
+ });
2552
+ });
2553
+
2554
+ describe('Should present advanced filter selection', () => {
2555
+ it('Should return "Advanced" label when advanced type in values', () => {
2556
+ const res = highchartsRenderer.getFilterLabel({ name: 'test', values: { type: 'advanced'} }, false);
2557
+ expect(res.label).toEqual('test (Advanced)');
2558
+ expect(res.tooltip).toEqual('test (Advanced)');
2559
+ });
2560
+
2561
+ it('Should return "Advanced" label when advanced type in datetypevalues', () => {
2562
+ const res = highchartsRenderer.getFilterLabel({ name: 'test', datetypevalues: { type: 'advanced'} }, false);
2563
+ expect(res.label).toEqual('test (Advanced)');
2564
+ expect(res.tooltip).toEqual('test (Advanced)');
2565
+ });
2566
+ });
2567
+
2568
+ describe('Should present All if nothing selected', () => {
2569
+ it('Should return "All" label when nothing selected', () => {
2570
+ const res = highchartsRenderer.getFilterLabel({ name: 'test'}, false);
2571
+ expect(res.label).toEqual('test (All)');
2572
+ expect(res.tooltip).toEqual('test (All)');
2573
+ });
2574
+ });
2575
+ });
2576
+
2577
+ describe('function getRelevantFilters', () => {
2578
+ it('should return an empty array if given an empty array', () => {
2579
+ const filters = highchartsRenderer.getRelevantFilters([]);
2580
+ expect(filters).toEqual([]);
2581
+ });
2582
+
2583
+ it('should filter out elements that do not have includes, excludes, or datetypevalues properties', () => {
2584
+ const filters = [
2585
+ {fields: ['field1'], otherProperty: 'value'},
2586
+ {fields: ['field2'], includes: [1, 2, 3]},
2587
+ {fields: ['field3'], excludes: ['abc']},
2588
+ {fields: ['field4'], datetypevalues: {datetype: 'date', start: '2022-01-01', end: '2022-01-31'}}
2589
+ ];
2590
+ const relevantFilters = highchartsRenderer.getRelevantFilters(filters);
2591
+ expect(relevantFilters.length).toEqual(3);
2592
+ expect(relevantFilters).toContainEqual({
2593
+ fields: ['field2'],
2594
+ values: [1, 2, 3],
2595
+ is_excluded: false,
2596
+ allow_nulls: false,
2597
+ inject_only: false
2598
+ });
2599
+ expect(relevantFilters).toContainEqual({
2600
+ fields: ['field3'],
2601
+ values: ['abc'],
2602
+ is_excluded: true,
2603
+ allow_nulls: false,
2604
+ inject_only: false
2605
+ });
2606
+ expect(relevantFilters).toContainEqual({
2607
+ fields: ['field4'],
2608
+ values: {datetype: 'date', start: '2022-01-01', end: '2022-01-31'},
2609
+ is_excluded: false,
2610
+ allow_nulls: false,
2611
+ inject_only: false
2612
+ });
2613
+ });
2614
+
2615
+ it('should handle empty includes and excludes properties by returning an empty values array', () => {
2616
+ const filters = [
2617
+ {fields: ['field1'], includes: []},
2618
+ {fields: ['field2'], includes: [1, 2, 3], excludes: []},
2619
+ {fields: ['field3'], excludes: ['abc']}
2620
+ ];
2621
+ const relevantFilters = highchartsRenderer.getRelevantFilters(filters);
2622
+ expect(relevantFilters.length).toEqual(3);
2623
+ expect(relevantFilters[0].values).toEqual([]);
2624
+ expect(relevantFilters[1].values).toEqual([1, 2, 3]);
2625
+ expect(relevantFilters[2].values).toEqual(['abc']);
2626
+ });
2627
+
2628
+ it('should set is_excluded to true for elements that have an excludes property', () => {
2629
+ const filters = [
2630
+ {fields: ['field1'], includes: [1, 2, 3]},
2631
+ {fields: ['field2'], excludes: ['abc']},
2632
+ {fields: ['field3'], excludes: [null]}
2633
+ ];
2634
+ const relevantFilters = highchartsRenderer.getRelevantFilters(filters);
2635
+ expect(relevantFilters.length).toEqual(3);
2636
+ expect(relevantFilters[0].is_excluded).toBe(false);
2637
+ expect(relevantFilters[1].is_excluded).toBe(true);
2638
+ expect(relevantFilters[2].is_excluded).toBe(true);
2639
+ });
2640
+
2641
+ it('should handle datetypevalues', () => {
2642
+ const filtersList = [
2643
+ {
2644
+ fields: ['date'],
2645
+ datetypevalues: {
2646
+ datetype: 'last_month',
2647
+ from: null,
2648
+ to: null
2649
+ }
2650
+ }
2651
+ ];
2652
+
2653
+ const expected = [
2654
+ {
2655
+ fields: ['date'],
2656
+ values: {
2657
+ datetype: 'last_month',
2658
+ from: null,
2659
+ to: null
2660
+ },
2661
+ is_excluded: false,
2662
+ allow_nulls: false,
2663
+ inject_only: false
2664
+ }
2665
+ ];
2666
+
2667
+ expect(highchartsRenderer.getRelevantFilters(filtersList)).toEqual(expected);
2668
+ });
2669
+ });
2670
+
2671
+ describe('function parseOptionsToObject', () => {
2672
+ it('should return an object when given an object', () => {
2673
+ const obj = { key: 'value' };
2674
+ const result = highchartsRenderer.parseOptionsToObject(obj);
2675
+ expect(result).toEqual(obj);
2676
+ });
2677
+
2678
+ it('should return an empty object when given empty string', () => {
2679
+ let result = highchartsRenderer.parseOptionsToObject('');
2680
+ expect(result).toEqual({});
2681
+ });
2682
+
2683
+ it('should parse a JSON string into an object', () => {
2684
+ const str = '{ "key": "value" }';
2685
+ const result = highchartsRenderer.parseOptionsToObject(str);
2686
+ expect(result).toEqual({ key: 'value' });
2687
+ });
2688
+
2689
+ it('should remove line breaks from the JSON string before parsing', () => {
2690
+ const str = '{\n "key": "value"\n}';
2691
+ const result = highchartsRenderer.parseOptionsToObject(str);
2692
+ expect(result).toEqual({ key: 'value' });
2693
+ });
2694
+
2695
+ it('should throw an error if given an invalid JSON string', () => {
2696
+ const str = '{ "key": "value" ';
2697
+ expect(() => highchartsRenderer.parseOptionsToObject(str)).toThrow();
2698
+ });
2699
+ });
2700
+
2701
+ describe('function getDashboardOverrideValues', () => {
2702
+ let dataModel;
2703
+ let graph;
2704
+ let localCurrentDashboard;
2705
+
2706
+ beforeEach(() => {
2707
+ dataModel = {
2708
+ current_dashboard: {
2709
+ fields_selectors: [
2710
+ {
2711
+ value: 'field1',
2712
+ fields_selector: {
2713
+ default_field: { id: 'field1', name: 'Field 1' },
2714
+ other_fields: [
2715
+ { id: 'field1', name: 'Field 1' },
2716
+ { id: 'field2', name: 'Field 2' },
2717
+ ]
2718
+ }
2719
+ },
2720
+ {
2721
+ value: 'field2',
2722
+ fields_selector: {
2723
+ default_field: { id: 'field2', name: 'Field 2' },
2724
+ other_fields: [
2725
+ { id: 'field1', name: 'Field 1' },
2726
+ { id: 'field2', name: 'Field 2' },
2727
+ ]
2728
+ }
2729
+ }
2730
+ ]
2731
+ },
2732
+ ebmedded_override_value_ids: []
2733
+ };
2734
+
2735
+ graph = {
2736
+ vals: [{ field: 'field1' }]
2737
+ };
2738
+
2739
+ localCurrentDashboard = {
2740
+ fields_selectors: [
2741
+ {
2742
+ value: 'field2',
2743
+ fields_selector: {
2744
+ default_field: { id: 'field1', name: 'Field 1' },
2745
+ other_fields: [
2746
+ { id: 'field1', name: 'Field 1' },
2747
+ { id: 'field2', name: 'Field 2' },
2748
+ ]
2749
+ }
2750
+ }
2751
+ ]
2752
+ };
2753
+ });
2754
+
2755
+ it('should return empty array when no conditions met', () => {
2756
+ expect(highchartsRenderer.getDashboardOverrideValues({}, {}, {})).toEqual([]);
2757
+ });
2758
+
2759
+ it('should return array of value objects when ebmedded_override_value_ids exist', () => {
2760
+ dataModel.ebmedded_override_value_ids = [1, 2, 3]
2761
+ expect(highchartsRenderer.getDashboardOverrideValues(dataModel, {}, {})).toEqual([
2762
+ { id: 1 },
2763
+ { id: 2 },
2764
+ { id: 3 }
2765
+ ]);
2766
+ });
2767
+
2768
+ it('should return empty array when local_current_dashboard undefined', () => {
2769
+ expect(highchartsRenderer.getDashboardOverrideValues({}, graph, undefined)).toEqual([]);
2770
+ });
2771
+
2772
+ it('should return empty array when graph undefined', () => {
2773
+ expect(highchartsRenderer.getDashboardOverrideValues(dataModel, undefined, localCurrentDashboard)).toEqual([]);
2774
+ });
2775
+
2776
+ it('should return empty array when graph vals empty', () => {
2777
+ expect(highchartsRenderer.getDashboardOverrideValues(dataModel, { vals: [] }, localCurrentDashboard)).toEqual([]);
2778
+ });
2779
+
2780
+ it('should return empty array when graph vals length > 1', () => {
2781
+ expect(highchartsRenderer.getDashboardOverrideValues(dataModel, { vals: [{ field: 'field1' }, { field: 'field2' }] }, localCurrentDashboard)).toEqual([]);
2782
+ });
2783
+
2784
+ it('should return empty array when no matching field selector', () => {
2785
+ expect(highchartsRenderer.getDashboardOverrideValues(dataModel, { vals: [{ field: 'field3' }] }, localCurrentDashboard)).toEqual([]);
2786
+ });
2787
+
2788
+ it('should return value object when selector value != graph val field', () => {
2789
+ expect(highchartsRenderer.getDashboardOverrideValues(dataModel, graph, localCurrentDashboard)).toEqual([{ id: 'field2', name: 'Field 2' }]);
2790
+ });
2791
+ });
2792
+
2793
+ describe('function getDashboardFilters', () => {
2794
+ let data_model;
2795
+ let remove_filters_from_global;
2796
+
2797
+ beforeEach(() => {
2798
+ data_model = {
2799
+ current_dashboard: {
2800
+ filters: [
2801
+ {
2802
+ fields: [{id: '1', name: 'Field 1'}],
2803
+ includes: ['value 1']
2804
+ },
2805
+ {
2806
+ fields: [{id: '2', name: 'Field 2'}],
2807
+ includes: ['value 2']
2808
+ }
2809
+ ]
2810
+ },
2811
+ ebmedded_filters: []
2812
+ };
2813
+ remove_filters_from_global = [{id: '2', name: 'Field 2'}];
2814
+ });
2815
+
2816
+ it('should return an empty array when no relevant filters found', () => {
2817
+ const local_current_dashboard = {
2818
+ fields_selectors: [{value: '1', fields_selector: {default_field: {id: '1'}}}]
2819
+ };
2820
+ const result = highchartsRenderer.getDashboardFilters({}, [], local_current_dashboard);
2821
+ expect(result).toEqual([]);
2822
+ });
2823
+
2824
+ it('should return an array of relevant filters from the current dashboard', () => {
2825
+ const result = highchartsRenderer.getDashboardFilters(data_model, [], data_model.current_dashboard);
2826
+ expect(result.length).toEqual(2);
2827
+ });
2828
+
2829
+ it('should return an array of relevant filters from the current dashboard and embedded filters', () => {
2830
+ data_model.ebmedded_filters = [{
2831
+ fields: [{id: '3', name: 'Field 3'}],
2832
+ includes: ['value 3']
2833
+ }];
2834
+ const result = highchartsRenderer.getDashboardFilters(data_model, [], data_model.current_dashboard);
2835
+ expect(result.length).toEqual(3);
2836
+ });
2837
+
2838
+ it('should remove specified fields from the returned filters array', () => {
2839
+ const result = highchartsRenderer.getDashboardFilters(data_model, remove_filters_from_global, data_model.current_dashboard);
2840
+ expect(result.length).toEqual(1);
2841
+ });
2842
+
2843
+ it('should add "[null]" to values array for filters with "allow_nulls" flag', () => {
2844
+ const currentDashboardWithNull = {
2845
+ filters: [
2846
+ {
2847
+ fields: [{ id: 'field1', name: 'Field 1' }],
2848
+ includes: ['value1', 'value2'],
2849
+ allow_nulls: false,
2850
+ },
2851
+ ],
2852
+ };
2853
+ const dataModelWithNull = { current_dashboard: currentDashboardWithNull };
2854
+ const result = highchartsRenderer.getDashboardFilters(dataModelWithNull);
2855
+ expect(result[0].values).toEqual(['value1', 'value2']);
2856
+ });
2857
+
2858
+ it('should not add "[null]" to values array if it is already present', () => {
2859
+ const currentDashboardWithNull = {
2860
+ filters: [
2861
+ {
2862
+ fields: [{ id: 'field1', name: 'Field 1' }],
2863
+ includes: ['value1'],
2864
+ allow_nulls: true,
2865
+ },
2866
+ ],
2867
+ };
2868
+ const dataModelWithNull = { current_dashboard: currentDashboardWithNull };
2869
+ const result = highchartsRenderer.getDashboardFilters(dataModelWithNull);
2870
+ expect(result[0].values).toEqual(['value1', '[null]']);
2871
+ });
2872
+ });
2873
+
2874
+ describe('function getPresentationTagType', () => {
2875
+ it('should return "date_tags" if local_current_dashboard has date tags', () => {
2876
+ const data_model = {
2877
+ current_dashboard: {
2878
+ date_tags: [{ id: 1, name: 'Date Tag 1' }]
2879
+ }
2880
+ };
2881
+ const result = highchartsRenderer.getPresentationTagType(data_model, data_model.current_dashboard);
2882
+ expect(result).toBe('date_tags');
2883
+ });
2884
+
2885
+ it('should return "plan_tags" if local_current_dashboard has plan tags', () => {
2886
+ const data_model = {
2887
+ current_dashboard: {
2888
+ plan_tags: [{ id: 1, name: 'Plan Tag 1' }]
2889
+ }
2890
+ };
2891
+ const result = highchartsRenderer.getPresentationTagType(data_model, data_model.current_dashboard);
2892
+ expect(result).toBe('plan_tags');
2893
+ });
2894
+
2895
+ it('should return undefined if local_current_dashboard has no tags', () => {
2896
+ const data_model = {
2897
+ current_dashboard: {}
2898
+ };
2899
+ const result = highchartsRenderer.getPresentationTagType(data_model);
2900
+ expect(result).toBeUndefined();
2901
+ });
2902
+
2903
+ it('should return "date_tags" if local_current_dashboard is undefined but data_model has date tags', () => {
2904
+ const data_model = {
2905
+ current_dashboard: {
2906
+ date_tags: [{ id: 1, name: 'Date Tag 1' }]
2907
+ }
2908
+ };
2909
+ const result = highchartsRenderer.getPresentationTagType(data_model);
2910
+ expect(result).toBe('date_tags');
2911
+ });
2912
+
2913
+ it('should return "plan_tags" if local_current_dashboard is undefined but data_model has plan tags', () => {
2914
+ const data_model = {
2915
+ current_dashboard: {
2916
+ plan_tags: [{ id: 1, name: 'Plan Tag 1' }]
2917
+ }
2918
+ };
2919
+ const result = highchartsRenderer.getPresentationTagType(data_model);
2920
+ expect(result).toBe('plan_tags');
2921
+ });
2922
+ });
2923
+
2924
+ describe('function getPresentationDataTag', () => {
2925
+ const data_model = { current_dashboard: { presentation_data_tag_object: { value: 'foo' } } };
2926
+ const dataKeyTag = 'date_tags';
2927
+
2928
+ it('returns presentation_data_tag_object value if local_current_dashboard is undefined', () => {
2929
+ const result = highchartsRenderer.getPresentationDataTag(data_model, undefined, dataKeyTag);
2930
+ expect(result).toBe('foo');
2931
+ });
2932
+
2933
+ it('returns presentation_data_tag_object value if local_current_dashboard has presentation_data_tag_object', () => {
2934
+ const local_current_dashboard = { presentation_data_tag_object: { value: 'bar' } };
2935
+ const result = highchartsRenderer.getPresentationDataTag(data_model, local_current_dashboard, dataKeyTag);
2936
+ expect(result).toBe('bar');
2937
+ });
2938
+
2939
+ it('returns value of highest dataKeyTag value in local_current_dashboard', () => {
2940
+ const local_current_dashboard = {
2941
+ date_tags: [
2942
+ { value: '2022-01-01' },
2943
+ { value: '2021-01-01' },
2944
+ { value: '2023-01-01' },
2945
+ ],
2946
+ };
2947
+ const result = highchartsRenderer.getPresentationDataTag(data_model, local_current_dashboard, dataKeyTag);
2948
+ expect(result).toBe('2023-01-01');
2949
+ });
2950
+
2951
+ it('returns null if local_current_dashboard has no presentation_data_tag_object or dataKeyTag values', () => {
2952
+ const local_current_dashboard = {};
2953
+ const result = highchartsRenderer.getPresentationDataTag(data_model, local_current_dashboard, dataKeyTag);
2954
+ expect(result).toBeNull();
2955
+ });
2956
+
2957
+ it('returns null if local_current_dashboard has empty dataKeyTag array', () => {
2958
+ const local_current_dashboard = { date_tags: [] };
2959
+ const result = highchartsRenderer.getPresentationDataTag(data_model, local_current_dashboard, dataKeyTag);
2960
+ expect(result).toBeNull();
2961
+ });
2962
+ });
2963
+
2964
+ describe('function getDashboardApplyScenarios', () => {
2965
+ let data_model;
2966
+ let graph;
2967
+
2968
+ beforeEach(() => {
2969
+ graph = { vals: [{ field: 'field1' }] };
2970
+ data_model = {
2971
+ current_dashboard: {
2972
+ scenario_models: [
2973
+ {
2974
+ value: 1,
2975
+ scenario_model: { source_fields: ['field1'], scenarios: [{ id: 1 }, { id: 2 }] },
2976
+ },
2977
+ {
2978
+ value: 2,
2979
+ scenario_model: { source_fields: ['field2'], scenarios: [{ id: 3 }, { id: 4 }] },
2980
+ },
2981
+ ],
2982
+ },
2983
+ ebmedded_apply_scenario_ids: [],
2984
+ };
2985
+ });
2986
+
2987
+ it('returns ebmedded_apply_scenario_ids if data_model has it', () => {
2988
+ data_model.ebmedded_apply_scenario_ids = [5, 6];
2989
+ const local_current_dashboard = { foo: 'bar' };
2990
+ const result = highchartsRenderer.getDashboardApplyScenarios(data_model, graph, local_current_dashboard);
2991
+ expect(result).toEqual([5, 6]);
2992
+ });
2993
+
2994
+ it('returns empty array if scenario_models in local_current_dashboard are not provided', () => {
2995
+ const result = highchartsRenderer.getDashboardApplyScenarios(data_model, {vals: [null]}, {});
2996
+ expect(result).toEqual([]);
2997
+ });
2998
+
2999
+ it('returns empty array if graph has no vals', () => {
3000
+ const result = highchartsRenderer.getDashboardApplyScenarios(data_model, {});
3001
+ expect(result).toEqual([]);
3002
+ });
3003
+
3004
+ it('returns empty array if graph has more than one val', () => {
3005
+ const graph = { vals: [{ field: 'field1' }, { field: 'field2' }] };
3006
+ const result = highchartsRenderer.getDashboardApplyScenarios(data_model, graph, {});
3007
+ expect(result).toEqual([]);
3008
+ });
3009
+
3010
+ it('returns array of selected scenario ids', () => {
3011
+ const result = highchartsRenderer.getDashboardApplyScenarios(data_model, graph, data_model.current_dashboard);
3012
+ expect(result).toEqual([1]);
3013
+ });
3014
+
3015
+ it('returns empty array if no matching scenario is found', () => {
3016
+ const graph = { vals: [{ field: 'field3' }] };
3017
+ const result = highchartsRenderer.getDashboardApplyScenarios(data_model, graph, data_model.current_dashboard);
3018
+ expect(result).toEqual([]);
3019
+ });
3020
+ });
3021
+
3022
+ describe('function isDate', () => {
3023
+ it('returns true for valid date string', () => {
3024
+ expect(highchartsRenderer.isDate('2022-01-01')).toBe(true);
3025
+ });
3026
+
3027
+ it('returns false for invalid date string', () => {
3028
+ expect(highchartsRenderer.isDate('not a date')).toBe(false);
3029
+ });
3030
+
3031
+ it('returns false for undefined input', () => {
3032
+ expect(highchartsRenderer.isDate(undefined)).toBe(false);
3033
+ });
3034
+
3035
+ it('returns false for empty string input', () => {
3036
+ expect(highchartsRenderer.isDate('')).toBe(false);
3037
+ });
3038
+ });
3039
+
3040
+ describe('function isDateFormat', () => {
3041
+ it('returns true for valid date string and format', () => {
3042
+ expect(highchartsRenderer.isDateFormat('2022-01-01', 'YYYY-MM-DD')).toBe(true);
3043
+ });
3044
+
3045
+ it('returns false for invalid date string', () => {
3046
+ expect(highchartsRenderer.isDateFormat('not a date', 'YYYY-MM-DD')).toBe(false);
3047
+ });
3048
+
3049
+ it('returns false for null input', () => {
3050
+ expect(highchartsRenderer.isDateFormat(null, 'YYYY-MM-DD')).toBe(false);
3051
+ });
3052
+
3053
+ it('returns false for undefined input', () => {
3054
+ expect(highchartsRenderer.isDateFormat(undefined, 'YYYY-MM-DD')).toBe(false);
3055
+ });
3056
+
3057
+ it('returns false for non-string input', () => {
3058
+ expect(highchartsRenderer.isDateFormat(123, 'YYYY-MM-DD')).toBe(false);
3059
+ });
3060
+
3061
+ it('returns false for empty string input', () => {
3062
+ expect(highchartsRenderer.isDateFormat('', 'YYYY-MM-DD')).toBe(false);
3063
+ });
3064
+
3065
+ it('returns false for invalid format', () => {
3066
+ expect(highchartsRenderer.isDateFormat('2022-01-01', 'invalid format')).toBe(false);
3067
+ });
3068
+ });
3069
+
3070
+ describe('function containsIgnoreCase', () => {
3071
+ it('should return true when str contains it, ignoring case', () => {
3072
+ const str = 'The quick brown fox jumps over the lazy dog';
3073
+ const it = 'brown';
3074
+ expect(highchartsRenderer.containsIgnoreCase(str, it)).toBe(true);
3075
+ });
3076
+
3077
+ it('should return true when str contains it, with different case', () => {
3078
+ const str = 'The quick brown fox jumps over the lazy dog';
3079
+ const it = 'BROWN';
3080
+ expect(highchartsRenderer.containsIgnoreCase(str, it)).toBe(true);
3081
+ });
3082
+
3083
+ it('should return false when str does not contain it, ignoring case', () => {
3084
+ const str = 'The quick brown fox jumps over the lazy dog';
3085
+ const it = 'cat';
3086
+ expect(highchartsRenderer.containsIgnoreCase(str, it)).toBe(false);
3087
+ });
3088
+
3089
+ it('should return false when str is empty', () => {
3090
+ const str = '';
3091
+ const it = 'dog';
3092
+ expect(highchartsRenderer.containsIgnoreCase(str, it)).toBe(false);
3093
+ });
3094
+ });
3095
+
3096
+ describe('function generateTableFormula', () => {
3097
+ it('pivotUtilities.getPivotTableFormula should be called', () => {
3098
+ spyOn($.pivotUtilities, 'getPivotTableFormula').and.callFake(() => null);
3099
+ highchartsRenderer.generateTableFormula(1,2,3,4,5,6, 7);
3100
+ expect($.pivotUtilities.getPivotTableFormula).lastCalledWith(1, 2, 3, 4, 5, 6, 7);
3101
+ });
3102
+ });
3103
+
3104
+ describe('function updateSelectedOverrideValues', () => {
3105
+ const widget = {
3106
+ vals: [{ name: 'selected_name' }]
3107
+ };
3108
+
3109
+ const overrideValues = [{ name: 'override_name' }];
3110
+
3111
+ it('should update selected values in res object', () => {
3112
+ const res = [
3113
+ { override_name: 'value1', selected_name: 'valueA' },
3114
+ { override_name: 'value2', selected_name: 'valueB' }
3115
+ ];
3116
+ const expectedRes = [
3117
+ { override_name: 'value1', selected_name: 'value1' },
3118
+ { override_name: 'value2', selected_name: 'value2' }
3119
+ ];
3120
+ expect(highchartsRenderer.updateSelectedOverrideValues(widget, overrideValues, res)).toEqual(expectedRes);
3121
+ });
3122
+
3123
+ it('should not update res object if override_values array is empty', () => {
3124
+ const res = [
3125
+ { override_name: 'value1', selected_name: 'valueA' },
3126
+ { override_name: 'value2', selected_name: 'valueB' }
3127
+ ];
3128
+ expect(highchartsRenderer.updateSelectedOverrideValues(widget, [], res)).toEqual(res);
3129
+ });
3130
+
3131
+ it('should not update res object if name_to_find is no_name_for_selected', () => {
3132
+ const res = [
3133
+ { override_name: 'value1', selected_name: 'valueA' },
3134
+ { override_name: 'value2', selected_name: 'valueB' }
3135
+ ];
3136
+ const overrideValues = [{ name: 'no_name_for_selected' }];
3137
+ expect(highchartsRenderer.updateSelectedOverrideValues(widget, overrideValues, res)).toEqual(res);
3138
+ });
3139
+
3140
+ it('should not update res object if name_to_set is null', () => {
3141
+ const widget = { vals: [] };
3142
+ const res = [
3143
+ { override_name: 'value1', selected_name: 'valueA' },
3144
+ { override_name: 'value2', selected_name: 'valueB' }
3145
+ ];
3146
+ expect(highchartsRenderer.updateSelectedOverrideValues(widget, overrideValues, res)).toEqual(res);
3147
+ });
3148
+ });
3149
+
3150
+ describe('function convertUniqueDateValues', () => {
3151
+ const widget = {
3152
+ template_id: 'template1',
3153
+ vals: [
3154
+ {field: 'field1', aggregator: 'UNIQUE_VALUES'},
3155
+ {field: 'field2', aggregator: 'COUNT'}
3156
+ ]
3157
+ };
3158
+
3159
+ const templates = [
3160
+ {id: 'template1', fields: [{id: 'field1', name: 'date_field', type: 'Date'}]},
3161
+ {id: 'template2', fields: [{id: 'field3', name: 'string_field', type: 'String'}]}
3162
+ ];
3163
+
3164
+ it('should convert unique date values in res object', () => {
3165
+ const res = [
3166
+ {date_field: [1640995200, 1641081600], string_field: 'value1'},
3167
+ {date_field: [1641168000], string_field: 'value2'}
3168
+ ];
3169
+ const expectedRes = [
3170
+ {date_field: ['01/01/2022', '01/02/2022'], string_field: 'value1'},
3171
+ {date_field: ['01/03/2022'], string_field: 'value2'}
3172
+ ];
3173
+ expect(highchartsRenderer.convertUniqueDateValues(widget, templates, res)).toEqual(expectedRes);
3174
+ });
3175
+
3176
+ it('should not convert date values if fields_to_convert is empty', () => {
3177
+ const widget = {
3178
+ template_id: 'template2',
3179
+ vals: [
3180
+ {field: 'field1', aggregator: 'SUM'},
3181
+ {field: 'field2', aggregator: 'AVG'}
3182
+ ]
3183
+ };
3184
+ const res = [
3185
+ {date_field: ['2022-01-01', '2022-01-02'], string_field: 'value1'},
3186
+ {date_field: ['2022-01-03'], string_field: 'value2'}
3187
+ ];
3188
+ expect(highchartsRenderer.convertUniqueDateValues(widget, templates, res)).toEqual(res);
3189
+ });
3190
+
3191
+ it('should not convert date values if res is empty', () => {
3192
+ const res = [];
3193
+ expect(highchartsRenderer.convertUniqueDateValues(widget, templates, res)).toEqual(res);
3194
+ });
3195
+
3196
+ it('should not convert date values if widget is null', () => {
3197
+ const res = [
3198
+ {date_field: ['2022-01-01', '2022-01-02'], string_field: 'value1'},
3199
+ {date_field: ['2022-01-03'], string_field: 'value2'}
3200
+ ];
3201
+ expect(highchartsRenderer.convertUniqueDateValues(null, templates, res)).toEqual(res);
3202
+ });
3203
+
3204
+ it('should not convert date values if widget.vals is null', () => {
3205
+ const widget = {template_id: 'template1'};
3206
+ const res = [
3207
+ {date_field: ['2022-01-01', '2022-01-02'], string_field: 'value1'},
3208
+ {date_field: ['2022-01-03'], string_field: 'value2'}
3209
+ ];
3210
+ expect(highchartsRenderer.convertUniqueDateValues(widget, templates, res)).toEqual(res);
3211
+ });
3212
+ });
3213
+
3214
+ describe('function setNewFieldNames', () => {
3215
+ beforeEach(() => {
3216
+ highchartsRenderer.useTotalsCalculation = false;
3217
+ });
3218
+
3219
+ it('should return the input if useTotalsCalculation is true', () => {
3220
+ const res = [{ DR_Values: 'value1' }, { DR_Values: 'value2' }];
3221
+ highchartsRenderer.useTotalsCalculation = true;
3222
+ const result = highchartsRenderer.setNewFieldNames(res);
3223
+
3224
+ expect(result).toEqual(res);
3225
+ });
3226
+
3227
+ it('should update DR_Values field names', () => {
3228
+ const res = [{ DR_Values: 'DR_Values' }, { DR_Values: 'value2' }];
3229
+ const expected = [{ DR_Values: 'Values' }, { DR_Values: 'value2' }];
3230
+ const result = highchartsRenderer.setNewFieldNames(res);
3231
+
3232
+ expect(result).toEqual(expected);
3233
+ });
3234
+
3235
+ it('should handle empty input', () => {
3236
+ const res = null;
3237
+ const expected = null;
3238
+ const result = highchartsRenderer.setNewFieldNames(res);
3239
+
3240
+ expect(result).toEqual(expected);
3241
+ });
3242
+
3243
+ it('should handle empty DR_Values array in input', () => {
3244
+ const res = [{}];
3245
+ const expected = [{ DR_Values: undefined }];
3246
+ const result = highchartsRenderer.setNewFieldNames(res);
3247
+
3248
+ expect(result).toEqual(expected);
3249
+ });
3250
+ });
3251
+
3252
+ describe('function getOptionsForLegends', () => {
3253
+ const rowAttrsLength = 1;
3254
+ let additionOptions;
3255
+
3256
+ beforeEach(() => {
3257
+ highchartsRenderer.isMobile = false;
3258
+ additionOptions = {
3259
+ legends_position: {value: null},
3260
+ hideChartHeader: false,
3261
+ subtitle: {subtitle: null}
3262
+ };
3263
+ });
3264
+
3265
+ it('should return topPosition for mobile devices and legends_position is not set to none', () => {
3266
+ highchartsRenderer.isMobile = true;
3267
+ const result = highchartsRenderer.getOptionsForLegends(additionOptions, rowAttrsLength, false, false);
3268
+ expect(result.align).toEqual('left');
3269
+ expect(result.verticalAlign).toEqual('top');
3270
+ expect(result.layout).toEqual('horizontal');
3271
+ });
3272
+
3273
+ it('should return topPosition when legends_position is not set and not line/pie chart', () => {
3274
+ const result = highchartsRenderer.getOptionsForLegends(additionOptions, rowAttrsLength, false, false);
3275
+ expect(result.align).toEqual('left');
3276
+ expect(result.verticalAlign).toEqual('top');
3277
+ expect(result.layout).toEqual('horizontal');
3278
+ });
3279
+
3280
+ it('should return leftPosition when legends_position is not set and line chart', () => {
3281
+ const result = highchartsRenderer.getOptionsForLegends(additionOptions, rowAttrsLength, true, false);
3282
+ expect(result.align).toEqual('left');
3283
+ expect(result.verticalAlign).toEqual('top');
3284
+ expect(result.layout).toEqual('vertical');
3285
+ });
3286
+
3287
+ it('should return rightPosition when legends_position is not set and pie chart', () => {
3288
+ const result = highchartsRenderer.getOptionsForLegends(additionOptions, rowAttrsLength, false, true);
3289
+ expect(result.align).toEqual('right');
3290
+ expect(result.verticalAlign).toEqual('top');
3291
+ expect(result.layout).toEqual('vertical');
3292
+ });
3293
+
3294
+ it('should return topPosition when legends_position is set to top', () => {
3295
+ additionOptions.legends_position.value = 'top';
3296
+ const result = highchartsRenderer.getOptionsForLegends(additionOptions, rowAttrsLength, false, false);
3297
+ expect(result.align).toEqual('left');
3298
+ expect(result.verticalAlign).toEqual('top');
3299
+ expect(result.layout).toEqual('horizontal');
3300
+ });
3301
+
3302
+ it('should return bottomPosition when legends_position is set to bottom', () => {
3303
+ additionOptions.legends_position.value = 'bottom';
3304
+ const result = highchartsRenderer.getOptionsForLegends(additionOptions, rowAttrsLength, false, false);
3305
+ expect(result.maxHeight).toEqual(37);
3306
+ });
3307
+
3308
+ it('should return leftPosition when legends_position is set to left', () => {
3309
+ additionOptions.legends_position.value = 'left';
3310
+ const result = highchartsRenderer.getOptionsForLegends(additionOptions, rowAttrsLength, false, false);
3311
+ expect(result.align).toEqual('left');
3312
+ expect(result.verticalAlign).toEqual('top');
3313
+ expect(result.layout).toEqual('vertical');
3314
+ });
3315
+
3316
+ it('should return rightPosition when legends_position is set to right', () => {
3317
+ additionOptions.legends_position.value = 'right';
3318
+ const result = highchartsRenderer.getOptionsForLegends(additionOptions, rowAttrsLength, false, false);
3319
+ expect(result.align).toEqual('right');
3320
+ expect(result.verticalAlign).toEqual('top');
3321
+ expect(result.layout).toEqual('vertical');
3322
+ });
3323
+
3324
+ it('should return disabled state when legends_position is set to none', () => {
3325
+ additionOptions.legends_position.value = 'none';
3326
+ const result = highchartsRenderer.getOptionsForLegends(additionOptions, rowAttrsLength, false, false);
3327
+ expect(result.enabled).toEqual(false);
3328
+ });
3329
+ });
3330
+
3331
+ describe('function setYAxisMinMax', () => {
3332
+ let yAxis;
3333
+
3334
+ beforeEach(() => {
3335
+ yAxis = { min: null, max: null };
3336
+ });
3337
+
3338
+ it('should set the minimum and maximum values of the yAxis if the axisYOptions is defined and has valid values', () => {
3339
+ const axisYOptions = { min: '10', max: '20' };
3340
+ highchartsRenderer.setYAxisMinMax(yAxis, axisYOptions);
3341
+ expect(yAxis.min).toEqual(10);
3342
+ expect(yAxis.max).toEqual(20);
3343
+ });
3344
+
3345
+ it('should set the minimum value of the yAxis to null if the axisYOptions has an invalid minimum value', () => {
3346
+ const axisYOptions = { min: 'invalid', max: '20' };
3347
+ highchartsRenderer.setYAxisMinMax(yAxis, axisYOptions);
3348
+ expect(yAxis.min).toBeNull();
3349
+ expect(yAxis.max).toEqual(20);
3350
+ });
3351
+
3352
+ it('should set the maximum value of the yAxis to null if the axisYOptions has an invalid maximum value', () => {
3353
+ const axisYOptions = { min: '10', max: 'invalid' };
3354
+ highchartsRenderer.setYAxisMinMax(yAxis, axisYOptions);
3355
+ expect(yAxis.min).toEqual(10);
3356
+ expect(yAxis.max).toBeNull();
3357
+ });
3358
+
3359
+ it('should set the minimum and maximum values of the yAxis to null if the axisYOptions is not defined', () => {
3360
+ highchartsRenderer.setYAxisMinMax(yAxis);
3361
+ expect(yAxis.min).toBeNull();
3362
+ expect(yAxis.max).toBeNull();
3363
+ });
3364
+ });
3365
+
3366
+ describe('function getDateFieldFormat', () => {
3367
+ let widget;
3368
+ let dateField;
3369
+
3370
+ beforeEach(() => {
3371
+ widget = {
3372
+ options: {
3373
+ date_aggregation_configs: [
3374
+ {
3375
+ field_id: 1,
3376
+ aggregate_by: 'quarter',
3377
+ is_formatting_by_aggregation_method: true,
3378
+ }
3379
+ ],
3380
+ },
3381
+ };
3382
+
3383
+ dateField = {
3384
+ id: 1,
3385
+ format: '%Y-%m-%d',
3386
+ };
3387
+ });
3388
+
3389
+ it('returns format as is when there is no aggregation config', () => {
3390
+ widget.options.date_aggregation_configs = [];
3391
+ const result = highchartsRenderer.getDateFieldFormat(widget, dateField);
3392
+ expect(result).toEqual('%Y-%m-%d');
3393
+ });
3394
+
3395
+ it('returns format by time frame when there is an aggregation config', () => {
3396
+ const result = highchartsRenderer.getDateFieldFormat(widget, dateField);
3397
+ expect(result).toEqual('[Q]Q-YY');
3398
+ });
3399
+
3400
+ it('returns format as is when there is an aggregation config but no time frame specified', () => {
3401
+ widget.options.date_aggregation_configs[0].aggregate_by = null;
3402
+ const result = highchartsRenderer.getDateFieldFormat(widget, dateField);
3403
+ expect(result).toEqual('%Y-%m-%d');
3404
+ });
3405
+ });
3406
+
3407
+ describe('function getDateFormatByTimeframe', () => {
3408
+ it('should return the correct date format for "month" timeframe', () => {
3409
+ const result = highchartsRenderer.getDateFormatByTimeframe('month', 'YYYY-MM-DD');
3410
+ expect(result).toBe('MMM-YY');
3411
+ });
3412
+
3413
+ it('should return the correct date format for "year" timeframe', () => {
3414
+ const result = highchartsRenderer.getDateFormatByTimeframe('year', 'YYYY-MM-DD');
3415
+ expect(result).toBe('YYYY');
3416
+ });
3417
+
3418
+ it('should return the correct date format for "quarter" timeframe', () => {
3419
+ const result = highchartsRenderer.getDateFormatByTimeframe('quarter', 'YYYY-MM-DD');
3420
+ expect(result).toBe('[Q]Q-YY');
3421
+ });
3422
+
3423
+ it('should return the default date format for unrecognized timeframe', () => {
3424
+ expect(highchartsRenderer.getDateFormatByTimeframe('day', 'YYYY-MM-DD')).toBe('YYYY-MM-DD');
3425
+ expect(highchartsRenderer.getDateFormatByTimeframe('week', 'YYYY-MM-DD')).toBe('YYYY-MM-DD');
3426
+ });
3427
+ });
3428
+
3429
+ describe('function getOthersName', () => {
3430
+ it('returns the filtered out field name when it exists in options', () => {
3431
+ const options = {
3432
+ total_value_options: {
3433
+ filter_options: {
3434
+ filteredOutFieldName: 'Excluded'
3435
+ }
3436
+ }
3437
+ };
3438
+ const othersName = highchartsRenderer.getOthersName(options);
3439
+ expect(othersName).toBe('Excluded');
3440
+ });
3441
+
3442
+ it('returns "Others" when the filtered out field name does not exist in options', () => {
3443
+ const options = {};
3444
+ const othersName = highchartsRenderer.getOthersName(options);
3445
+ expect(othersName).toBe('Others');
3446
+ });
3447
+ });
3448
+
3449
+ describe('function transformRowsAndColsForBreakdown', () => {
3450
+ let point;
3451
+ let opts;
3452
+
3453
+ beforeEach(() => {
3454
+ point = {
3455
+ options: {},
3456
+ colKeys: ["Col1", "Col2", "Others"],
3457
+ };
3458
+
3459
+ opts = {
3460
+ total_value_options: {
3461
+ filter_options: {
3462
+ filteredOutFieldName: "Others",
3463
+ },
3464
+ },
3465
+ };
3466
+ });
3467
+
3468
+ it("should replace Others with DR_Others in cols and return rows as cols when point is not total", () => {
3469
+ const rows = ["Row1", "Row2"];
3470
+ const cols = ["Col1", "Col2", "Others"];
3471
+ const expectedResult = {
3472
+ rows: cols,
3473
+ cols: [point.colKeys[0]],
3474
+ };
3475
+
3476
+ const result = highchartsRenderer.transformRowsAndColsForBreakdown(rows, cols, point, opts);
3477
+ expect(result).toEqual(expectedResult);
3478
+ });
3479
+
3480
+ it("should set rows to empty array when point is total", () => {
3481
+ const rows = ["Row1", "Row2"];
3482
+ const cols = ["Col1", "Col2", "Not_Others"];
3483
+ point.options.isTotal = true;
3484
+ const expectedResult = {
3485
+ rows: [],
3486
+ cols: cols,
3487
+ };
3488
+
3489
+ const result = highchartsRenderer.transformRowsAndColsForBreakdown(rows, cols, point, opts);
3490
+ expect(result).toEqual(expectedResult);
3491
+ });
3492
+ });
3493
+
3494
+ describe('function getBreakdownXAxisLabelFormatter', () => {
3495
+ it('returns correct formatter function', () => {
3496
+ const chartSeries = [{
3497
+ data: [
3498
+ { name: 'Label1', isTotal: true },
3499
+ { name: 'Label2', isTotal: false }
3500
+ ]
3501
+ }];
3502
+ const formatter = highchartsRenderer.getBreakdownXAxisLabelFormatter(chartSeries);
3503
+
3504
+ const totalResult = formatter.apply({ value: 'Label1' });
3505
+ expect(totalResult).toEqual('<span style=\"\">Label1</span>');
3506
+
3507
+ const normalResult = formatter.apply({ value: 'Label2' });
3508
+ expect(normalResult).toEqual('<span style="font-weight: normal; color: #51566f;">Label2</span>');
3509
+ });
3510
+ });
3511
+
3512
+ describe('function getTrendSeriesName', () => {
3513
+ it('returns expected name when name is present in the series object', () => {
3514
+ const series = {
3515
+ name: 'Sales'
3516
+ };
3517
+ const expectedName = 'Trend Line (Sales)';
3518
+ expect(highchartsRenderer.getTrendSeriesName(series)).toBe(expectedName);
3519
+ });
3520
+
3521
+ it('returns expected name when no name is present in the series object', () => {
3522
+ const series = {};
3523
+ const expectedName = 'Trend Line';
3524
+ expect(highchartsRenderer.getTrendSeriesName(series)).toBe(expectedName);
3525
+ });
3526
+ });
2329
3527
  });