@ons/design-system 72.10.8 → 72.10.10

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.
Files changed (66) hide show
  1. package/README.md +9 -5
  2. package/components/accordion/accordion.js +3 -2
  3. package/components/announcement-banner/_announcement-banner.scss +24 -0
  4. package/components/announcement-banner/_macro.njk +33 -0
  5. package/components/announcement-banner/_macro.spec.js +106 -0
  6. package/components/announcement-banner/_test_examples.js +22 -0
  7. package/components/announcement-banner/example-banner-black.njk +12 -0
  8. package/components/announcement-banner/example-banner-red.njk +13 -0
  9. package/components/announcement-banner/example-banner-teal.njk +13 -0
  10. package/components/autosuggest/autosuggest.spec.js +2 -0
  11. package/components/autosuggest/autosuggest.ui.js +12 -7
  12. package/components/breadcrumbs/_breadcrumbs.scss +53 -0
  13. package/components/breadcrumbs/_macro.njk +33 -24
  14. package/components/breadcrumbs/_macro.spec.js +25 -0
  15. package/components/button/_button.scss +29 -1
  16. package/components/chart/_chart.scss +88 -0
  17. package/components/chart/_macro.njk +25 -6
  18. package/components/chart/_macro.spec.js +1178 -640
  19. package/components/chart/bar-chart.js +8 -1
  20. package/components/chart/chart-iframe-resize.js +2 -2
  21. package/components/chart/common-chart-options.js +9 -0
  22. package/components/chart/example-bar-chart-with-axis-min-and-max-values.njk +0 -1
  23. package/components/chart/example-bar-chart-with-point-range-and-reference-line-annotations.njk +4 -4
  24. package/components/chart/example-bar-chart.njk +0 -1
  25. package/components/chart/example-iframe-chart.njk +1 -1
  26. package/components/chart/range-annotations-options.js +1 -1
  27. package/components/download-resources/download-resources.spec.js +2 -0
  28. package/components/duration/example-duration-error-for-single-field.njk +0 -1
  29. package/components/duration/example-duration-error.njk +0 -1
  30. package/components/footer/_macro.spec.js +2 -2
  31. package/components/header/_macro.njk +5 -16
  32. package/components/header/example-header-button-and-navigation.njk +133 -0
  33. package/components/header/example-header-external-with-navigation-and-search.njk +1 -1
  34. package/components/hero/_hero.scss +17 -22
  35. package/components/hero/_macro.njk +1 -1
  36. package/components/hero/_macro.spec.js +1 -1
  37. package/components/hero/example-hero-dark-with-external-breadcrumbs.njk +194 -0
  38. package/components/hero/example-hero-default-with-external-breadcrumbs.njk +201 -0
  39. package/components/hero/example-hero-grey-with-external-breadcrumbs.njk +243 -0
  40. package/components/hero/example-hero-navy-blue-with-external-breadcrumbs.njk +200 -0
  41. package/components/hero/example-hero-pale-blue-with-external-breadcrumbs.njk +201 -0
  42. package/components/icon/_macro.njk +1 -1
  43. package/components/mutually-exclusive/mutually-exclusive.js +3 -1
  44. package/components/navigation/_macro.njk +11 -16
  45. package/components/navigation/_navigation.scss +24 -0
  46. package/components/radios/clear-radios.js +4 -2
  47. package/components/relationships/relationships.js +4 -2
  48. package/components/table/_macro.njk +107 -112
  49. package/components/table/_macro.spec.js +35 -44
  50. package/components/table/_table.scss +0 -12
  51. package/components/table/example-table-sortable.njk +1 -1
  52. package/components/tabs/example-tabs-details.njk +1 -1
  53. package/components/textarea/_macro.njk +1 -0
  54. package/components/textarea/_macro.spec.js +1 -0
  55. package/components/timeout-panel/timeout-panel.spec.js +1 -1
  56. package/components/video/video.js +2 -0
  57. package/css/main.css +1 -1
  58. package/js/timeout.js +9 -6
  59. package/layout/_template.njk +13 -0
  60. package/package.json +6 -6
  61. package/scripts/main.es5.js +4 -2
  62. package/scripts/main.js +4 -2
  63. package/scss/main.scss +1 -0
  64. package/scss/vars/_colors.scss +3 -0
  65. package/scss/vars/_forms.scss +11 -0
  66. package/components/table/example-table-scrollable.njk +0 -158
@@ -63,10 +63,40 @@ describe('Macro: Chart', () => {
63
63
  expect($('figcaption').length).toBe(0);
64
64
  expect($('.ons-chart__download-title').length).toBe(0);
65
65
  });
66
+
67
+ test('THEN: it renders the chart container with the correct aria attributes', () => {
68
+ expect($('.ons-chart__container').attr('aria-label')).toBe('chart container');
69
+ });
70
+ });
71
+ });
72
+
73
+ describe('GIVEN: Params: instructions', () => {
74
+ describe('WHEN: instructions is provided', () => {
75
+ const $ = cheerio.load(
76
+ renderComponent('chart', {
77
+ ...EXAMPLE_LINE_CHART_REQUIRED_PARAMS,
78
+ instructions: 'Some custom instructions for the chart.',
79
+ }),
80
+ );
81
+
82
+ test('THEN: it renders the chart with the correct instructions text', () => {
83
+ const expectedText = 'Some custom instructions for the chart.';
84
+ expect($('#chart-instructions-chart-123').text().trim()).toBe(expectedText);
85
+ });
86
+ });
87
+
88
+ describe('WHEN: instructions is not provided', () => {
89
+ const $ = cheerio.load(renderComponent('chart', EXAMPLE_LINE_CHART_REQUIRED_PARAMS));
90
+
91
+ test('THEN: it renders the chart with the default instructions text', () => {
92
+ const expectedText =
93
+ 'Use the Tab key to move focus into the chart. Once inside, use the arrow keys to navigate between data points. As you move, tooltips will be announced to describe each point. Touch device users, explore by touch or with swipe gestures.';
94
+ expect($('#chart-instructions-chart-123').text().trim()).toBe(expectedText);
95
+ });
66
96
  });
67
97
  });
68
98
 
