-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChart.test.tsx
More file actions
818 lines (712 loc) · 29.9 KB
/
Chart.test.tsx
File metadata and controls
818 lines (712 loc) · 29.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
import { test, expect } from '@playwright/experimental-ct-react';
import AxeBuilder from '@axe-core/playwright';
import {
Sparkline,
SparklineWithColor,
FullChart,
LinearCurve,
WithFadeLeft,
WithFadeLeftCustom,
CustomAriaLabel,
EmptyData,
SingleDataPoint,
NoAnimation,
CustomStrokeWidth,
WithFormatters,
SimpleTooltip,
DetailedTooltipExplicit,
CustomTooltip,
ScatterBasic,
ScatterMultiSeries,
SplitBasic,
SplitDetailed,
BarListRanked,
WaterfallBasic,
SankeyBasic,
FunnelBasic,
BarBasic,
} from './Chart.test-stories';
const axeConfig = {
rules: {
'landmark-one-main': { enabled: false },
'page-has-heading-one': { enabled: false },
region: { enabled: false },
},
};
// ---------------------------------------------------------------------------
// Accessibility
// ---------------------------------------------------------------------------
test.describe('Chart accessibility', () => {
test('sparkline has no accessibility violations', async ({ mount, page }) => {
await mount(<Sparkline />);
const results = await new AxeBuilder({ page })
.options(axeConfig)
.analyze();
expect(results.violations).toEqual([]);
});
test('full chart has no accessibility violations', async ({
mount,
page,
}) => {
await mount(<FullChart />);
const results = await new AxeBuilder({ page })
.options(axeConfig)
.analyze();
expect(results.violations).toEqual([]);
});
test('svg has role="img" and aria-label', async ({ mount, page }) => {
await mount(<Sparkline />);
const svg = page.locator('[data-testid="chart"] svg');
await expect(svg).toHaveAttribute('role', 'img');
await expect(svg).toHaveAttribute('aria-label');
});
test('custom aria-label overrides auto-generated one', async ({
mount,
page,
}) => {
await mount(<CustomAriaLabel />);
const svg = page.locator('[data-testid="chart"] svg');
await expect(svg).toHaveAttribute('aria-label', 'Weekly revenue trend');
});
test('svg contains a desc element', async ({ mount, page }) => {
await mount(<Sparkline />);
const desc = page.locator('[data-testid="chart"] svg desc');
await expect(desc).toBeAttached();
const text = await desc.textContent();
expect(text).toContain('data points');
});
});
// ---------------------------------------------------------------------------
// Rendering
// ---------------------------------------------------------------------------
test.describe('Chart rendering', () => {
test('renders SVG with correct dimensions', async ({ mount, page }) => {
await mount(<Sparkline />);
const svg = page.locator('[data-testid="chart"] svg');
await expect(svg).toBeVisible();
const height = await svg.getAttribute('height');
expect(height).toBe('170');
});
test('renders path elements for series', async ({ mount, page }) => {
await mount(<FullChart />);
const paths = page.locator('[data-testid="chart"] svg path');
// 2 series with active + inactive paths + area fill paths
const count = await paths.count();
expect(count).toBeGreaterThanOrEqual(4);
});
test('sparkline renders paths', async ({ mount, page }) => {
await mount(<Sparkline />);
const paths = page.locator('[data-testid="chart"] svg path');
const count = await paths.count();
expect(count).toBeGreaterThanOrEqual(1);
});
test('empty data renders container but no SVG paths', async ({
mount,
page,
}) => {
await mount(<EmptyData />);
const container = page.locator('[data-testid="chart"]');
await expect(container).toBeVisible();
// With no data/width, SVG may not render paths
const paths = page.locator('[data-testid="chart"] svg path');
const count = await paths.count();
expect(count).toBeLessThanOrEqual(0);
});
test('single data point renders without errors', async ({
mount,
page,
}) => {
await mount(<SingleDataPoint />);
const svg = page.locator('[data-testid="chart"] svg');
await expect(svg).toBeVisible();
const paths = page.locator('[data-testid="chart"] svg path');
const count = await paths.count();
expect(count).toBeGreaterThanOrEqual(1);
});
});
// ---------------------------------------------------------------------------
// Curve types
// ---------------------------------------------------------------------------
test.describe('Chart curve types', () => {
test('monotone curve produces C commands in path', async ({
mount,
page,
}) => {
await mount(<Sparkline />);
const path = page.locator('[data-testid="chart"] svg path').first();
const d = await path.getAttribute('d');
expect(d).toContain('C');
});
test('linear curve produces only L commands in path', async ({
mount,
page,
}) => {
await mount(<LinearCurve />);
const path = page.locator('[data-testid="chart"] svg path').first();
const d = await path.getAttribute('d');
expect(d).toContain('L');
expect(d).not.toContain('C');
});
});
// ---------------------------------------------------------------------------
// Grid and axis
// ---------------------------------------------------------------------------
test.describe('Chart grid and axis', () => {
test('grid lines are rendered when grid=true', async ({ mount, page }) => {
await mount(<FullChart />);
// Grid lines are <line> elements with the gridLine class
const lines = page.locator('[data-testid="chart"] svg line');
const count = await lines.count();
// Should have grid lines + the cursor line
expect(count).toBeGreaterThanOrEqual(2);
});
test('x-axis labels appear when xKey is set', async ({ mount, page }) => {
await mount(<FullChart />);
// X labels are <text> elements containing day names
const monLabel = page.locator('[data-testid="chart"] svg text', {
hasText: 'Mon',
});
await expect(monLabel.first()).toBeVisible();
});
test('y-axis labels appear when grid=true', async ({ mount, page }) => {
await mount(<FullChart />);
// Y labels are <text> elements with numeric content
const textEls = page.locator('[data-testid="chart"] svg text');
const count = await textEls.count();
// Should have both x and y labels
expect(count).toBeGreaterThanOrEqual(3);
});
});
// ---------------------------------------------------------------------------
// Tooltip and hover
// ---------------------------------------------------------------------------
test.describe('Chart tooltip', () => {
test('tooltip is hidden by default', async ({ mount, page }) => {
await mount(<FullChart />);
const tooltip = page.locator('[data-testid="chart"] > div');
// Tooltip element exists but is display: none via inline style
await expect(tooltip).toBeAttached();
await expect(tooltip).toHaveCSS('display', 'none');
});
test('tooltip appears on hover', async ({ mount, page }) => {
await mount(<FullChart />);
const svg = page.locator('[data-testid="chart"] svg');
const box = await svg.boundingBox();
if (!box) throw new Error('SVG not visible');
// Hover in the middle of the chart
await page.mouse.move(box.x + box.width / 2, box.y + box.height / 2);
const tooltip = page.locator('[data-testid="chart"] > div');
// Wait for tooltip to become visible
await expect(tooltip).toBeVisible({ timeout: 2000 });
});
test('tooltip shows series labels', async ({ mount, page }) => {
await mount(<FullChart />);
const svg = page.locator('[data-testid="chart"] svg');
const box = await svg.boundingBox();
if (!box) throw new Error('SVG not visible');
await page.mouse.move(box.x + box.width / 2, box.y + box.height / 2);
// Should show both series labels
const tooltip = page.locator('[data-testid="chart"] > div');
await expect(tooltip).toBeVisible({ timeout: 2000 });
await expect(tooltip.locator('text=Incoming').or(tooltip.getByText('Incoming'))).toBeVisible();
await expect(tooltip.locator('text=Outgoing').or(tooltip.getByText('Outgoing'))).toBeVisible();
});
test('tooltip hides on mouse leave', async ({ mount, page }) => {
await mount(<FullChart />);
const svg = page.locator('[data-testid="chart"] svg');
const box = await svg.boundingBox();
if (!box) throw new Error('SVG not visible');
// Hover then leave
await page.mouse.move(box.x + box.width / 2, box.y + box.height / 2);
const tooltip = page.locator('[data-testid="chart"] > div');
await expect(tooltip).toBeVisible({ timeout: 2000 });
// Move mouse well below the chart to trigger mouseLeave
await page.mouse.move(box.x + box.width / 2, box.y + box.height + 100);
// Tooltip should hide (inline style.display = 'none')
await expect(tooltip).toHaveCSS('display', 'none', { timeout: 2000 });
});
test('cursor line appears on hover', async ({ mount, page }) => {
await mount(<FullChart />);
const svg = page.locator('[data-testid="chart"] svg');
const box = await svg.boundingBox();
if (!box) throw new Error('SVG not visible');
await page.mouse.move(box.x + box.width / 2, box.y + box.height / 2);
// Cursor line should be visible (style.display cleared)
const lines = page.locator('[data-testid="chart"] svg line');
const count = await lines.count();
let hasCursorVisible = false;
for (let i = 0; i < count; i++) {
const display = await lines.nth(i).evaluate(
(el) => (el as SVGElement).style.display,
);
if (display !== 'none') hasCursorVisible = true;
}
expect(hasCursorVisible).toBe(true);
});
test('hover dots appear on hover', async ({ mount, page }) => {
await mount(<FullChart />);
const svg = page.locator('[data-testid="chart"] svg');
const box = await svg.boundingBox();
if (!box) throw new Error('SVG not visible');
await page.mouse.move(box.x + box.width / 2, box.y + box.height / 2);
// Active dots (circles) should be visible
const dots = page.locator('[data-testid="chart"] svg circle');
const count = await dots.count();
expect(count).toBe(2); // Two series
for (let i = 0; i < count; i++) {
const display = await dots.nth(i).evaluate(
(el) => (el as SVGElement).style.display,
);
expect(display).not.toBe('none');
}
});
test('formatValue is applied in tooltip', async ({ mount, page }) => {
await mount(<WithFormatters />);
const svg = page.locator('[data-testid="chart"] svg');
const box = await svg.boundingBox();
if (!box) throw new Error('SVG not visible');
await page.mouse.move(box.x + box.width / 2, box.y + box.height / 2);
const tooltip = page.locator('[data-testid="chart"] > div');
await expect(tooltip).toBeVisible({ timeout: 2000 });
// Values should be formatted with $ prefix
const text = await tooltip.textContent();
expect(text).toContain('$');
});
});
// ---------------------------------------------------------------------------
// Tooltip variants
// ---------------------------------------------------------------------------
test.describe('Chart tooltip variants', () => {
test('tooltip="simple" shows only x-label, no series rows', async ({
mount,
page,
}) => {
await mount(<SimpleTooltip />);
const svg = page.locator('[data-testid="chart"] svg');
const box = await svg.boundingBox();
if (!box) throw new Error('SVG not visible');
await page.mouse.move(box.x + box.width / 2, box.y + box.height / 2);
const tooltip = page.locator('[data-testid="chart"] > div');
await expect(tooltip).toBeVisible({ timeout: 2000 });
const text = await tooltip.textContent();
// Should contain a date label (one of the x values)
expect(text).toBeTruthy();
});
test('tooltip="detailed" renders series rows (same as boolean true)', async ({
mount,
page,
}) => {
await mount(<DetailedTooltipExplicit />);
const svg = page.locator('[data-testid="chart"] svg');
const box = await svg.boundingBox();
if (!box) throw new Error('SVG not visible');
await page.mouse.move(box.x + box.width / 2, box.y + box.height / 2);
const tooltip = page.locator('[data-testid="chart"] > div');
await expect(tooltip).toBeVisible({ timeout: 2000 });
await expect(
tooltip.getByText('Incoming'),
).toBeVisible();
await expect(
tooltip.getByText('Outgoing'),
).toBeVisible();
});
test('tooltip render function receives datum and renders custom content', async ({
mount,
page,
}) => {
await mount(<CustomTooltip />);
const svg = page.locator('[data-testid="chart"] svg');
const box = await svg.boundingBox();
if (!box) throw new Error('SVG not visible');
await page.mouse.move(box.x + box.width / 2, box.y + box.height / 2);
const tooltip = page.locator('[data-testid="chart"] > div');
await expect(tooltip).toBeVisible({ timeout: 2000 });
const custom = page.locator('[data-testid="custom-tooltip-content"]');
await expect(custom).toBeVisible({ timeout: 2000 });
const text = await custom.textContent();
expect(text).toContain('Custom:');
});
});
// ---------------------------------------------------------------------------
// fadeLeft
// ---------------------------------------------------------------------------
test.describe('Chart fadeLeft', () => {
test('fadeLeft=true adds SVG mask and defs', async ({ mount, page }) => {
await mount(<WithFadeLeft />);
const defs = page.locator('[data-testid="chart"] svg defs');
await expect(defs).toBeAttached();
const mask = page.locator('[data-testid="chart"] svg mask');
await expect(mask).toBeAttached();
const gradient = page.locator(
'[data-testid="chart"] svg linearGradient',
);
await expect(gradient.first()).toBeAttached();
});
test('fadeLeft={60} adds SVG mask', async ({ mount, page }) => {
await mount(<WithFadeLeftCustom />);
const mask = page.locator('[data-testid="chart"] svg mask');
await expect(mask).toBeAttached();
});
test('no fadeLeft means no mask in SVG', async ({ mount, page }) => {
await mount(<Sparkline />);
const mask = page.locator('[data-testid="chart"] svg mask');
await expect(mask).not.toBeAttached();
});
});
// ---------------------------------------------------------------------------
// Props: color, strokeWidth, animate
// ---------------------------------------------------------------------------
test.describe('Chart props', () => {
test('color prop sets stroke color on single-series path', async ({
mount,
page,
}) => {
await mount(<SparklineWithColor />);
// Find path with a non-"none" stroke
const paths = page.locator('[data-testid="chart"] svg path[stroke]:not([stroke="none"])');
const stroke = await paths.first().getAttribute('stroke');
expect(stroke).toBe('rgb(0, 0, 255)');
});
test('strokeWidth prop sets stroke-width attribute', async ({
mount,
page,
}) => {
await mount(<CustomStrokeWidth />);
const paths = page.locator('[data-testid="chart"] svg path[stroke]:not([stroke="none"])');
const sw = await paths.first().getAttribute('stroke-width');
expect(sw).toBe('4');
});
test('animate=false does not apply animation class', async ({
mount,
page,
}) => {
await mount(<NoAnimation />);
const paths = page.locator('[data-testid="chart"] svg path[stroke]:not([stroke="none"])');
const cls = await paths.first().getAttribute('class');
expect(cls ?? '').not.toContain('lineAnimate');
});
test('animate=true applies animation class by default', async ({
mount,
page,
}) => {
await mount(<FullChart />);
const paths = page.locator('[data-testid="chart"] svg path[stroke]:not([stroke="none"])');
const cls = await paths.first().getAttribute('class');
expect(cls).toBeTruthy();
});
});
// ---------------------------------------------------------------------------
// Scatter chart
// ---------------------------------------------------------------------------
test.describe('Scatter chart', () => {
test('renders circles for data points', async ({ mount, page }) => {
await mount(<ScatterBasic />);
const circles = page.locator('[data-testid="scatter-chart"] svg circle');
const count = await circles.count();
expect(count).toBe(4);
});
test('has role="graphics-document" and aria-roledescription', async ({ mount, page }) => {
await mount(<ScatterBasic />);
const svg = page.locator('[data-testid="scatter-chart"] svg');
await expect(svg).toHaveAttribute('role', 'graphics-document document');
await expect(svg).toHaveAttribute('aria-roledescription', 'Scatter chart');
await expect(svg).toHaveAttribute('aria-label');
});
test('renders grid lines when grid=true', async ({ mount, page }) => {
await mount(<ScatterBasic />);
const lines = page.locator('[data-testid="scatter-chart"] svg line');
const count = await lines.count();
expect(count).toBeGreaterThanOrEqual(2);
});
test('multi-series renders legend when legend=true', async ({ mount, page }) => {
await mount(<ScatterMultiSeries />);
const legendItems = page.locator('[data-testid="scatter-chart"]').locator('..').getByText('Series A', { exact: true });
await expect(legendItems).toBeVisible();
});
test('has no accessibility violations', async ({ mount, page }) => {
await mount(<ScatterBasic />);
const results = await new AxeBuilder({ page })
.options(axeConfig)
.analyze();
expect(results.violations).toEqual([]);
});
});
// ---------------------------------------------------------------------------
// Split chart
// ---------------------------------------------------------------------------
test.describe('Split chart', () => {
test('renders segments for data', async ({ mount, page }) => {
await mount(<SplitBasic />);
const root = page.locator('[data-testid="split-chart"]');
await expect(root).toBeVisible();
const barWrap = root.locator('[role="graphics-document document"]');
await expect(barWrap).toBeAttached();
});
test('renders legend items', async ({ mount, page }) => {
await mount(<SplitBasic />);
const root = page.locator('[data-testid="split-chart"]');
await expect(root.getByText('Payments')).toBeVisible();
await expect(root.getByText('Transfers')).toBeVisible();
await expect(root.getByText('Fees')).toBeVisible();
});
test('has no accessibility violations', async ({ mount, page }) => {
await mount(<SplitBasic />);
const results = await new AxeBuilder({ page })
.options({
...axeConfig,
rules: { ...axeConfig.rules, 'color-contrast': { enabled: false } },
})
.analyze();
expect(results.violations).toEqual([]);
});
});
// ---------------------------------------------------------------------------
// Split detailed variant
// ---------------------------------------------------------------------------
test.describe('Split detailed variant', () => {
test('renders formatted value per segment', async ({ mount, page }) => {
await mount(<SplitDetailed />);
const root = page.locator('[data-testid="split-chart"]');
await expect(root.getByText('$246.1M')).toBeVisible();
await expect(root.getByText('$87.8M')).toBeVisible();
await expect(root.getByText('Incoming')).toBeVisible();
});
test('shows percentage with one decimal place', async ({ mount, page }) => {
await mount(<SplitDetailed />);
const root = page.locator('[data-testid="split-chart"]');
const countText = root.locator('[class*="splitDetailedCount"]').first();
await expect(countText).toContainText('%');
const text = await countText.textContent();
expect(text).toMatch(/\d+\.\d%/);
});
test('does not render default dot legend', async ({ mount, page }) => {
await mount(<SplitDetailed />);
const root = page.locator('[data-testid="split-chart"]');
const defaultLegend = root.locator('[class*="legendItem"]');
await expect(defaultLegend).toHaveCount(0);
});
});
// ---------------------------------------------------------------------------
// BarList ranked variant
// ---------------------------------------------------------------------------
test.describe('BarList ranked variant', () => {
test('renders ranked rows with rank numbers', async ({ mount, page }) => {
await mount(<BarListRanked />);
const root = page.locator('[data-testid="barlist-ranked"]');
await expect(root).toBeVisible();
await expect(root.getByText('United States')).toBeVisible();
await expect(root.getByText('Japan')).toBeVisible();
await expect(root.getByText('1', { exact: true })).toBeVisible();
});
test('has role="list"', async ({ mount, page }) => {
await mount(<BarListRanked />);
const root = page.locator('[data-testid="barlist-ranked"]');
await expect(root).toHaveAttribute('role', 'list');
});
test('shows change indicators', async ({ mount, page }) => {
await mount(<BarListRanked />);
const root = page.locator('[data-testid="barlist-ranked"]');
const arrows = root.getByText('\u2191');
await expect(arrows).toBeVisible();
});
test('has no accessibility violations', async ({ mount, page }) => {
await mount(<BarListRanked />);
const results = await new AxeBuilder({ page })
.options(axeConfig)
.analyze();
expect(results.violations).toEqual([]);
});
});
// ---------------------------------------------------------------------------
// Waterfall chart
// ---------------------------------------------------------------------------
test.describe('Waterfall chart', () => {
test('renders bars for each segment', async ({ mount, page }) => {
await mount(<WaterfallBasic />);
const rects = page.locator('[data-testid="waterfall-chart"] svg rect[fill]');
const count = await rects.count();
expect(count).toBeGreaterThanOrEqual(7);
});
test('renders connector lines when showConnectors=true', async ({ mount, page }) => {
await mount(<WaterfallBasic />);
const connectors = page.locator('[data-testid="waterfall-chart"] svg line[stroke-dasharray="2 2"]');
const count = await connectors.count();
expect(count).toBeGreaterThanOrEqual(1);
});
test('has role="graphics-document" and aria-roledescription', async ({ mount, page }) => {
await mount(<WaterfallBasic />);
const svg = page.locator('[data-testid="waterfall-chart"] svg');
await expect(svg).toHaveAttribute('role', 'graphics-document document');
await expect(svg).toHaveAttribute('aria-roledescription', 'Waterfall chart');
await expect(svg).toHaveAttribute('aria-label');
});
test('has no accessibility violations', async ({ mount, page }) => {
await mount(<WaterfallBasic />);
const results = await new AxeBuilder({ page })
.options(axeConfig)
.analyze();
expect(results.violations).toEqual([]);
});
});
// ---------------------------------------------------------------------------
// Sankey chart
// ---------------------------------------------------------------------------
test.describe('Sankey chart', () => {
test('renders nodes as rects', async ({ mount, page }) => {
await mount(<SankeyBasic />);
const rects = page.locator('[data-testid="sankey-chart"] svg rect[role="graphics-symbol"]');
const count = await rects.count();
expect(count).toBe(4);
});
test('renders links as paths', async ({ mount, page }) => {
await mount(<SankeyBasic />);
const paths = page.locator('[data-testid="sankey-chart"] svg path[role="graphics-symbol"]');
const count = await paths.count();
expect(count).toBe(4);
});
test('has role="graphics-document" and aria-roledescription', async ({ mount, page }) => {
await mount(<SankeyBasic />);
const svg = page.locator('[data-testid="sankey-chart"] svg');
await expect(svg).toHaveAttribute('role', 'graphics-document document');
await expect(svg).toHaveAttribute('aria-roledescription', 'Flow diagram');
});
test('renders node labels', async ({ mount, page }) => {
await mount(<SankeyBasic />);
const root = page.locator('[data-testid="sankey-chart"]');
const labels = root.locator('svg text');
const count = await labels.count();
expect(count).toBe(4);
});
test('has no accessibility violations', async ({ mount, page }) => {
await mount(<SankeyBasic />);
const results = await new AxeBuilder({ page })
.options(axeConfig)
.analyze();
expect(results.violations).toEqual([]);
});
});
// ---------------------------------------------------------------------------
// Funnel chart
// ---------------------------------------------------------------------------
test.describe('Funnel chart', () => {
test('renders a path for each stage', async ({ mount, page }) => {
await mount(<FunnelBasic />);
const paths = page.locator(
'[data-testid="funnel-chart"] svg path[role="graphics-symbol"]',
);
const count = await paths.count();
expect(count).toBe(5);
});
test('shows conversion rate in tooltip on hover', async ({ mount, page }) => {
await mount(<FunnelBasic />);
const svg = page.locator('[data-testid="funnel-chart"] svg');
await svg.focus();
await page.keyboard.press('ArrowRight');
await page.keyboard.press('ArrowRight');
const tooltip = page.locator('[data-testid="funnel-chart"] > div[class*="tooltip"]').first();
await expect(tooltip).toBeVisible();
await expect(tooltip).toContainText('42%');
});
test('has role="graphics-document" and aria-roledescription', async ({ mount, page }) => {
await mount(<FunnelBasic />);
const svg = page.locator('[data-testid="funnel-chart"] svg');
await expect(svg).toHaveAttribute('role', 'graphics-document document');
await expect(svg).toHaveAttribute('aria-roledescription', 'Funnel chart');
await expect(svg).toHaveAttribute('aria-label');
});
test('has no accessibility violations', async ({ mount, page }) => {
await mount(<FunnelBasic />);
const results = await new AxeBuilder({ page })
.options(axeConfig)
.analyze();
expect(results.violations).toEqual([]);
});
});
// ---------------------------------------------------------------------------
// Keyboard interaction
// ---------------------------------------------------------------------------
test.describe('Keyboard interaction', () => {
test('Line chart: arrow keys show tooltip, Escape dismisses', async ({ mount, page }) => {
await mount(<FullChart />);
const svg = page.locator('[data-testid="chart"] svg');
await svg.focus();
await page.keyboard.press('ArrowRight');
await page.keyboard.press('ArrowRight');
const tooltip = page.locator('[data-testid="chart"] > div[class*="tooltip"]').first();
await expect(tooltip).toBeVisible();
await page.keyboard.press('Escape');
await expect(tooltip).toBeHidden();
});
test('Bar chart: arrow keys show tooltip, Escape dismisses', async ({ mount, page }) => {
await mount(<BarBasic />);
const svg = page.locator('[data-testid="bar-chart"] svg');
await svg.focus();
await page.keyboard.press('ArrowRight');
await page.keyboard.press('ArrowRight');
const tooltip = page.locator('[data-testid="bar-chart"] > div[class*="tooltip"]').first();
await expect(tooltip).toBeVisible();
await page.keyboard.press('Escape');
await expect(tooltip).toBeHidden();
});
test('Scatter chart: arrow keys show tooltip, Escape dismisses', async ({ mount, page }) => {
await mount(<ScatterBasic />);
const svg = page.locator('[data-testid="scatter-chart"] svg');
await svg.focus();
await page.keyboard.press('ArrowRight');
await page.keyboard.press('ArrowRight');
const tooltip = page.locator('[data-testid="scatter-chart"] > div[class*="tooltip"]').first();
await expect(tooltip).toBeVisible();
await page.keyboard.press('Escape');
await expect(tooltip).toBeHidden();
});
test('Split chart: arrow keys swap legend to active segment', async ({ mount, page }) => {
await mount(<SplitBasic />);
const bar = page.locator('[data-testid="split-chart"] [class*="splitBarWrap"]');
const legend = page.locator('[data-testid="split-chart"] [class*="legend"]').first();
await expect(legend).toContainText('Payments');
await expect(legend).toContainText('Transfers');
await bar.focus();
await page.keyboard.press('ArrowRight');
await expect(legend).toContainText('Payments');
await expect(legend).not.toContainText('Transfers');
await page.keyboard.press('Escape');
await expect(legend).toContainText('Transfers');
});
test('Funnel chart: arrow keys show tooltip, Escape dismisses', async ({ mount, page }) => {
await mount(<FunnelBasic />);
const svg = page.locator('[data-testid="funnel-chart"] svg');
await svg.focus();
await page.keyboard.press('ArrowRight');
const tooltip = page.locator('[data-testid="funnel-chart"] > div[class*="tooltip"]').first();
await expect(tooltip).toBeVisible();
await page.keyboard.press('Escape');
await expect(tooltip).toBeHidden();
});
test('Waterfall chart: arrow keys show tooltip, Escape dismisses', async ({ mount, page }) => {
await mount(<WaterfallBasic />);
const svg = page.locator('[data-testid="waterfall-chart"] svg');
await svg.focus();
await page.keyboard.press('ArrowRight');
const tooltip = page.locator('[data-testid="waterfall-chart"] > div[class*="tooltip"]').first();
await expect(tooltip).toBeVisible();
await page.keyboard.press('Escape');
await expect(tooltip).toBeHidden();
});
test('Sankey chart: arrow keys show tooltip, Escape dismisses', async ({ mount, page }) => {
await mount(<SankeyBasic />);
const svg = page.locator('[data-testid="sankey-chart"] svg');
await svg.focus();
await page.keyboard.press('ArrowRight');
const tooltip = page.locator('[data-testid="sankey-chart"] > div[class*="tooltip"]').first();
await expect(tooltip).toBeVisible();
await page.keyboard.press('Escape');
await expect(tooltip).toBeHidden();
});
test('focus-visible ring appears on SVG charts', async ({ mount, page }) => {
await mount(<FullChart />);
const svg = page.locator('[data-testid="chart"] svg');
await svg.focus();
const outline = await svg.evaluate((el) => getComputedStyle(el).outlineStyle);
expect(outline).not.toBe('none');
});
});