69
- describe('GIVEN: Params: Theme', () => {
99
+ describe('GIVEN: Params: theme', () => {
70
100
  describe('WHEN: theme is provided', () => {
71
101
  const $ = cheerio.load(
72
102
  renderComponent('chart', {
@@ -81,7 +111,7 @@ describe('Macro: Chart', () => {
81
111
  });
82
112
  });
83
113
 
84
- describe('GIVEN: Params: Heading Level', () => {
114
+ describe('GIVEN: Params: headingLevel', () => {
85
115
  describe('WHEN: heading level is provided', () => {
86
116
  const $ = cheerio.load(
87
117
  renderComponent('chart', {
@@ -111,7 +141,7 @@ describe('Macro: Chart', () => {
111
141
  });
112
142
  });
113
143
 
114
- describe('GIVEN: Params: Tick Interval', () => {
144
+ describe('GIVEN: Params: tickInterval', () => {
115
145
  describe('WHEN: tick interval is provided', () => {
116
146
  const $ = cheerio.load(
117
147
  renderComponent('chart', {
@@ -143,39 +173,146 @@ describe('Macro: Chart', () => {
143
173
  });
144
174
  });
145
175
 
146
- describe('GIVEN: Params: Config', () => {
147
- describe('WHEN: config params are provided', () => {
176
+ describe('GIVEN: Params: xAxis', () => {
177
+ describe('WHEN: xAxis options are provided', () => {
148
178
  const $ = cheerio.load(renderComponent('chart', EXAMPLE_LINE_CHART_WITH_CONFIG_PARAMS));
149
179
  const configScript = $(`script[data-highcharts-config--chart-456]`).html();
150
180
 
151
- test('THEN: it renders the legend when enabled', () => {
152
- expect(configScript).toContain('"enabled":true');
153
- });
154
-
155
- test('THEN: it includes correct xAxis properties', () => {
181
+ test('THEN: it renders the xAxis correctly', () => {
156
182
  expect(configScript).toContain('"text":"X Axis Label"');
157
183
  expect(configScript).toContain('"categories":["A","B","C"]');
158
- expect(configScript).toContain('"type":"linear"');
159
184
  });
185
+ });
186
+
187
+ describe('WHEN: xAxis min and max are provided', () => {
188
+ test('THEN: xAxis min and max are ignored', () => {
189
+ const params = {
190
+ id: 'test-chart',
191
+ title: 'Test Chart',
192
+ chartType: 'line',
193
+ xAxis: {
194
+ title: 'X Axis Title',
195
+ categories: ['A', 'B', 'C'],
196
+ type: 'linear',
197
+ labelFormat: '{value}',
198
+ min: 1,
199
+ max: 10,
200
+ startOnTick: true,
201
+ endOnTick: true,
202
+ },
203
+ yAxis: {
204
+ title: 'Y Axis Title',
205
+ labelFormat: '{value}',
206
+ },
207
+ series: [],
208
+ };
209
+
210
+ const $ = cheerio.load(renderComponent('chart', params));
211
+ const configScript = $(`script[data-highcharts-config--${params.id}]`).html();
212
+
213
+ expect(configScript).not.toContain('"min":1');
214
+ expect(configScript).not.toContain('"max":10');
215
+ expect(configScript).not.toContain('"startOnTick":true');
216
+ expect(configScript).not.toContain('"endOnTick":true');
217
+ });
218
+ });
219
+ });
220
+
221
+ describe('GIVEN: Params: yAxis', () => {
222
+ describe('WHEN: yAxis options are provided', () => {
223
+ const $ = cheerio.load(renderComponent('chart', EXAMPLE_LINE_CHART_WITH_CONFIG_PARAMS));
224
+ const configScript = $(`script[data-highcharts-config--chart-456]`).html();
160
225
 
161
- test('THEN: it includes correct yAxis properties', () => {
226
+ test('THEN: it renders the yAxis correctly', () => {
162
227
  expect(configScript).toContain('"text":"Y Axis Label"');
163
228
  expect(configScript).toContain('"labels":{"format":"{value:,.f}"}');
164
229
  });
230
+ });
231
+
232
+ describe('WHEN: yAxis min and max are provided', () => {
233
+ test('THEN: yAxis min and max are included in config', () => {
234
+ const params = {
235
+ id: 'test-chart',
236
+ title: 'Test Chart',
237
+ xAxis: {
238
+ title: 'X Axis Title',
239
+ categories: ['A', 'B', 'C'],
240
+ type: 'linear',
241
+ labelFormat: '{value}',
242
+ },
243
+ chartType: 'line',
244
+ yAxis: {
245
+ title: 'Y Axis Title',
246
+ labelFormat: '{value}',
247
+ min: 0,
248
+ max: 100,
249
+ startOnTick: false,
250
+ endOnTick: true,
251
+ },
252
+ series: [],
253
+ };
254
+
255
+ const $ = cheerio.load(renderComponent('chart', params));
256
+ const configScript = $(`script[data-highcharts-config--${params.id}]`).html();
257
+
258
+ expect(configScript).toContain('"min":0');
259
+ expect(configScript).toContain('"max":100');
260
+ expect(configScript).toContain('"startOnTick":false');
261
+ expect(configScript).toContain('"endOnTick":true');
262
+ });
263
+ });
264
+
265
+ describe('WHEN: yAxis min and max are not provided', () => {
266
+ test('THEN: yAxis min and max are not included in config', () => {
267
+ const params = {
268
+ id: 'test-chart',
269
+ title: 'Test Chart',
270
+ xAxis: {
271
+ title: 'X Axis Title',
272
+ categories: ['A', 'B', 'C'],
273
+ type: 'linear',
274
+ labelFormat: '{value}',
275
+ },
276
+ chartType: 'line',
277
+ yAxis: {
278
+ title: 'Y Axis Title',
279
+ labelFormat: '{value}',
280
+ min: undefined,
281
+ max: undefined,
282
+ startOnTick: undefined,
283
+ endOnTick: undefined,
284
+ },
285
+ series: [],
286
+ };
287
+
288
+ const $ = cheerio.load(renderComponent('chart', params));
289
+ const configScript = $(`script[data-highcharts-config--${params.id}]`).html();
290
+
291
+ const config = JSON.parse(configScript);
292
+
293
+ expect(config.yAxis.min).toBeUndefined();
294
+ expect(config.yAxis.max).toBeUndefined();
295
+ expect(config.yAxis.startOnTick).toBeUndefined();
296
+ expect(config.yAxis.endOnTick).toBeUndefined();
297
+ });
298
+ });
299
+ });
300
+
301
+ describe('GIVEN: Params: series', () => {
302
+ describe('WHEN: series data is provided', () => {
303
+ const $ = cheerio.load(renderComponent('chart', EXAMPLE_LINE_CHART_WITH_CONFIG_PARAMS));
304
+ const configScript = $(`script[data-highcharts-config--chart-456]`).html();
165
305
 
166
- test('THEN: it includes correct series data', () => {
306
+ test('THEN: it renders the series correctly', () => {
167
307
  expect(configScript).toContain('"name":"Category 1"');
168
308
  expect(configScript).toContain('"data":[5,15,25]');
169
309
  expect(configScript).toContain('"name":"Category 2"');
170
310
  expect(configScript).toContain('"data":[10,20,30]');
171
- expect(configScript).toContain('"connectNulls":true');
172
- expect(configScript).toContain('"marker":{"enabled":true}');
173
- expect(configScript).toContain('"dataLabels":{"enabled":true}');
174
311
  });
175
312
  });
176
313
  });
177
314
 
178
- describe('GIVEN: Params: Percentage Height Desktop', () => {
315
+ describe('GIVEN: Params: percentageHeightDesktop', () => {
179
316
  describe('WHEN: percentage height desktop is provided', () => {
180
317
  const $ = cheerio.load(renderComponent('chart', EXAMPLE_LINE_CHART_WITH_CONFIG_PARAMS));
181
318
  test('THEN: it includes correct percentage height desktop', () => {
@@ -184,7 +321,7 @@ describe('Macro: Chart', () => {
184
321
  });
185
322
  });
186
323
 
187
- describe('GIVEN: Params: Percentage Height Mobile', () => {
324
+ describe('GIVEN: Params: percentageHeightMobile', () => {
188
325
  describe('WHEN: percentage height mobile is provided', () => {
189
326
  const $ = cheerio.load(renderComponent('chart', EXAMPLE_LINE_CHART_WITH_CONFIG_PARAMS));
190
327
  test('THEN: it includes correct percentage height mobile', () => {
@@ -222,9 +359,7 @@ describe('Macro: Chart', () => {
222
359
  expect(noScriptFallbackImage).toContain('alt="A description of the fallback image for screen readers"');
223
360
  });
224
361
  });
225
- });
226
362
 
227
- describe('GIVEN: Params: no fallbackImageAlt', () => {
228
363
  describe('WHEN: fallbackImageAlt is not provided', () => {
229
364
  const $ = cheerio.load(
230
365
  renderComponent('chart', {
@@ -239,7 +374,7 @@ describe('Macro: Chart', () => {
239
374
  });
240
375
  });
241
376
 
242
- describe('GIVEN: Params: Caption', () => {
377
+ describe('GIVEN: Params: caption', () => {
243
378
  describe('WHEN: caption is provided', () => {
244
379
  const $ = cheerio.load(
245
380
  renderComponent('chart', {
@@ -278,7 +413,7 @@ describe('Macro: Chart', () => {
278
413
  });
279
414
  });
280
415
 
281
- describe('GIVEN: Params: Description', () => {
416
+ describe('GIVEN: Params: description', () => {
282
417
  describe('WHEN: description is provided', () => {
283
418
  const $ = cheerio.load(
284
419
  renderComponent('chart', {
@@ -288,13 +423,13 @@ describe('Macro: Chart', () => {
288
423
  );
289
424
 
290
425
  test('THEN: it renders the description for accessibility', () => {
291
- expect($('.ons-u-vh').text()).toBe('An accessible description for screen readers.');
426
+ expect($('#chart-audio-description-chart-123').text()).toBe('An accessible description for screen readers.');
292
427
  });
293
428
  });
294
429
  });
295
430
 
296
- describe('GIVEN: Params: Download', () => {
297
- describe('WHEN: download object are provided', () => {
431
+ describe('GIVEN: Params: download', () => {
432
+ describe('WHEN: download object is provided', () => {
298
433
  const $ = cheerio.load(
299
434
  renderComponent('chart', {
300
435
  ...EXAMPLE_LINE_CHART_REQUIRED_PARAMS,
@@ -320,7 +455,7 @@ describe('Macro: Chart', () => {
320
455
  });
321
456
  });
322
457
 
323
- describe('GIVEN: Params: Legend', () => {
458
+ describe('GIVEN: Params: legend', () => {
324
459
  describe('WHEN: legend parameter is provided and set to true', () => {
325
460
  const $ = cheerio.load(
326
461
  renderComponent('chart', {
@@ -362,12 +497,145 @@ describe('Macro: Chart', () => {
362
497
  legend: 'false',
363
498
  }),
364
499
  );
365
- test('THEN: it renders the legend', () => {
500
+ test('THEN: it renders the legend default value', () => {
366
501
  const configScript = $(`script[data-highcharts-config--line-chart-legend-tests-123]`).html();
367
502
  expect(configScript).toContain('"legend":{"enabled":true}');
368
503
  });
369
504
  });
370
505
  });
506
+
507
+ describe('GIVEN: Params: rangeAnnotations', () => {
508
+ describe('WHEN: range annotations params are provided on the yAxis with label width', () => {
509
+ const $ = cheerio.load(
510
+ renderComponent('chart', EXAMPLE_LINE_CHART_WITH_RANGE_ANNOTATION_ON_Y_AXIS_WITH_LABEL_WIDTH_PARAMS),
511
+ );
512
+
513
+ test('THEN: it passes jest-axe checks', async () => {
514
+ const results = await axe($.html());
515
+ expect(results).toHaveNoViolations();
516
+ });
517
+
518
+ test('THEN: it includes the range annotations JSON config', () => {
519
+ const configScript = $(`script[data-highcharts-range-annotations--line-chart-range-annotations-y-axis-123]`).html();
520
+ expect(configScript).toContain('"text":"A test y axis range annotation with a label width of 250px"');
521
+ expect(configScript).toContain('"axis":"y"');
522
+ expect(configScript).toContain('"labelWidth":250');
523
+ });
524
+ });
525
+
526
+ describe('WHEN: range annotations params are provided on the xAxis', () => {
527
+ const $ = cheerio.load(renderComponent('chart', EXAMPLE_LINE_CHART_WITH_RANGE_ANNOTATION_ON_X_AXIS_PARAMS));
528
+
529
+ test('THEN: it passes jest-axe checks', async () => {
530
+ const results = await axe($.html());
531
+ expect(results).toHaveNoViolations();
532
+ });
533
+
534
+ test('THEN: it includes the range annotations JSON config', () => {
535
+ const configScript = $(`script[data-highcharts-range-annotations--line-chart-range-annotations-x-axis-123]`).html();
536
+ expect(configScript).toContain('"text":"A test x axis range annotation"');
537
+ expect(configScript).toContain('"range":{"axisValue1":10,"axisValue2":15}');
538
+ expect(configScript).toContain('"axis":"x"');
539
+ expect(configScript).toContain('"labelOffsetX":150');
540
+ expect(configScript).toContain('"labelOffsetY":0');
541
+ });
542
+ });
543
+
544
+ describe('WHEN: range annotations params are provided with label inside', () => {
545
+ const $ = cheerio.load(renderComponent('chart', EXAMPLE_LINE_CHART_WITH_RANGE_ANNOTATION_WITH_LABEL_INSIDE_PARAMS));
546
+
547
+ test('THEN: it passes jest-axe checks', async () => {
548
+ const results = await axe($.html());
549
+ expect(results).toHaveNoViolations();
550
+ });
551
+
552
+ test('THEN: it includes the range annotations JSON config', () => {
553
+ const configScript = $(
554
+ `script[data-highcharts-range-annotations--line-chart-range-annotations-label-inside-123]`,
555
+ ).html();
556
+ expect(configScript).toContain('"text":"A test y axis range annotation with the label inside"');
557
+ expect(configScript).toContain('"axis":"y"');
558
+ expect(configScript).toContain('"labelInside":true');
559
+ });
560
+ });
561
+ });
562
+
563
+ describe('GIVEN: Params: referenceLineAnnotations', () => {
564
+ describe('WHEN: reference line annotations params are provided', () => {
565
+ const $ = cheerio.load(renderComponent('chart', EXAMPLE_LINE_CHART_WITH_REFERENCE_LINE_ANNOTATIONS_PARAMS));
566
+
567
+ test('THEN: it passes jest-axe checks', async () => {
568
+ const results = await axe($.html());
569
+ expect(results).toHaveNoViolations();
570
+ });
571
+
572
+ test('THEN: it includes the reference line annotations JSON config', () => {
573
+ const configScript = $(
574
+ `script[data-highcharts-reference-line-annotations--line-chart-reference-line-annotations-123]`,
575
+ ).html();
576
+ expect(configScript).toContain('"text":"A test x axis reference line annotation"');
577
+ expect(configScript).toContain('"value":34');
578
+ expect(configScript).toContain('"axis":"x"');
579
+ expect(configScript).toContain('"text":"A test y axis reference line annotation"');
580
+ expect(configScript).toContain('"value":12');
581
+ expect(configScript).toContain('"axis":"y"');
582
+ expect(configScript).toContain('"labelWidth":100');
583
+ });
584
+ });
585
+ });
586
+
587
+ describe('GIVEN: Params: annotations', () => {
588
+ describe('WHEN: annotations params are provided', () => {
589
+ const $ = cheerio.load(renderComponent('chart', EXAMPLE_LINE_CHART_WITH_ANNOTATIONS_PARAMS));
590
+
591
+ test('THEN: it passes jest-axe checks', async () => {
592
+ const results = await axe($.html());
593
+ expect(results).toHaveNoViolations();
594
+ });
595
+
596
+ test('THEN: it renders the footnotes', () => {
597
+ expect($('.ons-chart__annotations-footnotes').text()).toContain('1');
598
+ expect($('.ons-chart__annotations-footnotes').text()).toContain('A test annotation');
599
+ expect($('.ons-chart__annotations-footnotes').text()).toContain('2');
600
+ expect($('.ons-chart__annotations-footnotes').text()).toContain('Another test annotation');
601
+ });
602
+
603
+ test('THEN: the footnotes are hidden from screen readers', () => {
604
+ expect($('.ons-chart__annotations-footnotes').attr('aria-hidden')).toBe('true');
605
+ });
606
+
607
+ test('THEN: it includes the annotations JSON config', () => {
608
+ const configScript = $(`script[data-highcharts-annotations--line-chart-annotations-123]`).html();
609
+ expect(configScript).toContain('"text":"A test annotation"');
610
+ expect(configScript).toContain('"point":{"x":10,"y":1.3}');
611
+ expect(configScript).toContain('"labelOffsetX":10,"labelOffsetY":-50');
612
+ });
613
+ });
614
+ });
615
+
616
+ describe('GIVEN: Params: mixedAnnotations', () => {
617
+ describe('WHEN: mixed annotations params are provided', () => {
618
+ const $ = cheerio.load(renderComponent('chart', EXAMPLE_LINE_CHART_WITH_MIXED_ANNOTATION_TYPES_PARAMS));
619
+
620
+ test('THEN: it passes jest-axe checks', async () => {
621
+ const results = await axe($.html());
622
+ expect(results).toHaveNoViolations();
623
+ });
624
+
625
+ test('THEN: it renders the footnotes sequentially', () => {
626
+ expect($('.ons-chart__annotations-footnotes').text()).toContain('1');
627
+ expect($('.ons-chart__annotations-footnotes').text()).toContain('A test point annotation');
628
+ expect($('.ons-chart__annotations-footnotes').text()).toContain('2');
629
+ expect($('.ons-chart__annotations-footnotes').text()).toContain('A test x axis range annotation');
630
+ expect($('.ons-chart__annotations-footnotes').text()).toContain('3');
631
+ expect($('.ons-chart__annotations-footnotes').text()).toContain('A test y axis range annotation with the label inside');
632
+ expect($('.ons-chart__annotations-footnotes').text()).toContain('4');
633
+ expect($('.ons-chart__annotations-footnotes').text()).toContain('A test x axis reference line annotation');
634
+ expect($('.ons-chart__annotations-footnotes').text()).toContain('5');
635
+ expect($('.ons-chart__annotations-footnotes').text()).toContain('A test y axis reference line annotation');
636
+ });
637
+ });
638
+ });
371
639
  });
372
640
 
373
641
  describe('FOR: Bar Chart', () => {
@@ -400,29 +668,159 @@ describe('Macro: Chart', () => {
400
668
  });
401
669
  });
402
670
 
403
- describe('GIVEN: Params: Config', () => {
404
- describe('WHEN: config params are provided', () => {
405
- const $ = cheerio.load(
406
- renderComponent('chart', {
407
- ...EXAMPLE_BAR_CHART_PARAMS,
408
- legend: true,
409
- }),
410
- );
671
+ describe('GIVEN: Params: legend', () => {
672
+ describe('WHEN: legend is true', () => {
673
+ const $ = cheerio.load(renderComponent('chart', { ...EXAMPLE_BAR_CHART_PARAMS, legend: true }));
674
+
675
+ test('THEN: it renders the legend', () => {
676
+ const configScript = $(`script[data-highcharts-config--bar-chart-123]`).html();
677
+ expect(configScript).toContain('"legend":{"enabled":true}');
678
+ });
679
+ });
411
680
 
412
- test('THEN: it renders the legend when enabled', () => {
681
+ describe('WHEN: legend is false', () => {
682
+ const $ = cheerio.load(renderComponent('chart', { ...EXAMPLE_BAR_CHART_PARAMS, legend: false }));
683
+
684
+ test('THEN: it disables the legend', () => {
413
685
  const configScript = $(`script[data-highcharts-config--bar-chart-123]`).html();
414
- expect(configScript).toContain('"enabled":true');
686
+ expect(configScript).toContain('"legend":{"enabled":false}');
415
687
  });
688
+ });
689
+
690
+ describe('WHEN: legend is not provided', () => {
691
+ const $ = cheerio.load(renderComponent('chart', EXAMPLE_BAR_CHART_PARAMS));
416
692
 
417
- test('THEN: it includes correct xAxis and yAxis titles', () => {
693
+ test('THEN: it defaults to enabled', () => {
418
694
  const configScript = $(`script[data-highcharts-config--bar-chart-123]`).html();
695
+ expect(configScript).toContain('"legend":{"enabled":true}');
696
+ });
697
+ });
698
+ });
699
+
700
+ describe('GIVEN: Params: xAxis', () => {
701
+ describe('WHEN: xAxis options are provided', () => {
702
+ const $ = cheerio.load(renderComponent('chart', EXAMPLE_BAR_CHART_PARAMS));
703
+ const configScript = $(`script[data-highcharts-config--bar-chart-123]`).html();
704
+
705
+ test('THEN: it renders the xAxis correctly', () => {
419
706
  expect(configScript).toContain('"text":"X Axis Title"');
707
+ });
708
+ });
709
+
710
+ describe('WHEN: xAxis min and max are provided', () => {
711
+ test('THEN: xAxis min and max are ignored', () => {
712
+ const params = {
713
+ id: 'test-chart',
714
+ title: 'Test Chart',
715
+ chartType: 'bar',
716
+ xAxis: {
717
+ title: 'X Axis Title',
718
+ categories: ['A', 'B', 'C'],
719
+ type: 'linear',
720
+ labelFormat: '{value}',
721
+ min: 1,
722
+ max: 10,
723
+ startOnTick: true,
724
+ endOnTick: true,
725
+ },
726
+ yAxis: {
727
+ title: 'Y Axis Title',
728
+ labelFormat: '{value}',
729
+ },
730
+ series: [],
731
+ };
732
+
733
+ const $ = cheerio.load(renderComponent('chart', params));
734
+ const configScript = $(`script[data-highcharts-config--${params.id}]`).html();
735
+
736
+ expect(configScript).not.toContain('"min":1');
737
+ expect(configScript).not.toContain('"max":10');
738
+ expect(configScript).not.toContain('"startOnTick":true');
739
+ expect(configScript).not.toContain('"endOnTick":true');
740
+ });
741
+ });
742
+ });
743
+
744
+ describe('GIVEN: Params: yAxis', () => {
745
+ describe('WHEN: yAxis options are provided', () => {
746
+ const $ = cheerio.load(renderComponent('chart', EXAMPLE_BAR_CHART_PARAMS));
747
+ const configScript = $(`script[data-highcharts-config--bar-chart-123]`).html();
748
+
749
+ test('THEN: it renders the yAxis correctly', () => {
420
750
  expect(configScript).toContain('"text":"Y Axis Title"');
421
751
  });
422
752
  });
753
+
754
+ describe('WHEN: yAxis min and max are provided', () => {
755
+ test('THEN: yAxis min and max are included in config', () => {
756
+ const params = {
757
+ id: 'test-chart',
758
+ title: 'Test Chart',
759
+ xAxis: {
760
+ title: 'X Axis Title',
761
+ categories: ['A', 'B', 'C'],
762
+ type: 'linear',
763
+ labelFormat: '{value}',
764
+ },
765
+ chartType: 'line',
766
+ yAxis: {
767
+ title: 'Y Axis Title',
768
+ labelFormat: '{value}',
769
+ min: 0,
770
+ max: 100,
771
+ startOnTick: false,
772
+ endOnTick: true,
773
+ },
774
+ series: [],
775
+ };
776
+
777
+ const $ = cheerio.load(renderComponent('chart', params));
778
+ const configScript = $(`script[data-highcharts-config--${params.id}]`).html();
779
+
780
+ expect(configScript).toContain('"min":0');
781
+ expect(configScript).toContain('"max":100');
782
+ expect(configScript).toContain('"startOnTick":false');
783
+ expect(configScript).toContain('"endOnTick":true');
784
+ });
785
+ });
786
+
787
+ describe('WHEN: yAxis min and max are not provided', () => {
788
+ test('THEN: yAxis min and max are not included in config', () => {
789
+ const params = {
790
+ id: 'test-chart',
791
+ title: 'Test Chart',
792
+ xAxis: {
793
+ title: 'X Axis Title',
794
+ categories: ['A', 'B', 'C'],
795
+ type: 'linear',
796
+ labelFormat: '{value}',
797
+ },
798
+ chartType: 'line',
799
+ yAxis: {
800
+ title: 'Y Axis Title',
801
+ labelFormat: '{value}',
802
+ min: undefined,
803
+ max: undefined,
804
+ startOnTick: undefined,
805
+ endOnTick: undefined,
806
+ },
807
+ series: [],
808
+ };
809
+
810
+ const $ = cheerio.load(renderComponent('chart', params));
811
+ const configScript = $(`script[data-highcharts-config--${params.id}]`).html();
812
+
813
+ const config = JSON.parse(configScript);
814
+
815
+ expect(config.yAxis.min).toBeUndefined();
816
+ expect(config.yAxis.max).toBeUndefined();
817
+ expect(config.yAxis.startOnTick).toBeUndefined();
818
+ expect(config.yAxis.endOnTick).toBeUndefined();
819
+ });
820
+ });
423
821
  });
424
822
 
425
- describe('GIVEN: Params: Percentage Height Desktop', () => {
823
+ describe('GIVEN: Params: percentageHeightDesktop', () => {
426
824
  describe('WHEN: percentage height desktop is provided', () => {
427
825
  const $ = cheerio.load(renderComponent('chart', EXAMPLE_BAR_CHART_WITH_PERCENTAGE_HEIGHT_PARAMS));
428
826
  test('THEN: it does not include percentage height desktop', () => {
@@ -431,7 +829,7 @@ describe('Macro: Chart', () => {
431
829
  });
432
830
  });
433
831
 
434
- describe('GIVEN: Params: Percentage Height Mobile', () => {
832
+ describe('GIVEN: Params: percentageHeightMobile', () => {
435
833
  describe('WHEN: percentage height mobile is provided', () => {
436
834
  const $ = cheerio.load(renderComponent('chart', EXAMPLE_BAR_CHART_WITH_PERCENTAGE_HEIGHT_PARAMS));
437
835
  test('THEN: it does not include percentage height mobile', () => {
@@ -440,7 +838,7 @@ describe('Macro: Chart', () => {
440
838
  });
441
839
  });
442
840
 
443
- describe('GIVEN: Params: Caption', () => {
841
+ describe('GIVEN: Params: caption', () => {
444
842
  describe('WHEN: caption is provided', () => {
445
843
  const $ = cheerio.load(
446
844
  renderComponent('chart', {
@@ -455,7 +853,7 @@ describe('Macro: Chart', () => {
455
853
  });
456
854
  });
457
855
 
458
- describe('GIVEN: Params: Description', () => {
856
+ describe('GIVEN: Params: description', () => {
459
857
  describe('WHEN: description is provided', () => {
460
858
  const $ = cheerio.load(
461
859
  renderComponent('chart', {
@@ -465,13 +863,13 @@ describe('Macro: Chart', () => {
465
863
  );
466
864
 
467
865
  test('THEN: it renders the description for accessibility', () => {
468
- expect($('.ons-u-vh').text()).toBe('An accessible description for screen readers.');
866
+ expect($('#chart-audio-description-bar-chart-123').text()).toBe('An accessible description for screen readers.');
469
867
  });
470
868
  });
471
869
  });
472
870
 
473
- describe('GIVEN: Params: Download', () => {
474
- describe('WHEN: download object are provided', () => {
871
+ describe('GIVEN: Params: download', () => {
872
+ describe('WHEN: download object is provided', () => {
475
873
  const $ = cheerio.load(
476
874
  renderComponent('chart', {
477
875
  ...EXAMPLE_BAR_CHART_PARAMS,
@@ -497,8 +895,8 @@ describe('Macro: Chart', () => {
497
895
  });
498
896
  });
499
897
 
500
- describe('GIVEN: Stacked Bar Chart', () => {
501
- describe('WHEN: Stacked layout is enabled', () => {
898
+ describe('GIVEN: Params: useStackedLayout', () => {
899
+ describe('WHEN: useStackedLayout is set to true', () => {
502
900
  const $ = cheerio.load(
503
901
  renderComponent('chart', {
504
902
  ...EXAMPLE_BAR_CHART_PARAMS,
@@ -515,26 +913,69 @@ describe('Macro: Chart', () => {
515
913
  });
516
914
  });
517
915
  });
518
- });
519
-
520
- describe('FOR: Column Chart', () => {
521
- describe('GIVEN: Params: required', () => {
522
- describe('WHEN: required params are provided', () => {
523
- const $ = cheerio.load(renderComponent('chart', EXAMPLE_COLUMN_CHART_PARAMS));
524
916
 
917
+ describe('GIVEN: Params: annotations', () => {
918
+ describe('WHEN: annotations params are provided', () => {
919
+ const $ = cheerio.load(renderComponent('chart', EXAMPLE_BAR_CHART_WITH_ANNOTATIONS_PARAMS));
525
920
  test('THEN: it passes jest-axe checks', async () => {
526
921
  const results = await axe($.html());
527
922
  expect(results).toHaveNoViolations();
528
923
  });
529
924
 
530
- test('THEN: it renders the chart container with the correct data attributes', () => {
531
- expect($('[data-highcharts-base-chart]').attr('data-highcharts-type')).toBe('column');
532
- expect($('[data-highcharts-base-chart]').attr('data-highcharts-theme')).toBe('alternate');
533
- expect($('[data-highcharts-base-chart]').attr('data-highcharts-title')).toBe('Example Column Chart');
534
- expect($('[data-highcharts-base-chart]').attr('data-highcharts-id')).toBe('column-chart-123');
925
+ test('THEN: it renders the footnotes', () => {
926
+ expect($('.ons-chart__annotations-footnotes').text()).toContain('1');
927
+ expect($('.ons-chart__annotations-footnotes').text()).toContain('A test annotation');
535
928
  });
536
929
 
537
- test('THEN: it does NOT render optional fields', () => {
930
+ test('THEN: the footnotes are hidden from screen readers', () => {
931
+ expect($('.ons-chart__annotations-footnotes').attr('aria-hidden')).toBe('true');
932
+ });
933
+
934
+ test('THEN: it includes the annotations JSON config', () => {
935
+ const configScript = $(`script[data-highcharts-annotations--bar-chart-annotations-123]`).html();
936
+ expect(configScript).toContain('"text":"A test annotation"');
937
+ expect(configScript).toContain('"point":{"x":2,"y":3}');
938
+ expect(configScript).toContain('"labelOffsetX":10,"labelOffsetY":-50');
939
+ });
940
+ });
941
+ });
942
+
943
+ describe('GIVEN: Params: Series', () => {
944
+ describe('WHEN: chartType is not compatible with line series', () => {
945
+ const params = {
946
+ ...EXAMPLE_COLUMN_WITH_LINE_CHART_PARAMS,
947
+ chartType: 'bar',
948
+ };
949
+
950
+ const $ = cheerio.load(renderComponent('chart', params));
951
+ const configScript = $('script[data-highcharts-config--column-chart-123]').html();
952
+
953
+ test('THEN: it falls back to chartType and does not include "line" series', () => {
954
+ expect(configScript).not.toContain('"type":"line"');
955
+ expect(configScript).toContain('"type":"bar"');
956
+ });
957
+ });
958
+ });
959
+ });
960
+
961
+ describe('FOR: Column Chart', () => {
962
+ describe('GIVEN: Params: required', () => {
963
+ describe('WHEN: required params are provided', () => {
964
+ const $ = cheerio.load(renderComponent('chart', EXAMPLE_COLUMN_CHART_PARAMS));
965
+
966
+ test('THEN: it passes jest-axe checks', async () => {
967
+ const results = await axe($.html());
968
+ expect(results).toHaveNoViolations();
969
+ });
970
+
971
+ test('THEN: it renders the chart container with the correct data attributes', () => {
972
+ expect($('[data-highcharts-base-chart]').attr('data-highcharts-type')).toBe('column');
973
+ expect($('[data-highcharts-base-chart]').attr('data-highcharts-theme')).toBe('alternate');
974
+ expect($('[data-highcharts-base-chart]').attr('data-highcharts-title')).toBe('Example Column Chart');
975
+ expect($('[data-highcharts-base-chart]').attr('data-highcharts-id')).toBe('column-chart-123');
976
+ });
977
+
978
+ test('THEN: it does NOT render optional fields', () => {
538
979
  expect($('figcaption').length).toBe(0);
539
980
  expect($('.ons-chart__download-title').length).toBe(0);
540
981
  });
@@ -547,29 +988,124 @@ describe('Macro: Chart', () => {
547
988
  });
548
989
  });
549
990
 
550
- describe('GIVEN: Params: Config', () => {
551
- describe('WHEN: config params are provided', () => {
552
- const $ = cheerio.load(
553
- renderComponent('chart', {
554
- ...EXAMPLE_COLUMN_CHART_PARAMS,
555
- legend: true,
556
- }),
557
- );
991
+ describe('GIVEN: Params: legend', () => {
992
+ describe('WHEN: legend is true', () => {
993
+ const $ = cheerio.load(renderComponent('chart', { ...EXAMPLE_COLUMN_CHART_PARAMS, legend: true }));
994
+
995
+ test('THEN: it renders the legend', () => {
996
+ const configScript = $(`script[data-highcharts-config--column-chart-123]`).html();
997
+ expect(configScript).toContain('"legend":{"enabled":true}');
998
+ });
999
+ });
1000
+
1001
+ describe('WHEN: legend is false', () => {
1002
+ const $ = cheerio.load(renderComponent('chart', { ...EXAMPLE_COLUMN_CHART_PARAMS, legend: false }));
558
1003
 
559
- test('THEN: it renders the legend when enabled', () => {
1004
+ test('THEN: it disables the legend', () => {
560
1005
  const configScript = $(`script[data-highcharts-config--column-chart-123]`).html();
561
- expect(configScript).toContain('"enabled":true');
1006
+ expect(configScript).toContain('"legend":{"enabled":false}');
562
1007
  });
1008
+ });
1009
+
1010
+ describe('WHEN: legend is not provided', () => {
1011
+ const $ = cheerio.load(renderComponent('chart', EXAMPLE_COLUMN_CHART_PARAMS));
563
1012
 
564
- test('THEN: it includes correct xAxis and yAxis titles', () => {
1013
+ test('THEN: it defaults to enabled', () => {
565
1014
  const configScript = $(`script[data-highcharts-config--column-chart-123]`).html();
1015
+ expect(configScript).toContain('"legend":{"enabled":true}');
1016
+ });
1017
+ });
1018
+ });
1019
+
1020
+ describe('GIVEN: Params: xAxis', () => {
1021
+ describe('WHEN: xAxis options are provided', () => {
1022
+ const $ = cheerio.load(renderComponent('chart', EXAMPLE_COLUMN_CHART_PARAMS));
1023
+ const configScript = $(`script[data-highcharts-config--column-chart-123]`).html();
1024
+
1025
+ test('THEN: it renders the xAxis correctly', () => {
566
1026
  expect(configScript).toContain('"text":"X Axis Title"');
1027
+ });
1028
+ });
1029
+ });
1030
+
1031
+ describe('GIVEN: Params: yAxis', () => {
1032
+ describe('WHEN: yAxis options are provided', () => {
1033
+ const $ = cheerio.load(renderComponent('chart', EXAMPLE_COLUMN_CHART_PARAMS));
1034
+ const configScript = $(`script[data-highcharts-config--column-chart-123]`).html();
1035
+
1036
+ test('THEN: it renders the yAxis correctly', () => {
567
1037
  expect(configScript).toContain('"text":"Y Axis Title"');
568
1038
  });
569
1039
  });
1040
+ describe('WHEN: yAxis min and max are provided', () => {
1041
+ test('THEN: yAxis min and max are included in config', () => {
1042
+ const params = {
1043
+ id: 'test-chart',
1044
+ title: 'Test Chart',
1045
+ xAxis: {
1046
+ title: 'X Axis Title',
1047
+ categories: ['A', 'B', 'C'],
1048
+ type: 'linear',
1049
+ labelFormat: '{value}',
1050
+ },
1051
+ chartType: 'column',
1052
+ yAxis: {
1053
+ title: 'Y Axis Title',
1054
+ labelFormat: '{value}',
1055
+ min: 0,
1056
+ max: 100,
1057
+ startOnTick: false,
1058
+ endOnTick: true,
1059
+ },
1060
+ series: [],
1061
+ };
1062
+
1063
+ const $ = cheerio.load(renderComponent('chart', params));
1064
+ const configScript = $(`script[data-highcharts-config--${params.id}]`).html();
1065
+
1066
+ expect(configScript).toContain('"min":0');
1067
+ expect(configScript).toContain('"max":100');
1068
+ expect(configScript).toContain('"startOnTick":false');
1069
+ expect(configScript).toContain('"endOnTick":true');
1070
+ });
1071
+ });
1072
+ describe('WHEN: yAxis min and max are not provided', () => {
1073
+ test('THEN: yAxis min and max are not included in config', () => {
1074
+ const params = {
1075
+ id: 'test-chart',
1076
+ title: 'Test Chart',
1077
+ xAxis: {
1078
+ title: 'X Axis Title',
1079
+ categories: ['A', 'B', 'C'],
1080
+ type: 'linear',
1081
+ labelFormat: '{value}',
1082
+ },
1083
+ chartType: 'column',
1084
+ yAxis: {
1085
+ title: 'Y Axis Title',
1086
+ labelFormat: '{value}',
1087
+ min: undefined,
1088
+ max: undefined,
1089
+ startOnTick: undefined,
1090
+ endOnTick: undefined,
1091
+ },
1092
+ series: [],
1093
+ };
1094
+
1095
+ const $ = cheerio.load(renderComponent('chart', params));
1096
+ const configScript = $(`script[data-highcharts-config--${params.id}]`).html();
1097
+
1098
+ const config = JSON.parse(configScript);
1099
+
1100
+ expect(config.yAxis.min).toBeUndefined();
1101
+ expect(config.yAxis.max).toBeUndefined();
1102
+ expect(config.yAxis.startOnTick).toBeUndefined();
1103
+ expect(config.yAxis.endOnTick).toBeUndefined();
1104
+ });
1105
+ });
570
1106
  });
571
1107
 
572
- describe('GIVEN: Params: Percentage Height Desktop', () => {
1108
+ describe('GIVEN: Params: percentageHeightDesktop', () => {
573
1109
  describe('WHEN: percentage height desktop is provided', () => {
574
1110
  const $ = cheerio.load(renderComponent('chart', EXAMPLE_COLUMN_CHART_PARAMS));
575
1111
  test('THEN: it includes correct percentage height desktop', () => {
@@ -578,7 +1114,7 @@ describe('Macro: Chart', () => {
578
1114
  });
579
1115
  });
580
1116
 
581
- describe('GIVEN: Params: Percentage Height Mobile', () => {
1117
+ describe('GIVEN: Params: percentageHeightMobile', () => {
582
1118
  describe('WHEN: percentage height mobile is provided', () => {
583
1119
  const $ = cheerio.load(renderComponent('chart', EXAMPLE_COLUMN_CHART_PARAMS));
584
1120
  test('THEN: it includes correct percentage height mobile', () => {
@@ -587,7 +1123,7 @@ describe('Macro: Chart', () => {
587
1123
  });
588
1124
  });
589
1125
 
590
- describe('GIVEN: Params: Caption', () => {
1126
+ describe('GIVEN: Params: caption', () => {
591
1127
  describe('WHEN: caption is provided', () => {
592
1128
  const $ = cheerio.load(
593
1129
  renderComponent('chart', {
@@ -602,7 +1138,7 @@ describe('Macro: Chart', () => {
602
1138
  });
603
1139
  });
604
1140
 
605
- describe('GIVEN: Params: Description', () => {
1141
+ describe('GIVEN: Params: description', () => {
606
1142
  describe('WHEN: description is provided', () => {
607
1143
  const $ = cheerio.load(
608
1144
  renderComponent('chart', {
@@ -612,13 +1148,13 @@ describe('Macro: Chart', () => {
612
1148
  );
613
1149
 
614
1150
  test('THEN: it renders the description for accessibility', () => {
615
- expect($('.ons-u-vh').text()).toBe('An accessible description for screen readers.');
1151
+ expect($('#chart-audio-description-column-chart-123').text()).toBe('An accessible description for screen readers.');
616
1152
  });
617
1153
  });
618
1154
  });
619
1155
 
620
- describe('GIVEN: Params: Download', () => {
621
- describe('WHEN: download object are provided', () => {
1156
+ describe('GIVEN: Params: download', () => {
1157
+ describe('WHEN: download object is provided', () => {
622
1158
  const $ = cheerio.load(
623
1159
  renderComponent('chart', {
624
1160
  ...EXAMPLE_COLUMN_CHART_PARAMS,
@@ -644,7 +1180,7 @@ describe('Macro: Chart', () => {
644
1180
  });
645
1181
  });
646
1182
 
647
- describe('GIVEN: Stacked Column Chart', () => {
1183
+ describe('GIVEN: Params: useStackedLayout', () => {
648
1184
  describe('WHEN: Stacked layout is enabled', () => {
649
1185
  const $ = cheerio.load(
650
1186
  renderComponent('chart', {
@@ -662,69 +1198,8 @@ describe('Macro: Chart', () => {
662
1198
  });
663
1199
  });
664
1200
  });
665
- });
666
-
667
- describe('FOR: Line chart with annotations', () => {
668
- describe('GIVEN: Params: Annotations', () => {
669
- describe('WHEN: annotations params are provided', () => {
670
- const $ = cheerio.load(renderComponent('chart', EXAMPLE_LINE_CHART_WITH_ANNOTATIONS_PARAMS));
671
-
672
- test('THEN: it passes jest-axe checks', async () => {
673
- const results = await axe($.html());
674
- expect(results).toHaveNoViolations();
675
- });
676
-
677
- test('THEN: it renders the footnotes', () => {
678
- expect($('.ons-chart__annotations-footnotes').text()).toContain('1');
679
- expect($('.ons-chart__annotations-footnotes').text()).toContain('A test annotation');
680
- expect($('.ons-chart__annotations-footnotes').text()).toContain('2');
681
- expect($('.ons-chart__annotations-footnotes').text()).toContain('Another test annotation');
682
- });
683
-
684
- test('THEN: the footnotes are hidden from screen readers', () => {
685
- expect($('.ons-chart__annotations-footnotes').attr('aria-hidden')).toBe('true');
686
- });
687
-
688
- test('THEN: it includes the Annotations JSON config', () => {
689
- const configScript = $(`script[data-highcharts-annotations--line-chart-annotations-123]`).html();
690
- expect(configScript).toContain('"text":"A test annotation"');
691
- expect(configScript).toContain('"point":{"x":10,"y":1.3}');
692
- expect(configScript).toContain('"labelOffsetX":10,"labelOffsetY":-50');
693
- });
694
- });
695
- });
696
- });
697
-
698
- describe('FOR: Bar chart with annotations', () => {
699
- describe('GIVEN: Params: Annotations', () => {
700
- describe('WHEN: annotations params are provided', () => {
701
- const $ = cheerio.load(renderComponent('chart', EXAMPLE_BAR_CHART_WITH_ANNOTATIONS_PARAMS));
702
- test('THEN: it passes jest-axe checks', async () => {
703
- const results = await axe($.html());
704
- expect(results).toHaveNoViolations();
705
- });
706
-
707
- test('THEN: it renders the footnotes', () => {
708
- expect($('.ons-chart__annotations-footnotes').text()).toContain('1');
709
- expect($('.ons-chart__annotations-footnotes').text()).toContain('A test annotation');
710
- });
711
-
712
- test('THEN: the footnotes are hidden from screen readers', () => {
713
- expect($('.ons-chart__annotations-footnotes').attr('aria-hidden')).toBe('true');
714
- });
715
-
716
- test('THEN: it includes the Annotations JSON config', () => {
717
- const configScript = $(`script[data-highcharts-annotations--bar-chart-annotations-123]`).html();
718
- expect(configScript).toContain('"text":"A test annotation"');
719
- expect(configScript).toContain('"point":{"x":2,"y":3}');
720
- expect(configScript).toContain('"labelOffsetX":10,"labelOffsetY":-50');
721
- });
722
- });
723
- });
724
- });
725
1201
 
726
- describe('FOR: Column chart with annotations', () => {
727
- describe('GIVEN: Params: Annotations', () => {
1202
+ describe('GIVEN: Params: annotations', () => {
728
1203
  describe('WHEN: annotations params are provided', () => {
729
1204
  const $ = cheerio.load(renderComponent('chart', EXAMPLE_COLUMN_CHART_WITH_ANNOTATIONS_PARAMS));
730
1205
 
@@ -742,7 +1217,7 @@ describe('Macro: Chart', () => {
742
1217
  expect($('.ons-chart__annotations-footnotes').attr('aria-hidden')).toBe('true');
743
1218
  });
744
1219
 
745
- test('THEN: it includes the Annotations JSON config', () => {
1220
+ test('THEN: it includes the annotations JSON config', () => {
746
1221
  const configScript = $(`script[data-highcharts-annotations--column-chart-annotations-123]`).html();
747
1222
  expect(configScript).toContain('"text":"A test annotation"');
748
1223
  expect(configScript).toContain('"point":{"x":11,"y":31.8}');
@@ -750,11 +1225,9 @@ describe('Macro: Chart', () => {
750
1225
  });
751
1226
  });
752
1227
  });
753
- });
754
1228
 
755
- describe('FOR: Column Chart with Line', () => {
756
- describe('GIVEN: Params: required', () => {
757
- describe('WHEN: required params are provided', () => {
1229
+ describe('GIVEN: Params: series', () => {
1230
+ describe('WHEN: seriesType is line and required params are provided', () => {
758
1231
  const $ = cheerio.load(renderComponent('chart', EXAMPLE_COLUMN_WITH_LINE_CHART_PARAMS));
759
1232
  const configScript = $(`script[data-highcharts-config--column-chart-123]`).html();
760
1233
 
@@ -781,7 +1254,8 @@ describe('Macro: Chart', () => {
781
1254
  expect(configScript).toContain('"text":"Y Axis Title"');
782
1255
  });
783
1256
  });
784
- describe('WHEN: more than one line is provided', () => {
1257
+
1258
+ describe('WHEN: seriesType is line and more than one line is provided', () => {
785
1259
  const $ = cheerio.load(
786
1260
  renderComponent('chart', {
787
1261
  ...EXAMPLE_COLUMN_WITH_LINE_CHART_PARAMS,
@@ -799,78 +1273,8 @@ describe('Macro: Chart', () => {
799
1273
  expect(lineTypeMatches).toBe(1);
800
1274
  });
801
1275
  });
802
- });
803
-
804
- describe('GIVEN: Params: Legend', () => {
805
- describe('WHEN: legend is enabled', () => {
806
- const $ = cheerio.load(renderComponent('chart', { ...EXAMPLE_COLUMN_WITH_LINE_CHART_PARAMS, legend: false }));
807
-
808
- test('THEN: it renders the legend', () => {
809
- const configScript = $(`script[data-highcharts-config--column-chart-123]`).html();
810
- expect(configScript).toContain('"enabled":false');
811
- });
812
- });
813
- });
814
-
815
- describe('GIVEN: Params: Caption', () => {
816
- describe('WHEN: caption is provided', () => {
817
- const $ = cheerio.load(
818
- renderComponent('chart', {
819
- ...EXAMPLE_COLUMN_WITH_LINE_CHART_PARAMS,
820
- caption: 'This is an example caption for the chart.',
821
- }),
822
- );
823
-
824
- test('THEN: it renders the caption when provided', () => {
825
- expect($('figcaption').text()).toBe('This is an example caption for the chart.');
826
- });
827
- });
828
- });
829
-
830
- describe('GIVEN: Params: Description', () => {
831
- describe('WHEN: description is provided', () => {
832
- const $ = cheerio.load(
833
- renderComponent('chart', {
834
- ...EXAMPLE_COLUMN_WITH_LINE_CHART_PARAMS,
835
- description: 'An accessible description for screen readers.',
836
- }),
837
- );
838
-
839
- test('THEN: it renders the description for accessibility', () => {
840
- expect($('.ons-u-vh').text()).toBe('An accessible description for screen readers.');
841
- });
842
- });
843
- });
844
-
845
- describe('GIVEN: Params: Download', () => {
846
- describe('WHEN: download object is provided', () => {
847
- const $ = cheerio.load(
848
- renderComponent('chart', {
849
- ...EXAMPLE_COLUMN_WITH_LINE_CHART_PARAMS,
850
- download: {
851
- title: 'Download Chart Data',
852
- itemsList: [
853
- { text: 'Download as PNG', url: 'https://example.com/chart.png' },
854
- { text: 'Download as CSV', url: 'https://example.com/chart.csv' },
855
- ],
856
- },
857
- }),
858
- );
859
-
860
- test('THEN: it renders the download section correctly', () => {
861
- expect($('.ons-chart__download-title').text()).toBe('Download Chart Data');
862
-
863
- const downloadLinks = $('.ons-chart__download-title').next().find('li a');
864
- expect(downloadLinks.eq(0).text()).toBe('Download as PNG');
865
- expect(downloadLinks.eq(0).attr('href')).toBe('https://example.com/chart.png');
866
- expect(downloadLinks.eq(1).text()).toBe('Download as CSV');
867
- expect(downloadLinks.eq(1).attr('href')).toBe('https://example.com/chart.csv');
868
- });
869
- });
870
- });
871
1276
 
872
- describe('GIVEN: Params: Series: Type', () => {
873
- describe('WHEN: a series has an invalid type', () => {
1277
+ describe('WHEN: a series item has an invalid type', () => {
874
1278
  const invalidTypeParams = {
875
1279
  ...EXAMPLE_COLUMN_WITH_LINE_CHART_PARAMS,
876
1280
  series: [
@@ -889,23 +1293,6 @@ describe('Macro: Chart', () => {
889
1293
  });
890
1294
  });
891
1295
  });
892
-
893
- describe('GIVEN: Params: ChartType', () => {
894
- describe('WHEN: chartType is not compatible with line series', () => {
895
- const params = {
896
- ...EXAMPLE_COLUMN_WITH_LINE_CHART_PARAMS,
897
- chartType: 'bar',
898
- };
899
-
900
- const $ = cheerio.load(renderComponent('chart', params));
901
- const configScript = $('script[data-highcharts-config--column-chart-123]').html();
902
-
903
- test('THEN: it falls back to chartType and does not include "line" series', () => {
904
- expect(configScript).not.toContain('"type":"line"');
905
- expect(configScript).toContain('"type":"bar"');
906
- });
907
- });
908
- });
909
1296
  });
910
1297
 
911
1298
  describe('FOR: Scatter chart', () => {
@@ -926,38 +1313,175 @@ describe('Macro: Chart', () => {
926
1313
  });
927
1314
  });
928
1315
  });
929
- });
930
-
931
- describe('FOR: Area Chart', () => {
932
- describe('GIVEN: Params: required', () => {
933
- describe('WHEN: required params are provided', () => {
934
- const $ = cheerio.load(renderComponent('chart', EXAMPLE_AREA_CHART_PARAMS));
935
- const configScript = $(`script[data-highcharts-config--area-chart-123]`).html();
936
1316
 
937
- test('THEN: it passes jest-axe checks', async () => {
938
- const results = await axe($.html());
939
- expect(results).toHaveNoViolations();
940
- });
1317
+ describe('GIVEN: Params: xAxis', () => {
1318
+ describe('WHEN: xAxis options are provided', () => {
1319
+ test('THEN: xAxis min and max are included in config', () => {
1320
+ const params = {
1321
+ id: 'test-chart',
1322
+ title: 'Test Chart',
1323
+ chartType: 'scatter',
1324
+ xAxis: {
1325
+ title: 'X Axis Title',
1326
+ categories: ['A', 'B', 'C'],
1327
+ type: 'linear',
1328
+ labelFormat: '{value}',
1329
+ min: 1,
1330
+ max: 10,
1331
+ startOnTick: true,
1332
+ endOnTick: false,
1333
+ },
1334
+ yAxis: {
1335
+ title: 'Y Axis Title',
1336
+ labelFormat: '{value}',
1337
+ },
1338
+ series: [],
1339
+ };
941
1340
 
942
- test('THEN: it includes at least one area series', () => {
943
- expect(configScript).toContain('"type":"area"');
944
- });
1341
+ const $ = cheerio.load(renderComponent('chart', params));
1342
+ const configScript = $(`script[data-highcharts-config--${params.id}]`).html();
945
1343
 
946
- test('THEN: it renders the chart container with correct data attributes', () => {
947
- expect($('[data-highcharts-base-chart]').attr('data-highcharts-type')).toBe('area');
948
- expect($('[data-highcharts-base-chart]').attr('data-highcharts-theme')).toBe('primary');
949
- expect($('[data-highcharts-base-chart]').attr('data-highcharts-title')).toBe('Example Area Chart');
950
- expect($('[data-highcharts-base-chart]').attr('data-highcharts-id')).toBe('area-chart-123');
1344
+ expect(configScript).toContain('"min":1');
1345
+ expect(configScript).toContain('"max":10');
1346
+ expect(configScript).toContain('"startOnTick":true');
1347
+ expect(configScript).toContain('"endOnTick":false');
951
1348
  });
1349
+ });
952
1350
 
953
- test('THEN: it includes the Highcharts JSON config', () => {
1351
+ describe('WHEN: xAxis options are not provided', () => {
1352
+ test('THEN: xAxis min and max are not included in config', () => {
1353
+ const params = {
1354
+ id: 'test-chart',
1355
+ title: 'Test Chart',
1356
+ chartType: 'scatter',
1357
+ xAxis: {
1358
+ title: 'X Axis Title',
1359
+ categories: ['A', 'B', 'C'],
1360
+ type: 'linear',
1361
+ labelFormat: '{value}',
1362
+ min: undefined,
1363
+ max: undefined,
1364
+ startOnTick: undefined,
1365
+ endOnTick: undefined,
1366
+ },
1367
+ yAxis: {
1368
+ title: 'Y Axis Title',
1369
+ labelFormat: '{value}',
1370
+ },
1371
+ series: [],
1372
+ };
1373
+
1374
+ const $ = cheerio.load(renderComponent('chart', params));
1375
+ const configScript = $(`script[data-highcharts-config--${params.id}]`).html();
1376
+
1377
+ const config = JSON.parse(configScript);
1378
+
1379
+ expect(config.xAxis.min).toBeUndefined();
1380
+ expect(config.xAxis.max).toBeUndefined();
1381
+ expect(config.xAxis.startOnTick).toBeUndefined();
1382
+ expect(config.xAxis.endOnTick).toBeUndefined();
1383
+ });
1384
+ });
1385
+ describe('WHEN: yAxis options are provided', () => {
1386
+ test('THEN: yAxis min and max are included in config', () => {
1387
+ const params = {
1388
+ id: 'test-chart',
1389
+ title: 'Test Chart',
1390
+ xAxis: {
1391
+ title: 'X Axis Title',
1392
+ categories: ['A', 'B', 'C'],
1393
+ type: 'linear',
1394
+ labelFormat: '{value}',
1395
+ },
1396
+ chartType: 'scatter',
1397
+ yAxis: {
1398
+ title: 'Y Axis Title',
1399
+ labelFormat: '{value}',
1400
+ min: 0,
1401
+ max: 100,
1402
+ startOnTick: false,
1403
+ endOnTick: true,
1404
+ },
1405
+ series: [],
1406
+ };
1407
+
1408
+ const $ = cheerio.load(renderComponent('chart', params));
1409
+ const configScript = $(`script[data-highcharts-config--${params.id}]`).html();
1410
+
1411
+ expect(configScript).toContain('"min":0');
1412
+ expect(configScript).toContain('"max":100');
1413
+ expect(configScript).toContain('"startOnTick":false');
1414
+ expect(configScript).toContain('"endOnTick":true');
1415
+ });
1416
+ });
1417
+
1418
+ describe('WHEN: yAxis options are not provided', () => {
1419
+ test('THEN: yAxis min and max are not included in config', () => {
1420
+ const params = {
1421
+ id: 'test-chart',
1422
+ title: 'Test Chart',
1423
+ xAxis: {
1424
+ title: 'X Axis Title',
1425
+ categories: ['A', 'B', 'C'],
1426
+ type: 'linear',
1427
+ labelFormat: '{value}',
1428
+ },
1429
+ chartType: 'scatter',
1430
+ yAxis: {
1431
+ title: 'Y Axis Title',
1432
+ labelFormat: '{value}',
1433
+ min: undefined,
1434
+ max: undefined,
1435
+ startOnTick: undefined,
1436
+ endOnTick: undefined,
1437
+ },
1438
+ series: [],
1439
+ };
1440
+
1441
+ const $ = cheerio.load(renderComponent('chart', params));
1442
+ const configScript = $(`script[data-highcharts-config--${params.id}]`).html();
1443
+
1444
+ const config = JSON.parse(configScript);
1445
+
1446
+ expect(config.yAxis.min).toBeUndefined();
1447
+ expect(config.yAxis.max).toBeUndefined();
1448
+ expect(config.yAxis.startOnTick).toBeUndefined();
1449
+ expect(config.yAxis.endOnTick).toBeUndefined();
1450
+ });
1451
+ });
1452
+ });
1453
+ });
1454
+
1455
+ describe('FOR: Area Chart', () => {
1456
+ describe('GIVEN: Params: required', () => {
1457
+ describe('WHEN: required params are provided', () => {
1458
+ const $ = cheerio.load(renderComponent('chart', EXAMPLE_AREA_CHART_PARAMS));
1459
+ const configScript = $(`script[data-highcharts-config--area-chart-123]`).html();
1460
+
1461
+ test('THEN: it passes jest-axe checks', async () => {
1462
+ const results = await axe($.html());
1463
+ expect(results).toHaveNoViolations();
1464
+ });
1465
+
1466
+ test('THEN: it includes at least one area series', () => {
1467
+ expect(configScript).toContain('"type":"area"');
1468
+ });
1469
+
1470
+ test('THEN: it renders the chart container with correct data attributes', () => {
1471
+ expect($('[data-highcharts-base-chart]').attr('data-highcharts-type')).toBe('area');
1472
+ expect($('[data-highcharts-base-chart]').attr('data-highcharts-theme')).toBe('primary');
1473
+ expect($('[data-highcharts-base-chart]').attr('data-highcharts-title')).toBe('Example Area Chart');
1474
+ expect($('[data-highcharts-base-chart]').attr('data-highcharts-id')).toBe('area-chart-123');
1475
+ });
1476
+
1477
+ test('THEN: it includes the Highcharts JSON config', () => {
954
1478
  expect(configScript).toContain('"text":"X Axis Title"');
955
1479
  expect(configScript).toContain('"text":"Y Axis Title"');
956
1480
  });
957
1481
  });
958
1482
  });
959
1483
 
960
- describe('GIVEN: Params: Legend', () => {
1484
+ describe('GIVEN: Params: legend', () => {
961
1485
  describe('WHEN: legend is enabled', () => {
962
1486
  const $ = cheerio.load(renderComponent('chart', { ...EXAMPLE_AREA_CHART_PARAMS, legend: false }));
963
1487
 
@@ -968,7 +1492,7 @@ describe('Macro: Chart', () => {
968
1492
  });
969
1493
  });
970
1494
 
971
- describe('GIVEN: Params: Caption', () => {
1495
+ describe('GIVEN: Params: caption', () => {
972
1496
  describe('WHEN: caption is provided', () => {
973
1497
  const $ = cheerio.load(
974
1498
  renderComponent('chart', {
@@ -983,7 +1507,7 @@ describe('Macro: Chart', () => {
983
1507
  });
984
1508
  });
985
1509
 
986
- describe('GIVEN: Params: Description', () => {
1510
+ describe('GIVEN: Params: description', () => {
987
1511
  describe('WHEN: description is provided', () => {
988
1512
  const $ = cheerio.load(
989
1513
  renderComponent('chart', {
@@ -993,13 +1517,13 @@ describe('Macro: Chart', () => {
993
1517
  );
994
1518
 
995
1519
  test('THEN: it renders the description for accessibility', () => {
996
- expect($('.ons-u-vh').text()).toBe('An accessible description for screen readers.');
1520
+ expect($('#chart-audio-description-area-chart-123').text()).toBe('An accessible description for screen readers.');
997
1521
  });
998
1522
  });
999
1523
  });
1000
1524
 
1001
- describe('GIVEN: Params: Download', () => {
1002
- describe('WHEN: download object are provided', () => {
1525
+ describe('GIVEN: Params: download', () => {
1526
+ describe('WHEN: download object is provided', () => {
1003
1527
  const $ = cheerio.load(
1004
1528
  renderComponent('chart', {
1005
1529
  ...EXAMPLE_AREA_CHART_PARAMS,
@@ -1025,7 +1549,7 @@ describe('Macro: Chart', () => {
1025
1549
  });
1026
1550
  });
1027
1551
 
1028
- describe('GIVEN: Params: Footnotes', () => {
1552
+ describe('GIVEN: Params: footnotes', () => {
1029
1553
  describe('WHEN: footnotes are provided', () => {
1030
1554
  const $ = cheerio.load(
1031
1555
  renderComponent('chart', {
@@ -1044,13 +1568,82 @@ describe('Macro: Chart', () => {
1044
1568
  });
1045
1569
  });
1046
1570
  });
1571
+
1572
+ describe('GIVEN: Params: yAxis', () => {
1573
+ describe('WHEN: yAxis options are provided', () => {
1574
+ test('THEN: yAxis min and max are included in config', () => {
1575
+ const params = {
1576
+ id: 'test-chart',
1577
+ title: 'Test Chart',
1578
+ xAxis: {
1579
+ title: 'X Axis Title',
1580
+ categories: ['A', 'B', 'C'],
1581
+ type: 'linear',
1582
+ labelFormat: '{value}',
1583
+ },
1584
+ chartType: 'area',
1585
+ yAxis: {
1586
+ title: 'Y Axis Title',
1587
+ labelFormat: '{value}',
1588
+ min: 0,
1589
+ max: 100,
1590
+ startOnTick: false,
1591
+ endOnTick: true,
1592
+ },
1593
+ series: [],
1594
+ };
1595
+
1596
+ const $ = cheerio.load(renderComponent('chart', params));
1597
+ const configScript = $(`script[data-highcharts-config--${params.id}]`).html();
1598
+
1599
+ expect(configScript).toContain('"min":0');
1600
+ expect(configScript).toContain('"max":100');
1601
+ expect(configScript).toContain('"startOnTick":false');
1602
+ expect(configScript).toContain('"endOnTick":true');
1603
+ });
1604
+ });
1605
+ describe('WHEN: yAxis options are not provided', () => {
1606
+ test('THEN: yAxis min and max are not included in config', () => {
1607
+ const params = {
1608
+ id: 'test-chart',
1609
+ title: 'Test Chart',
1610
+ xAxis: {
1611
+ title: 'X Axis Title',
1612
+ categories: ['A', 'B', 'C'],
1613
+ type: 'linear',
1614
+ labelFormat: '{value}',
1615
+ },
1616
+ chartType: 'area',
1617
+ yAxis: {
1618
+ title: 'Y Axis Title',
1619
+ labelFormat: '{value}',
1620
+ min: undefined,
1621
+ max: undefined,
1622
+ startOnTick: undefined,
1623
+ endOnTick: undefined,
1624
+ },
1625
+ series: [],
1626
+ };
1627
+
1628
+ const $ = cheerio.load(renderComponent('chart', params));
1629
+ const configScript = $(`script[data-highcharts-config--${params.id}]`).html();
1630
+
1631
+ const config = JSON.parse(configScript);
1632
+
1633
+ expect(config.yAxis.min).toBeUndefined();
1634
+ expect(config.yAxis.max).toBeUndefined();
1635
+ expect(config.yAxis.startOnTick).toBeUndefined();
1636
+ expect(config.yAxis.endOnTick).toBeUndefined();
1637
+ });
1638
+ });
1639
+ });
1047
1640
  });
1048
1641
 
1049
1642
  describe('FOR: Boxplot Chart', () => {
1050
1643
  describe('GIVEN: Params: required', () => {
1051
1644
  describe('WHEN: required params are provided', () => {
1052
1645
  const $ = cheerio.load(renderComponent('chart', EXAMPLE_BOXPLOT_CHART_PARAMS));
1053
- const configScript = $(`script[data-highcharts-config--uuid]`).html();
1646
+ const configScript = $(`script[data-highcharts-config--boxplot-chart-123]`).html();
1054
1647
 
1055
1648
  test('THEN: it passes jest-axe checks', async () => {
1056
1649
  const results = await axe($.html());
@@ -1066,7 +1659,7 @@ describe('Macro: Chart', () => {
1066
1659
  expect(chartContainer.attr('data-highcharts-type')).toBe('boxplot');
1067
1660
  expect(chartContainer.attr('data-highcharts-theme')).toBe('primary');
1068
1661
  expect(chartContainer.attr('data-highcharts-title')).toBe('Example Boxplot Chart');
1069
- expect(chartContainer.attr('data-highcharts-id')).toBe('uuid');
1662
+ expect(chartContainer.attr('data-highcharts-id')).toBe('boxplot-chart-123');
1070
1663
  });
1071
1664
 
1072
1665
  test('THEN: it includes the Highcharts JSON config', () => {
@@ -1076,7 +1669,7 @@ describe('Macro: Chart', () => {
1076
1669
  });
1077
1670
  });
1078
1671
 
1079
- describe('GIVEN: Params: Legend', () => {
1672
+ describe('GIVEN: Params: legend', () => {
1080
1673
  describe('WHEN: both labels are provided and legend is enabled', () => {
1081
1674
  const $ = cheerio.load(
1082
1675
  renderComponent('chart', {
@@ -1159,7 +1752,7 @@ describe('Macro: Chart', () => {
1159
1752
  });
1160
1753
  });
1161
1754
 
1162
- describe('GIVEN: Params: Description', () => {
1755
+ describe('GIVEN: Params: description', () => {
1163
1756
  describe('WHEN: description is provided', () => {
1164
1757
  const accessibleDescription = 'An accessible description for screen readers.';
1165
1758
  const $ = cheerio.load(
@@ -1170,18 +1763,17 @@ describe('Macro: Chart', () => {
1170
1763
  );
1171
1764
 
1172
1765
  test('THEN: it renders the description for accessibility', () => {
1173
- expect($('.ons-u-vh').text()).toBe(accessibleDescription);
1766
+ expect($('#chart-audio-description-boxplot-chart-123').text()).toBe(accessibleDescription);
1174
1767
  });
1175
1768
  });
1176
1769
  });
1177
1770
 
1178
- describe('GIVEN: Params: Estimate Line and Uncertainty Range Labels', () => {
1179
- describe('WHEN: both labels are provided', () => {
1771
+ describe('GIVEN: Params: estimateLineLabel', () => {
1772
+ describe('WHEN: estimateLineLabel is provided', () => {
1180
1773
  const $ = cheerio.load(
1181
1774
  renderComponent('chart', {
1182
1775
  ...EXAMPLE_BOXPLOT_CHART_PARAMS,
1183
1776
  estimateLineLabel: 'Estimated value',
1184
- uncertaintyRangeLabel: '95% Confidence Interval',
1185
1777
  }),
1186
1778
  );
1187
1779
 
@@ -1189,6 +1781,17 @@ describe('Macro: Chart', () => {
1189
1781
  const baseChart = $('[data-highcharts-base-chart]');
1190
1782
  expect(baseChart.attr('data-highcharts-estimate-line-label')).toBe('Estimated value');
1191
1783
  });
1784
+ });
1785
+ });
1786
+
1787
+ describe('GIVEN: Params: uncertaintyRangeLabel', () => {
1788
+ describe('WHEN: uncertaintyRangeLabel is provided', () => {
1789
+ const $ = cheerio.load(
1790
+ renderComponent('chart', {
1791
+ ...EXAMPLE_BOXPLOT_CHART_PARAMS,
1792
+ uncertaintyRangeLabel: '95% Confidence Interval',
1793
+ }),
1794
+ );
1192
1795
 
1193
1796
  test('THEN: it sets the uncertainty range label as a data attribute', () => {
1194
1797
  const baseChart = $('[data-highcharts-base-chart]');
@@ -1196,13 +1799,82 @@ describe('Macro: Chart', () => {
1196
1799
  });
1197
1800
  });
1198
1801
  });
1802
+
1803
+ describe('GIVEN: Params: yAxis', () => {
1804
+ describe('WHEN: yAxis min and max are provided', () => {
1805
+ test('THEN: yAxis min and max are included in config ', () => {
1806
+ const params = {
1807
+ id: 'test-chart',
1808
+ title: 'Test Chart',
1809
+ xAxis: {
1810
+ title: 'X Axis Title',
1811
+ categories: ['A', 'B', 'C'],
1812
+ type: 'linear',
1813
+ labelFormat: '{value}',
1814
+ },
1815
+ chartType: 'boxplot',
1816
+ yAxis: {
1817
+ title: 'Y Axis Title',
1818
+ labelFormat: '{value}',
1819
+ min: 0,
1820
+ max: 100,
1821
+ startOnTick: false,
1822
+ endOnTick: true,
1823
+ },
1824
+ series: [],
1825
+ };
1826
+
1827
+ const $ = cheerio.load(renderComponent('chart', params));
1828
+ const configScript = $(`script[data-highcharts-config--${params.id}]`).html();
1829
+
1830
+ expect(configScript).toContain('"min":0');
1831
+ expect(configScript).toContain('"max":100');
1832
+ expect(configScript).toContain('"startOnTick":false');
1833
+ expect(configScript).toContain('"endOnTick":true');
1834
+ });
1835
+ });
1836
+ describe('WHEN: yAxis min and max are not provided', () => {
1837
+ test('THEN: yAxis min and max are not included in config', () => {
1838
+ const params = {
1839
+ id: 'test-chart',
1840
+ title: 'Test Chart',
1841
+ xAxis: {
1842
+ title: 'X Axis Title',
1843
+ categories: ['A', 'B', 'C'],
1844
+ type: 'linear',
1845
+ labelFormat: '{value}',
1846
+ },
1847
+ chartType: 'boxplot',
1848
+ yAxis: {
1849
+ title: 'Y Axis Title',
1850
+ labelFormat: '{value}',
1851
+ min: undefined,
1852
+ max: undefined,
1853
+ startOnTick: undefined,
1854
+ endOnTick: undefined,
1855
+ },
1856
+ series: [],
1857
+ };
1858
+
1859
+ const $ = cheerio.load(renderComponent('chart', params));
1860
+ const configScript = $(`script[data-highcharts-config--${params.id}]`).html();
1861
+
1862
+ const config = JSON.parse(configScript);
1863
+
1864
+ expect(config.yAxis.min).toBeUndefined();
1865
+ expect(config.yAxis.max).toBeUndefined();
1866
+ expect(config.yAxis.startOnTick).toBeUndefined();
1867
+ expect(config.yAxis.endOnTick).toBeUndefined();
1868
+ });
1869
+ });
1870
+ });
1199
1871
  });
1200
1872
 
1201
1873
  describe('FOR: Column Range Chart', () => {
1202
- describe('GIVEN: Params: Required', () => {
1874
+ describe('GIVEN: Params: required', () => {
1203
1875
  describe('WHEN: required params are provided', () => {
1204
1876
  const $ = cheerio.load(renderComponent('chart', EXAMPLE_COLUMN_RANGE_CHART_PARAMS));
1205
- const configScript = $(`script[data-highcharts-config--uuid]`).html();
1877
+ const configScript = $(`script[data-highcharts-config--column-range-chart-123]`).html();
1206
1878
 
1207
1879
  test('THEN: it passes jest-axe accessibility checks', async () => {
1208
1880
  const results = await axe($.html());
@@ -1216,7 +1888,7 @@ describe('Macro: Chart', () => {
1216
1888
  expect(baseChart.attr('data-highcharts-title')).toBe(
1217
1889
  'Food stores showed a strong rise on the month, while non-food stores fell',
1218
1890
  );
1219
- expect(baseChart.attr('data-highcharts-id')).toBe('uuid');
1891
+ expect(baseChart.attr('data-highcharts-id')).toBe('column-range-chart-123');
1220
1892
  });
1221
1893
 
1222
1894
  test('THEN: it includes columnrange and scatter series types', () => {
@@ -1225,10 +1897,79 @@ describe('Macro: Chart', () => {
1225
1897
  });
1226
1898
  });
1227
1899
  });
1900
+
1901
+ describe('GIVEN: Params: yAxis', () => {
1902
+ describe('WHEN: yAxis min and max are provided', () => {
1903
+ test('THEN: yAxis min and max are included in config', () => {
1904
+ const params = {
1905
+ id: 'test-chart',
1906
+ title: 'Test Chart',
1907
+ xAxis: {
1908
+ title: 'X Axis Title',
1909
+ categories: ['A', 'B', 'C'],
1910
+ type: 'linear',
1911
+ labelFormat: '{value}',
1912
+ },
1913
+ chartType: 'columnrange',
1914
+ yAxis: {
1915
+ title: 'Y Axis Title',
1916
+ labelFormat: '{value}',
1917
+ min: 0,
1918
+ max: 100,
1919
+ startOnTick: false,
1920
+ endOnTick: true,
1921
+ },
1922
+ series: [],
1923
+ };
1924
+
1925
+ const $ = cheerio.load(renderComponent('chart', params));
1926
+ const configScript = $(`script[data-highcharts-config--${params.id}]`).html();
1927
+
1928
+ expect(configScript).toContain('"min":0');
1929
+ expect(configScript).toContain('"max":100');
1930
+ expect(configScript).toContain('"startOnTick":false');
1931
+ expect(configScript).toContain('"endOnTick":true');
1932
+ });
1933
+ });
1934
+ describe('WHEN: yAxis min and max are not provided', () => {
1935
+ test('THEN: yAxis min and max are not included in config', () => {
1936
+ const params = {
1937
+ id: 'test-chart',
1938
+ title: 'Test Chart',
1939
+ xAxis: {
1940
+ title: 'X Axis Title',
1941
+ categories: ['A', 'B', 'C'],
1942
+ type: 'linear',
1943
+ labelFormat: '{value}',
1944
+ },
1945
+ chartType: 'columnrange',
1946
+ yAxis: {
1947
+ title: 'Y Axis Title',
1948
+ labelFormat: '{value}',
1949
+ min: undefined,
1950
+ max: undefined,
1951
+ startOnTick: undefined,
1952
+ endOnTick: undefined,
1953
+ },
1954
+ series: [],
1955
+ };
1956
+
1957
+ const $ = cheerio.load(renderComponent('chart', params));
1958
+ const configScript = $(`script[data-highcharts-config--${params.id}]`).html();
1959
+
1960
+ const config = JSON.parse(configScript);
1961
+
1962
+ expect(config.yAxis.min).toBeUndefined();
1963
+ expect(config.yAxis.max).toBeUndefined();
1964
+ expect(config.yAxis.startOnTick).toBeUndefined();
1965
+ expect(config.yAxis.endOnTick).toBeUndefined();
1966
+ });
1967
+ });
1968
+ });
1228
1969
  });
1229
1970
 
1230
1971
  describe('FOR: Invalid Chart', () => {
1231
- describe('GIVEN: Invalid chart type', () => {
1972
+ describe('GIVEN: Params: chartType', () => {
1232
1973
  describe('WHEN: an invalid chart type is provided', () => {
1233
1974
  const $ = cheerio.load(renderComponent('chart', EXAMPLE_INVALID_CHART_PARAMS));
1234
1975
 
@@ -1254,7 +1995,7 @@ describe('Macro: Chart', () => {
1254
1995
  });
1255
1996
 
1256
1997
  test('THEN: it still renders the description', () => {
1257
- expect($('.ons-u-vh').text()).toBe('A detailed description');
1998
+ expect($('#chart-audio-description-invalid-chart-123').text()).toBe('A detailed description');
1258
1999
  });
1259
2000
 
1260
2001
  test('THEN: it still renders the caption', () => {
@@ -1268,443 +2009,240 @@ describe('Macro: Chart', () => {
1268
2009
  });
1269
2010
  });
1270
2011
 
1271
- describe('FOR: Line chart with range annotation on the x axis', () => {
1272
- describe('GIVEN: Params: Range annotations', () => {
1273
- describe('WHEN: range annotations params are provided', () => {
1274
- const $ = cheerio.load(renderComponent('chart', EXAMPLE_LINE_CHART_WITH_RANGE_ANNOTATION_ON_X_AXIS_PARAMS));
2012
+ describe('FOR: Iframe Chart', () => {
2013
+ describe('GIVEN: Params: required', () => {
2014
+ describe('WHEN: iframeUrl param is provided', () => {
2015
+ const $ = cheerio.load(renderComponent('chart', EXAMPLE_IFRAME_CHART_PARAMS));
1275
2016
 
1276
2017
  test('THEN: it passes jest-axe checks', async () => {
1277
2018
  const results = await axe($.html());
1278
2019
  expect(results).toHaveNoViolations();
1279
2020
  });
1280
2021
 
1281
- test('THEN: it includes the range annotations JSON config', () => {
1282
- const configScript = $(`script[data-highcharts-range-annotations--line-chart-range-annotations-x-axis-123]`).html();
1283
- expect(configScript).toContain('"text":"A test x axis range annotation"');
1284
- expect(configScript).toContain('"range":{"axisValue1":10,"axisValue2":15}');
1285
- expect(configScript).toContain('"axis":"x"');
1286
- expect(configScript).toContain('"labelOffsetX":150');
1287
- expect(configScript).toContain('"labelOffsetY":0');
2022
+ test('THEN: it renders the iframe', () => {
2023
+ expect($('.ons-chart__iframe-wrapper').length).toBe(1);
2024
+ });
2025
+
2026
+ test('THEN: the Highcharts config is not included', () => {
2027
+ const configScript = $(`script[data-highcharts-config--iframe-chart-123]`).html();
2028
+ expect(configScript).toBeNull();
1288
2029
  });
1289
2030
  });
1290
2031
  });
1291
- });
1292
2032
 
1293
- describe('FOR: Line chart with range annotation on the y axis with label width', () => {
1294
- describe('GIVEN: Params: Range annotations', () => {
1295
- describe('WHEN: range annotations params are provided', () => {
2033
+ describe('GIVEN: Params: theme', () => {
2034
+ describe('WHEN: theme is provided', () => {
1296
2035
  const $ = cheerio.load(
1297
- renderComponent('chart', EXAMPLE_LINE_CHART_WITH_RANGE_ANNOTATION_ON_Y_AXIS_WITH_LABEL_WIDTH_PARAMS),
2036
+ renderComponent('chart', {
2037
+ ...EXAMPLE_IFRAME_CHART_PARAMS,
2038
+ theme: 'secondary',
2039
+ }),
1298
2040
  );
1299
2041
 
1300
- test('THEN: it passes jest-axe checks', async () => {
1301
- const results = await axe($.html());
1302
- expect(results).toHaveNoViolations();
1303
- });
1304
-
1305
- test('THEN: it includes the range annotations JSON config', () => {
1306
- const configScript = $(`script[data-highcharts-range-annotations--line-chart-range-annotations-y-axis-123]`).html();
1307
- expect(configScript).toContain('"text":"A test y axis range annotation with a label width of 250px"');
1308
- expect(configScript).toContain('"axis":"y"');
1309
- expect(configScript).toContain('"labelWidth":250');
2042
+ test('THEN: the theme parameter is ignored', () => {
2043
+ expect($('[data-highcharts-theme]').length).toBe(0);
1310
2044
  });
1311
2045
  });
1312
2046
  });
1313
- });
1314
-
1315
- describe('FOR: Line chart with range annotation with the label inside', () => {
1316
- describe('GIVEN: Params: Range annotations', () => {
1317
- describe('WHEN: range annotations params are provided', () => {
1318
- const $ = cheerio.load(renderComponent('chart', EXAMPLE_LINE_CHART_WITH_RANGE_ANNOTATION_WITH_LABEL_INSIDE_PARAMS));
1319
2047
 
1320
- test('THEN: it passes jest-axe checks', async () => {
1321
- const results = await axe($.html());
1322
- expect(results).toHaveNoViolations();
1323
- });
2048
+ describe('GIVEN: Params: percentageHeightDesktop', () => {
2049
+ describe('WHEN: percentageHeightDesktop is provided', () => {
2050
+ const $ = cheerio.load(
2051
+ renderComponent('chart', {
2052
+ ...EXAMPLE_IFRAME_CHART_PARAMS,
2053
+ percentageHeightDesktop: 50,
2054
+ }),
2055
+ );
1324
2056
 
1325
- test('THEN: it includes the range annotations JSON config', () => {
1326
- const configScript = $(
1327
- `script[data-highcharts-range-annotations--line-chart-range-annotations-label-inside-123]`,
1328
- ).html();
1329
- expect(configScript).toContain('"text":"A test y axis range annotation with the label inside"');
1330
- expect(configScript).toContain('"axis":"y"');
1331
- expect(configScript).toContain('"labelInside":true');
2057
+ test('THEN: the percentageHeightDesktop parameter is ignored', () => {
2058
+ expect($('[data-highcharts-percentage-height-desktop]').length).toBe(0);
1332
2059
  });
1333
2060
  });
1334
2061
  });
1335
- });
1336
-
1337
- describe('FOR: Line chart with reference line annotations', () => {
1338
- describe('GIVEN: Params: Reference line annotations', () => {
1339
- describe('WHEN: reference line annotations params are provided', () => {
1340
- const $ = cheerio.load(renderComponent('chart', EXAMPLE_LINE_CHART_WITH_REFERENCE_LINE_ANNOTATIONS_PARAMS));
1341
2062
 
1342
- test('THEN: it passes jest-axe checks', async () => {
1343
- const results = await axe($.html());
1344
- expect(results).toHaveNoViolations();
1345
- });
2063
+ describe('GIVEN: Params: percentageHeightMobile', () => {
2064
+ describe('WHEN: percentageHeightMobile is provided', () => {
2065
+ const $ = cheerio.load(
2066
+ renderComponent('chart', {
2067
+ ...EXAMPLE_IFRAME_CHART_PARAMS,
2068
+ percentageHeightMobile: 10,
2069
+ }),
2070
+ );
1346
2071
 
1347
- test('THEN: it includes the reference line annotations JSON config', () => {
1348
- const configScript = $(
1349
- `script[data-highcharts-reference-line-annotations--line-chart-reference-line-annotations-123]`,
1350
- ).html();
1351
- expect(configScript).toContain('"text":"A test x axis reference line annotation"');
1352
- expect(configScript).toContain('"value":34');
1353
- expect(configScript).toContain('"axis":"x"');
1354
- expect(configScript).toContain('"text":"A test y axis reference line annotation"');
1355
- expect(configScript).toContain('"value":12');
1356
- expect(configScript).toContain('"axis":"y"');
1357
- expect(configScript).toContain('"labelWidth":100');
2072
+ test('THEN: the percentageHeightMobile parameter is ignored', () => {
2073
+ expect($('[data-highcharts-percentage-height-mobile]').length).toBe(0);
1358
2074
  });
1359
2075
  });
1360
2076
  });
1361
- });
1362
-
1363
- describe('FOR: Line chart with mixed annotation types', () => {
1364
- describe('GIVEN: Params: Mixed annotations', () => {
1365
- describe('WHEN: mixed annotations params are provided', () => {
1366
- const $ = cheerio.load(renderComponent('chart', EXAMPLE_LINE_CHART_WITH_MIXED_ANNOTATION_TYPES_PARAMS));
1367
2077
 
1368
- test('THEN: it passes jest-axe checks', async () => {
1369
- const results = await axe($.html());
1370
- expect(results).toHaveNoViolations();
1371
- });
2078
+ describe('GIVEN: Params: tickInterval', () => {
2079
+ describe('WHEN: tickIntervalDesktop and tickIntervalMobile are provided', () => {
2080
+ const $ = cheerio.load(
2081
+ renderComponent('chart', {
2082
+ ...EXAMPLE_IFRAME_CHART_PARAMS,
2083
+ xAxis: { tickIntervalDesktop: 10, tickIntervalMobile: 5 },
2084
+ yAxis: { tickIntervalDesktop: 10, tickIntervalMobile: 5 },
2085
+ }),
2086
+ );
1372
2087
 
1373
- test('THEN: it renders the footnotes sequentially', () => {
1374
- expect($('.ons-chart__annotations-footnotes').text()).toContain('1');
1375
- expect($('.ons-chart__annotations-footnotes').text()).toContain('A test point annotation');
1376
- expect($('.ons-chart__annotations-footnotes').text()).toContain('2');
1377
- expect($('.ons-chart__annotations-footnotes').text()).toContain('A test x axis range annotation');
1378
- expect($('.ons-chart__annotations-footnotes').text()).toContain('3');
1379
- expect($('.ons-chart__annotations-footnotes').text()).toContain('A test y axis range annotation with the label inside');
1380
- expect($('.ons-chart__annotations-footnotes').text()).toContain('4');
1381
- expect($('.ons-chart__annotations-footnotes').text()).toContain('A test x axis reference line annotation');
1382
- expect($('.ons-chart__annotations-footnotes').text()).toContain('5');
1383
- expect($('.ons-chart__annotations-footnotes').text()).toContain('A test y axis reference line annotation');
2088
+ test('THEN: the tickIntervalDesktop and tickIntervalMobile parameters are ignored', () => {
2089
+ expect($('[data-highcharts-x-axis-tick-interval-desktop]').length).toBe(0);
2090
+ expect($('[data-highcharts-x-axis-tick-interval-mobile]').length).toBe(0);
2091
+ expect($('[data-highcharts-y-axis-tick-interval-desktop]').length).toBe(0);
2092
+ expect($('[data-highcharts-y-axis-tick-interval-mobile]').length).toBe(0);
1384
2093
  });
1385
2094
  });
1386
2095
  });
1387
- });
1388
2096
 
1389
- describe('FOR: Axis Min, Max, startOnTick, endOnTick', () => {
1390
- const BASE_PARAMS = {
1391
- id: 'test-chart',
1392
- title: 'Test Chart',
1393
- xAxis: {
1394
- title: 'X Axis Title',
1395
- categories: ['A', 'B', 'C'],
1396
- type: 'linear',
1397
- labelFormat: '{value}',
1398
- },
1399
- yAxis: {
1400
- title: 'Y Axis Title',
1401
- labelFormat: '{value}',
1402
- },
1403
- series: [],
1404
- };
1405
-
1406
- describe('GIVEN: chartType supports xAxis min/max (bar, scatter)', () => {
1407
- test('THEN: xAxis min and max are included in config when provided', () => {
1408
- const params = {
1409
- ...BASE_PARAMS,
1410
- chartType: 'scatter',
1411
- xAxis: {
1412
- ...BASE_PARAMS.xAxis,
1413
- min: 1,
1414
- max: 10,
1415
- startOnTick: true,
1416
- endOnTick: false,
1417
- },
1418
- };
1419
-
1420
- const $ = cheerio.load(renderComponent('chart', params));
1421
- const configScript = $(`script[data-highcharts-config--${params.id}]`).html();
1422
-
1423
- expect(configScript).toContain('"min":1');
1424
- expect(configScript).toContain('"max":10');
1425
- expect(configScript).toContain('"startOnTick":true');
1426
- expect(configScript).toContain('"endOnTick":false');
1427
- });
1428
-
1429
- test('THEN: xAxis min and max are NOT included if not defined', () => {
1430
- const params = {
1431
- ...BASE_PARAMS,
1432
- chartType: 'scatter',
1433
- xAxis: {
1434
- ...BASE_PARAMS.xAxis,
1435
- min: undefined,
1436
- max: undefined,
1437
- startOnTick: undefined,
1438
- endOnTick: undefined,
1439
- },
1440
- };
1441
-
1442
- const $ = cheerio.load(renderComponent('chart', params));
1443
- const configScript = $(`script[data-highcharts-config--${params.id}]`).html();
1444
-
1445
- const config = JSON.parse(configScript);
2097
+ describe('GIVEN: Params: estimateLineLabel', () => {
2098
+ describe('WHEN: estimateLineLabel is provided', () => {
2099
+ const $ = cheerio.load(
2100
+ renderComponent('chart', {
2101
+ ...EXAMPLE_IFRAME_CHART_PARAMS,
2102
+ estimateLineLabel: 'Estimated value',
2103
+ }),
2104
+ );
1446
2105
 
1447
- expect(config.xAxis.min).toBeUndefined();
1448
- expect(config.xAxis.max).toBeUndefined();
1449
- expect(config.xAxis.startOnTick).toBeUndefined();
1450
- expect(config.xAxis.endOnTick).toBeUndefined();
2106
+ test('THEN: the estimateLineLabel parameter is ignored', () => {
2107
+ expect($('[data-highcharts-estimate-line-label]').length).toBe(0);
2108
+ });
1451
2109
  });
1452
2110
  });
1453
2111
 
1454
- describe('GIVEN: chartType supports yAxis min/max (line, bar, column, scatter, area, columnrange, boxplot)', () => {
1455
- test('THEN: yAxis min and max are included in config when provided', () => {
1456
- const params = {
1457
- ...BASE_PARAMS,
1458
- chartType: 'line',
1459
- yAxis: {
1460
- ...BASE_PARAMS.yAxis,
1461
- min: 0,
1462
- max: 100,
1463
- startOnTick: false,
1464
- endOnTick: true,
1465
- },
1466
- };
1467
-
1468
- const $ = cheerio.load(renderComponent('chart', params));
1469
- const configScript = $(`script[data-highcharts-config--${params.id}]`).html();
1470
-
1471
- expect(configScript).toContain('"min":0');
1472
- expect(configScript).toContain('"max":100');
1473
- expect(configScript).toContain('"startOnTick":false');
1474
- expect(configScript).toContain('"endOnTick":true');
1475
- });
1476
-
1477
- test('THEN: yAxis min and max are NOT included if not defined', () => {
1478
- const params = {
1479
- ...BASE_PARAMS,
1480
- chartType: 'line',
1481
- yAxis: {
1482
- ...BASE_PARAMS.yAxis,
1483
- min: undefined,
1484
- max: undefined,
1485
- startOnTick: undefined,
1486
- endOnTick: undefined,
1487
- },
1488
- };
1489
-
1490
- const $ = cheerio.load(renderComponent('chart', params));
1491
- const configScript = $(`script[data-highcharts-config--${params.id}]`).html();
1492
-
1493
- const config = JSON.parse(configScript);
2112
+ describe('GIVEN: Params: uncertaintyRangeLabel', () => {
2113
+ describe('WHEN: uncertaintyRangeLabel is provided', () => {
2114
+ const $ = cheerio.load(
2115
+ renderComponent('chart', {
2116
+ ...EXAMPLE_IFRAME_CHART_PARAMS,
2117
+ uncertaintyRangeLabel: '95% Confidence Interval',
2118
+ }),
2119
+ );
1494
2120
 
1495
- expect(config.yAxis.min).toBeUndefined();
1496
- expect(config.yAxis.max).toBeUndefined();
1497
- expect(config.yAxis.startOnTick).toBeUndefined();
1498
- expect(config.yAxis.endOnTick).toBeUndefined();
2121
+ test('THEN: the uncertaintyRangeLabel parameter is ignored', () => {
2122
+ expect($('[data-highcharts-uncertainty-range-label]').length).toBe(0);
2123
+ });
1499
2124
  });
1500
2125
  });
1501
2126
 
1502
- describe('GIVEN: chartType does NOT support axis min/max', () => {
1503
- test('THEN: xAxis min and max are ignored', () => {
1504
- const params = {
1505
- ...BASE_PARAMS,
1506
- chartType: 'line',
1507
- xAxis: {
1508
- ...BASE_PARAMS.xAxis,
1509
- min: 1,
1510
- max: 10,
1511
- startOnTick: true,
1512
- endOnTick: true,
1513
- },
1514
- };
1515
-
1516
- const $ = cheerio.load(renderComponent('chart', params));
1517
- const configScript = $(`script[data-highcharts-config--${params.id}]`).html();
2127
+ describe('GIVEN: Params: customReferenceLineValue', () => {
2128
+ describe('WHEN: customReferenceLineValue is provided', () => {
2129
+ const $ = cheerio.load(
2130
+ renderComponent('chart', {
2131
+ ...EXAMPLE_IFRAME_CHART_PARAMS,
2132
+ yAxis: { customReferenceLineValue: 10 },
2133
+ }),
2134
+ );
1518
2135
 
1519
- expect(configScript).not.toContain('"min":1');
1520
- expect(configScript).not.toContain('"max":10');
1521
- expect(configScript).not.toContain('"startOnTick":true');
1522
- expect(configScript).not.toContain('"endOnTick":true');
2136
+ test('THEN: the customReferenceLineValue parameter is ignored', () => {
2137
+ expect($('[data-highcharts-custom-reference-line-value]').length).toBe(0);
2138
+ });
1523
2139
  });
1524
2140
  });
1525
- });
1526
-
1527
- describe('FOR: Iframe chart', () => {
1528
- describe('GIVEN: Params: Iframe chart', () => {
1529
- describe('WHEN: an iframe url param is provided', () => {
1530
- const $ = cheerio.load(renderComponent('chart', EXAMPLE_IFRAME_CHART_PARAMS));
1531
-
1532
- test('THEN: it passes jest-axe checks', async () => {
1533
- const results = await axe($.html());
1534
- expect(results).toHaveNoViolations();
1535
- });
1536
2141
 
1537
- test('THEN: it renders the iframe', () => {
1538
- expect($('.ons-chart__iframe-wrapper').length).toBe(1);
1539
- });
1540
-
1541
- test('THEN: it includes the iframe title as a data attribute', () => {
1542
- const iframe = $('.ons-chart__iframe-wrapper');
1543
- expect(iframe.attr('data-title')).toBe(EXAMPLE_IFRAME_CHART_PARAMS.title);
1544
- });
1545
-
1546
- test('THEN: the theme parameter is ignored', () => {
1547
- const $ = cheerio.load(
1548
- renderComponent('chart', {
1549
- ...EXAMPLE_IFRAME_CHART_PARAMS,
1550
- theme: 'secondary',
1551
- }),
1552
- );
1553
-
1554
- expect($('[data-highcharts-theme]').length).toBe(0);
1555
- });
1556
-
1557
- test('THEN: the percentageHeightDesktop and percentageHeightMobile parameters are ignored', () => {
1558
- const $ = cheerio.load(
1559
- renderComponent('chart', {
1560
- ...EXAMPLE_IFRAME_CHART_PARAMS,
1561
- percentageHeightDesktop: 50,
1562
- percentageHeightMobile: 10,
1563
- }),
1564
- );
2142
+ describe('GIVEN: Params: chartType', () => {
2143
+ describe('WHEN: chartType is boxplot and legend params are provided', () => {
2144
+ const $ = cheerio.load(
2145
+ renderComponent('chart', {
2146
+ ...EXAMPLE_IFRAME_CHART_PARAMS,
2147
+ chartType: 'boxplot',
2148
+ legend: true,
2149
+ estimateLineLabel: 'Estimated value',
2150
+ uncertaintyRangeLabel: '95% Confidence Interval',
2151
+ }),
2152
+ );
1565
2153
 
1566
- expect($('[data-highcharts-percentage-height-desktop]').length).toBe(0);
1567
- expect($('[data-highcharts-percentage-height-mobile]').length).toBe(0);
2154
+ test('THEN: the boxplot legend is not rendered', () => {
2155
+ expect($('.ons-chart__boxplot-legend').length).toBe(0);
1568
2156
  });
2157
+ });
2158
+ });
1569
2159
 
1570
- test('THEN: the tickIntervalDesktop and tickIntervalMobile parameters are ignored', () => {
1571
- const $ = cheerio.load(
1572
- renderComponent('chart', {
1573
- ...EXAMPLE_IFRAME_CHART_PARAMS,
1574
- xAxis: {
1575
- tickIntervalDesktop: 10,
1576
- tickIntervalMobile: 5,
1577
- },
1578
- yAxis: {
1579
- tickIntervalDesktop: 10,
1580
- tickIntervalMobile: 5,
1581
- },
1582
- }),
1583
- );
2160
+ describe('GIVEN: Params: invalidChartType', () => {
2161
+ describe('WHEN: an invalid chart type is provided', () => {
2162
+ const $ = cheerio.load(
2163
+ renderComponent('chart', {
2164
+ ...EXAMPLE_IFRAME_CHART_PARAMS,
2165
+ chartType: 'foobar',
2166
+ }),
2167
+ );
1584
2168
 
1585
- expect($('[data-highcharts-x-axis-tick-interval-desktop]').length).toBe(0);
1586
- expect($('[data-highcharts-x-axis-tick-interval-mobile]').length).toBe(0);
1587
- expect($('[data-highcharts-y-axis-tick-interval-desktop]').length).toBe(0);
1588
- expect($('[data-highcharts-y-axis-tick-interval-mobile]').length).toBe(0);
2169
+ test('THEN: the invalid chart type is ignored', () => {
2170
+ expect($('[data-invalid-chart-type]').length).toBe(0);
1589
2171
  });
2172
+ });
2173
+ });
1590
2174
 
1591
- test('THEN: the tickIntervalDesktop and tickIntervalMobile parameters are ignored', () => {
1592
- const $ = cheerio.load(
1593
- renderComponent('chart', {
1594
- ...EXAMPLE_IFRAME_CHART_PARAMS,
1595
- estimateLineLabel: 'Estimated value',
1596
- uncertaintyRangeLabel: '95% Confidence Interval',
1597
- }),
1598
- );
2175
+ describe('GIVEN: Params: annotations', () => {
2176
+ describe('WHEN: annotations, rangeAnnotations and referenceLineAnnotations are provided', () => {
2177
+ const $ = cheerio.load(
2178
+ renderComponent('chart', {
2179
+ ...EXAMPLE_IFRAME_CHART_PARAMS,
2180
+ annotations: [{ text: 'A test point annotation', point: { x: 2, y: 3 } }],
2181
+ rangeAnnotations: [{ text: 'Range annotation', range: { axisValue1: 10, axisValue2: 15 }, axis: 'x' }],
2182
+ referenceLineAnnotations: [{ text: 'Reference line', value: 34, axis: 'x' }],
2183
+ }),
2184
+ );
1599
2185
 
1600
- expect($('[data-highcharts-estimate-line-label]').length).toBe(0);
1601
- expect($('[data-highcharts-uncertainty-range-label]').length).toBe(0);
2186
+ test('THEN: annotations footnotes are not rendered', () => {
2187
+ expect($('[data-annotations-footnotes]').length).toBe(0);
1602
2188
  });
1603
2189
 
1604
- test('THEN: the customReferenceLineValue parameter is ignored', () => {
1605
- const $ = cheerio.load(
1606
- renderComponent('chart', {
1607
- ...EXAMPLE_IFRAME_CHART_PARAMS,
1608
- yAxis: {
1609
- customReferenceLineValue: 10,
1610
- },
1611
- }),
1612
- );
1613
-
1614
- expect($('[data-highcharts-custom-reference-line-value]').length).toBe(0);
2190
+ test('THEN: annotation scripts are not rendered', () => {
2191
+ expect($('[data-highcharts-annotations--iframe-chart-123]').length).toBe(0);
2192
+ expect($('[data-highcharts-range-annotations--iframe-chart-123]').length).toBe(0);
2193
+ expect($('[data-highcharts-reference-line-annotations--iframe-chart-123]').length).toBe(0);
1615
2194
  });
2195
+ });
2196
+ });
1616
2197
 
1617
- test('THEN: the legend for boxplot charts is not rendered', () => {
1618
- const $ = cheerio.load(
1619
- renderComponent('chart', {
1620
- ...EXAMPLE_IFRAME_CHART_PARAMS,
1621
- chartType: 'boxplot',
1622
- legend: true,
1623
- estimateLineLabel: 'Estimated value',
1624
- uncertaintyRangeLabel: '95% Confidence Interval',
1625
- }),
1626
- );
1627
-
1628
- expect($('.ons-chart__boxplot-legend').length).toBe(0);
1629
- });
2198
+ describe('GIVEN: Params: iframeAspectRatio', () => {
2199
+ describe('WHEN: iframeAspectRatio is not set', () => {
2200
+ const $ = cheerio.load(renderComponent('chart', EXAMPLE_IFRAME_CHART_PARAMS));
1630
2201
 
1631
- test('THEN: the Highcharts config is not included', () => {
1632
- const configScript = $(`script[data-highcharts-config--iframe-chart-123]`).html();
1633
- expect(configScript).toBeNull();
2202
+ test('THEN: it defaults to 16-9', () => {
2203
+ expect($('.ons-chart__iframe').hasClass('ons-chart__iframe--16-9')).toBe(true);
1634
2204
  });
2205
+ });
1635
2206
 
1636
- test('THEN: the annotations footnotes and scripts are not rendered', () => {
1637
- const $ = cheerio.load(
1638
- renderComponent('chart', {
1639
- ...EXAMPLE_IFRAME_CHART_PARAMS,
1640
- annotations: [
1641
- {
1642
- text: 'A test point annotation',
1643
- point: { x: 2, y: 3 },
1644
- labelOffsetX: 10,
1645
- labelOffsetY: -50,
1646
- },
1647
- ],
1648
- rangeAnnotations: [
1649
- {
1650
- text: 'A test x axis range annotation',
1651
- range: { axisValue1: 10, axisValue2: 15 },
1652
- axis: 'x',
1653
- labelOffsetX: 150,
1654
- labelOffsetY: 0,
1655
- },
1656
- {
1657
- text: 'A test y axis range annotation with the label inside',
1658
- range: { axisValue1: 5, axisValue2: 10 },
1659
- axis: 'y',
1660
- labelInside: true,
1661
- labelWidth: 250,
1662
- },
1663
- ],
1664
- referenceLineAnnotations: [
1665
- {
1666
- text: 'A test x axis reference line annotation',
1667
- value: 34,
1668
- axis: 'x',
1669
- },
1670
- {
1671
- text: 'A test y axis reference line annotation',
1672
- value: 12,
1673
- axis: 'y',
1674
- labelWidth: 100,
1675
- },
1676
- ],
1677
- }),
1678
- );
2207
+ describe('WHEN: iframeAspectRatio is unsupported', () => {
2208
+ const $ = cheerio.load(
2209
+ renderComponent('chart', {
2210
+ ...EXAMPLE_IFRAME_CHART_PARAMS,
2211
+ iframeAspectRatio: '16-10',
2212
+ }),
2213
+ );
1679
2214
 
1680
- expect($('[data-annotations-footnotes]').length).toBe(0);
1681
- expect($('[data-highcharts-annotations--iframe-chart-123]').length).toBe(0);
1682
- expect($('[data-highcharts-range-annotations--iframe-chart-123]').length).toBe(0);
1683
- expect($('[data-highcharts-reference-line-annotations--iframe-chart-123]').length).toBe(0);
2215
+ test('THEN: it defaults to 16-9', () => {
2216
+ expect($('.ons-chart__iframe').hasClass('ons-chart__iframe--16-9')).toBe(true);
1684
2217
  });
2218
+ });
1685
2219
 
1686
- test('THEN: invalid chart type is ignored', () => {
1687
- const $ = cheerio.load(
1688
- renderComponent('chart', {
1689
- ...EXAMPLE_IFRAME_CHART_PARAMS,
1690
- chartType: 'foobar',
1691
- }),
1692
- );
2220
+ describe('WHEN: iframeAspectRatio is supported', () => {
2221
+ const aspectRatio = '21-9';
2222
+ const $ = cheerio.load(
2223
+ renderComponent('chart', {
2224
+ ...EXAMPLE_IFRAME_CHART_PARAMS,
2225
+ iframeAspectRatio: aspectRatio,
2226
+ }),
2227
+ );
1693
2228
 
1694
- expect($('[data-invalid-chart-type]').length).toBe(0);
2229
+ test('THEN: it applies the aspect ratio class', () => {
2230
+ expect($('.ons-chart__iframe').hasClass(`ons-chart__iframe--${aspectRatio}`)).toBe(true);
1695
2231
  });
1696
2232
  });
2233
+ });
1697
2234
 
1698
- describe('WHEN: Params: fallbackImageUrl is set', () => {
2235
+ describe('GIVEN: Params: fallbackImageUrl', () => {
2236
+ describe('WHEN: fallbackImageUrl is provided', () => {
1699
2237
  const $ = cheerio.load(
1700
2238
  renderComponent('chart', {
1701
2239
  ...EXAMPLE_IFRAME_CHART_PARAMS,
1702
2240
  fallbackImageUrl: '/img/small/line-chart-screenshot.png',
1703
2241
  }),
1704
2242
  );
1705
- const iframe = $(`.ons-chart__iframe-wrapper`);
1706
- test('THEN: the iframe is hidden when JavaScript is disabled', () => {
1707
- expect(iframe.attr('class')).toContain('ons-chart__non-js-hide');
2243
+
2244
+ test('THEN: the iframe wrapper is hidden when JavaScript is disabled', () => {
2245
+ expect($('.ons-chart__iframe-wrapper').attr('class')).toContain('ons-chart__non-js-hide');
1708
2246
  });
1709
2247
  });
1710
2248
  });