@react-magma/charts 14.2.0 → 14.2.2-v5-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/charts.js +49 -11
- package/dist/charts.js.map +1 -1
- package/dist/charts.modern.module.js +49 -11
- package/dist/charts.modern.module.js.map +1 -1
- package/dist/charts.umd.js +229 -56
- package/dist/charts.umd.js.map +1 -1
- package/package.json +3 -3
- package/src/components/CarbonChart/CarbonChart.test.js +27 -19
- package/src/components/CarbonChart/CarbonChart.tsx +60 -11
- package/dist/components/ChartTable/ChartTable.test.d.ts +0 -1
- package/src/components/ChartTable/ChartTable.test.tsx +0 -452
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-magma/charts",
|
|
3
|
-
"version": "14.2.0",
|
|
3
|
+
"version": "14.2.2-v5-next.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"identity-obj-proxy": "3.0.0",
|
|
51
51
|
"react": "18.3.1",
|
|
52
52
|
"react-dom": "18.3.1",
|
|
53
|
-
"react-magma-dom": "^5.
|
|
53
|
+
"react-magma-dom": "^5.3.1-v5-next.0",
|
|
54
54
|
"react-magma-icons": "^3.2.5",
|
|
55
55
|
"rollup": "^4.52.4",
|
|
56
56
|
"rollup-plugin-postcss": "^4.0.2"
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"@emotion/styled": "^11.14.0",
|
|
61
61
|
"react": "^18.3.1",
|
|
62
62
|
"react-dom": "^18.3.1",
|
|
63
|
-
"react-magma-dom": "^5.
|
|
63
|
+
"react-magma-dom": "^5.3.1-v5-next.0",
|
|
64
64
|
"react-magma-icons": "^3.2.5"
|
|
65
65
|
},
|
|
66
66
|
"engines": {
|
|
@@ -1472,15 +1472,6 @@ describe('CarbonChart', () => {
|
|
|
1472
1472
|
});
|
|
1473
1473
|
|
|
1474
1474
|
describe('focus on dot content', () => {
|
|
1475
|
-
it('should set opacity to 1 when a dot receives focus', () => {
|
|
1476
|
-
const wrapper = renderChart();
|
|
1477
|
-
const dot = addDot(wrapper);
|
|
1478
|
-
|
|
1479
|
-
fireEvent.focusIn(dot);
|
|
1480
|
-
|
|
1481
|
-
expect(dot.style.opacity).toBe('1');
|
|
1482
|
-
});
|
|
1483
|
-
|
|
1484
1475
|
it('should dispatch mouseover on dot focusin to reveal tooltip data', () => {
|
|
1485
1476
|
const wrapper = renderChart();
|
|
1486
1477
|
const dot = addDot(wrapper);
|
|
@@ -1520,28 +1511,45 @@ describe('CarbonChart', () => {
|
|
|
1520
1511
|
});
|
|
1521
1512
|
|
|
1522
1513
|
describe('data visibility', () => {
|
|
1523
|
-
it('should
|
|
1514
|
+
it('should dispatch mouseout on dot focusout to hide tooltip', () => {
|
|
1524
1515
|
const wrapper = renderChart();
|
|
1525
1516
|
const dot = addDot(wrapper);
|
|
1526
1517
|
|
|
1527
|
-
|
|
1528
|
-
|
|
1518
|
+
const mouseoutSpy = jest.fn();
|
|
1519
|
+
dot.addEventListener('mouseout', mouseoutSpy);
|
|
1529
1520
|
|
|
1521
|
+
fireEvent.focusIn(dot);
|
|
1530
1522
|
fireEvent.focusOut(dot);
|
|
1531
|
-
|
|
1523
|
+
|
|
1524
|
+
expect(mouseoutSpy).toHaveBeenCalledTimes(1);
|
|
1532
1525
|
});
|
|
1533
1526
|
|
|
1534
|
-
it('should dispatch mouseout
|
|
1527
|
+
it('should not dispatch mouseout when focus moves from one dot to another', () => {
|
|
1535
1528
|
const wrapper = renderChart();
|
|
1536
|
-
const
|
|
1529
|
+
const firstDot = addDot(wrapper);
|
|
1530
|
+
const secondDot = addDot(wrapper);
|
|
1537
1531
|
|
|
1538
1532
|
const mouseoutSpy = jest.fn();
|
|
1539
|
-
|
|
1533
|
+
firstDot.addEventListener('mouseout', mouseoutSpy);
|
|
1540
1534
|
|
|
1541
|
-
fireEvent.
|
|
1542
|
-
fireEvent.focusOut(dot);
|
|
1535
|
+
fireEvent.focusOut(firstDot, { relatedTarget: secondDot });
|
|
1543
1536
|
|
|
1544
|
-
expect(mouseoutSpy).
|
|
1537
|
+
expect(mouseoutSpy).not.toHaveBeenCalled();
|
|
1538
|
+
});
|
|
1539
|
+
});
|
|
1540
|
+
|
|
1541
|
+
describe('dynamic dot rendering', () => {
|
|
1542
|
+
it('should stamp tabindex="0" on dots added after initial raf pass', () => {
|
|
1543
|
+
const wrapper = renderChart();
|
|
1544
|
+
|
|
1545
|
+
// Run initial pass before adding a dot so the observer must handle it.
|
|
1546
|
+
act(() => rafCallbacks[rafCallbacks.length - 1](0));
|
|
1547
|
+
|
|
1548
|
+
const lateDot = addDot(wrapper);
|
|
1549
|
+
|
|
1550
|
+
act(() => mutationObserverCallback([]));
|
|
1551
|
+
|
|
1552
|
+
expect(lateDot).toHaveAttribute('tabindex', '0');
|
|
1545
1553
|
});
|
|
1546
1554
|
});
|
|
1547
1555
|
});
|
|
@@ -1411,7 +1411,13 @@ export const CarbonChart = React.forwardRef<HTMLDivElement, CarbonChartProps>(
|
|
|
1411
1411
|
const timer = setTimeout(() => {
|
|
1412
1412
|
if (internalRef.current) {
|
|
1413
1413
|
internalRef.current
|
|
1414
|
-
.querySelectorAll<SVGGElement>('g[aria-label]')
|
|
1414
|
+
.querySelectorAll<SVGGElement>('g.ruler[aria-label]')
|
|
1415
|
+
.forEach(g => {
|
|
1416
|
+
g.setAttribute('aria-hidden', 'true');
|
|
1417
|
+
});
|
|
1418
|
+
|
|
1419
|
+
internalRef.current
|
|
1420
|
+
.querySelectorAll<SVGGElement>('g[aria-label]:not(.ruler)')
|
|
1415
1421
|
.forEach(g => {
|
|
1416
1422
|
const role = g.getAttribute('role');
|
|
1417
1423
|
|
|
@@ -1427,6 +1433,30 @@ export const CarbonChart = React.forwardRef<HTMLDivElement, CarbonChartProps>(
|
|
|
1427
1433
|
return () => clearTimeout(timer);
|
|
1428
1434
|
}, [type, dataSet]);
|
|
1429
1435
|
|
|
1436
|
+
React.useEffect(() => {
|
|
1437
|
+
const container = internalRef.current;
|
|
1438
|
+
|
|
1439
|
+
if (!container) return;
|
|
1440
|
+
|
|
1441
|
+
const hideRulerFromAT = () => {
|
|
1442
|
+
container
|
|
1443
|
+
.querySelectorAll<SVGGElement>('g.ruler[aria-label]')
|
|
1444
|
+
.forEach(g => {
|
|
1445
|
+
if (!g.hasAttribute('aria-hidden')) {
|
|
1446
|
+
g.setAttribute('aria-hidden', 'true');
|
|
1447
|
+
}
|
|
1448
|
+
});
|
|
1449
|
+
};
|
|
1450
|
+
|
|
1451
|
+
hideRulerFromAT();
|
|
1452
|
+
|
|
1453
|
+
const observer = new MutationObserver(hideRulerFromAT);
|
|
1454
|
+
|
|
1455
|
+
observer.observe(container, { childList: true, subtree: true });
|
|
1456
|
+
|
|
1457
|
+
return () => observer.disconnect();
|
|
1458
|
+
}, [type, dataSet]);
|
|
1459
|
+
|
|
1430
1460
|
React.useEffect(() => {
|
|
1431
1461
|
const wrapper = internalRef.current;
|
|
1432
1462
|
|
|
@@ -1494,6 +1524,16 @@ export const CarbonChart = React.forwardRef<HTMLDivElement, CarbonChartProps>(
|
|
|
1494
1524
|
|
|
1495
1525
|
if (!wrapper) return;
|
|
1496
1526
|
|
|
1527
|
+
const stampDotTabIndex = () => {
|
|
1528
|
+
wrapper
|
|
1529
|
+
.querySelectorAll<SVGCircleElement>('circle.dot')
|
|
1530
|
+
.forEach(dot => {
|
|
1531
|
+
if (!dot.hasAttribute('tabindex')) {
|
|
1532
|
+
dot.setAttribute('tabindex', '0');
|
|
1533
|
+
}
|
|
1534
|
+
});
|
|
1535
|
+
};
|
|
1536
|
+
|
|
1497
1537
|
const isDot = (el: EventTarget | null): el is SVGCircleElement =>
|
|
1498
1538
|
el instanceof Element &&
|
|
1499
1539
|
el.nodeName.toLowerCase() === 'circle' &&
|
|
@@ -1503,7 +1543,6 @@ export const CarbonChart = React.forwardRef<HTMLDivElement, CarbonChartProps>(
|
|
|
1503
1543
|
if (!isDot(e.target)) return;
|
|
1504
1544
|
const dot = e.target as SVGCircleElement;
|
|
1505
1545
|
|
|
1506
|
-
dot.style.opacity = '1';
|
|
1507
1546
|
const { left, top, width, height } = dot.getBoundingClientRect();
|
|
1508
1547
|
const cx = left + width / 2;
|
|
1509
1548
|
const cy = top + height / 2;
|
|
@@ -1532,7 +1571,11 @@ export const CarbonChart = React.forwardRef<HTMLDivElement, CarbonChartProps>(
|
|
|
1532
1571
|
if (!isDot(e.target)) return;
|
|
1533
1572
|
const dot = e.target;
|
|
1534
1573
|
|
|
1535
|
-
|
|
1574
|
+
// Keep tooltip context while Tab focus moves between chart points.
|
|
1575
|
+
if (isDot(e.relatedTarget)) {
|
|
1576
|
+
return;
|
|
1577
|
+
}
|
|
1578
|
+
|
|
1536
1579
|
dot.dispatchEvent(new MouseEvent('mouseout', { bubbles: true }));
|
|
1537
1580
|
};
|
|
1538
1581
|
|
|
@@ -1555,13 +1598,18 @@ export const CarbonChart = React.forwardRef<HTMLDivElement, CarbonChartProps>(
|
|
|
1555
1598
|
};
|
|
1556
1599
|
|
|
1557
1600
|
const rafId = requestAnimationFrame(() => {
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1601
|
+
stampDotTabIndex();
|
|
1602
|
+
});
|
|
1603
|
+
|
|
1604
|
+
const dotObserver = new MutationObserver(() => {
|
|
1605
|
+
stampDotTabIndex();
|
|
1606
|
+
});
|
|
1607
|
+
|
|
1608
|
+
dotObserver.observe(wrapper, {
|
|
1609
|
+
childList: true,
|
|
1610
|
+
subtree: true,
|
|
1611
|
+
attributes: true,
|
|
1612
|
+
attributeFilter: ['class', 'style', 'tabindex'],
|
|
1565
1613
|
});
|
|
1566
1614
|
|
|
1567
1615
|
wrapper.addEventListener('focusin', onFocusIn);
|
|
@@ -1570,11 +1618,12 @@ export const CarbonChart = React.forwardRef<HTMLDivElement, CarbonChartProps>(
|
|
|
1570
1618
|
|
|
1571
1619
|
return () => {
|
|
1572
1620
|
cancelAnimationFrame(rafId);
|
|
1621
|
+
dotObserver.disconnect();
|
|
1573
1622
|
wrapper.removeEventListener('focusin', onFocusIn);
|
|
1574
1623
|
wrapper.removeEventListener('focusout', onFocusOut);
|
|
1575
1624
|
wrapper.removeEventListener('keydown', onKeyDown);
|
|
1576
1625
|
};
|
|
1577
|
-
}, [type]);
|
|
1626
|
+
}, [type, dataSet]);
|
|
1578
1627
|
|
|
1579
1628
|
const groupsLength = Object.keys(colorScale).length;
|
|
1580
1629
|
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import '@testing-library/jest-dom';
|
|
@@ -1,452 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
|
|
3
|
-
import '@testing-library/jest-dom';
|
|
4
|
-
import {
|
|
5
|
-
act,
|
|
6
|
-
render,
|
|
7
|
-
screen,
|
|
8
|
-
fireEvent,
|
|
9
|
-
waitFor,
|
|
10
|
-
} from '@testing-library/react';
|
|
11
|
-
import { DropdownMenuItem } from 'react-magma-dom';
|
|
12
|
-
import {
|
|
13
|
-
FullscreenExitIcon,
|
|
14
|
-
FullscreenIcon,
|
|
15
|
-
MoreVertIcon,
|
|
16
|
-
TableChartIcon,
|
|
17
|
-
} from 'react-magma-icons';
|
|
18
|
-
|
|
19
|
-
import { ChartDataTable } from './ChartDataTable';
|
|
20
|
-
import { ChartFullscreenButton } from './ChartFullscreenButton';
|
|
21
|
-
import { ChartMoreOptionsButton } from './ChartMoreOptionsButton';
|
|
22
|
-
import { ChartTableButton } from './ChartTableButton';
|
|
23
|
-
import { ChartTableModal } from './ChartTableModal';
|
|
24
|
-
import { ChartToolbar } from './ChartToolbar';
|
|
25
|
-
|
|
26
|
-
const dataSet = [
|
|
27
|
-
{ group: 'High performance', value: 50 },
|
|
28
|
-
{ group: 'Average performance', value: 30 },
|
|
29
|
-
{ group: 'Poor performance', value: 15 },
|
|
30
|
-
{ group: 'Not attempted', value: 5 },
|
|
31
|
-
];
|
|
32
|
-
|
|
33
|
-
// ---------------------------------------------------------------------------
|
|
34
|
-
// ChartDataTable
|
|
35
|
-
// ---------------------------------------------------------------------------
|
|
36
|
-
describe('ChartDataTable', () => {
|
|
37
|
-
it('derives column headers from dataset keys when no columns prop is given', () => {
|
|
38
|
-
render(<ChartDataTable dataSet={dataSet} />);
|
|
39
|
-
|
|
40
|
-
expect(
|
|
41
|
-
screen.getByRole('columnheader', { name: 'Group' })
|
|
42
|
-
).toBeInTheDocument();
|
|
43
|
-
expect(
|
|
44
|
-
screen.getByRole('columnheader', { name: 'Value' })
|
|
45
|
-
).toBeInTheDocument();
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it('renders all data rows', () => {
|
|
49
|
-
render(<ChartDataTable dataSet={dataSet} />);
|
|
50
|
-
|
|
51
|
-
expect(
|
|
52
|
-
screen.getByRole('cell', { name: 'High performance' })
|
|
53
|
-
).toBeInTheDocument();
|
|
54
|
-
expect(screen.getByRole('cell', { name: '50' })).toBeInTheDocument();
|
|
55
|
-
expect(
|
|
56
|
-
screen.getByRole('cell', { name: 'Not attempted' })
|
|
57
|
-
).toBeInTheDocument();
|
|
58
|
-
expect(screen.getByRole('cell', { name: '5' })).toBeInTheDocument();
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
it('accepts custom column definitions', () => {
|
|
62
|
-
const columns = [
|
|
63
|
-
{ header: 'Category', key: 'group' },
|
|
64
|
-
{ header: 'Count', key: 'value' },
|
|
65
|
-
];
|
|
66
|
-
|
|
67
|
-
render(<ChartDataTable columns={columns} dataSet={dataSet} />);
|
|
68
|
-
|
|
69
|
-
expect(
|
|
70
|
-
screen.getByRole('columnheader', { name: 'Category' })
|
|
71
|
-
).toBeInTheDocument();
|
|
72
|
-
expect(
|
|
73
|
-
screen.getByRole('columnheader', { name: 'Count' })
|
|
74
|
-
).toBeInTheDocument();
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
it('renders with isInverse without error', () => {
|
|
78
|
-
render(<ChartDataTable dataSet={dataSet} isInverse />);
|
|
79
|
-
|
|
80
|
-
expect(screen.getByRole('table')).toBeInTheDocument();
|
|
81
|
-
});
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
// ---------------------------------------------------------------------------
|
|
85
|
-
// ChartTableModal
|
|
86
|
-
// ---------------------------------------------------------------------------
|
|
87
|
-
describe('ChartTableModal', () => {
|
|
88
|
-
it('renders a dialog with semantic heading when open', () => {
|
|
89
|
-
render(
|
|
90
|
-
<ChartTableModal
|
|
91
|
-
dataSet={dataSet}
|
|
92
|
-
isOpen
|
|
93
|
-
onClose={jest.fn()}
|
|
94
|
-
title="Overall Performance"
|
|
95
|
-
/>
|
|
96
|
-
);
|
|
97
|
-
|
|
98
|
-
expect(screen.getByRole('dialog')).toBeInTheDocument();
|
|
99
|
-
expect(
|
|
100
|
-
screen.getByRole('heading', {
|
|
101
|
-
level: 2,
|
|
102
|
-
name: 'Tabular representation Overall Performance',
|
|
103
|
-
})
|
|
104
|
-
).toBeInTheDocument();
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
it('respects custom headerLevel', () => {
|
|
108
|
-
render(
|
|
109
|
-
<ChartTableModal
|
|
110
|
-
dataSet={dataSet}
|
|
111
|
-
headerLevel={1}
|
|
112
|
-
isOpen
|
|
113
|
-
onClose={jest.fn()}
|
|
114
|
-
title="Test"
|
|
115
|
-
/>
|
|
116
|
-
);
|
|
117
|
-
|
|
118
|
-
expect(screen.getByRole('heading', { level: 1 })).toBeInTheDocument();
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
it('respects custom headerLabel', () => {
|
|
122
|
-
render(
|
|
123
|
-
<ChartTableModal
|
|
124
|
-
dataSet={dataSet}
|
|
125
|
-
headerLabel="Data table"
|
|
126
|
-
isOpen
|
|
127
|
-
onClose={jest.fn()}
|
|
128
|
-
title="My Chart"
|
|
129
|
-
/>
|
|
130
|
-
);
|
|
131
|
-
|
|
132
|
-
expect(
|
|
133
|
-
screen.getByRole('heading', { name: 'Data table My Chart' })
|
|
134
|
-
).toBeInTheDocument();
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
it('does not render dialog when closed', () => {
|
|
138
|
-
render(
|
|
139
|
-
<ChartTableModal
|
|
140
|
-
dataSet={dataSet}
|
|
141
|
-
isOpen={false}
|
|
142
|
-
onClose={jest.fn()}
|
|
143
|
-
title="Test"
|
|
144
|
-
/>
|
|
145
|
-
);
|
|
146
|
-
|
|
147
|
-
expect(screen.queryByRole('dialog')).not.toBeInTheDocument();
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
it('renders the data table inside the modal', () => {
|
|
151
|
-
render(
|
|
152
|
-
<ChartTableModal
|
|
153
|
-
dataSet={dataSet}
|
|
154
|
-
isOpen
|
|
155
|
-
onClose={jest.fn()}
|
|
156
|
-
title="Test"
|
|
157
|
-
/>
|
|
158
|
-
);
|
|
159
|
-
|
|
160
|
-
expect(
|
|
161
|
-
screen.getByRole('columnheader', { name: 'Group' })
|
|
162
|
-
).toBeInTheDocument();
|
|
163
|
-
expect(
|
|
164
|
-
screen.getByRole('cell', { name: 'High performance' })
|
|
165
|
-
).toBeInTheDocument();
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
it('calls onClose when close button is activated', async () => {
|
|
169
|
-
jest.useFakeTimers();
|
|
170
|
-
const onClose = jest.fn();
|
|
171
|
-
|
|
172
|
-
render(
|
|
173
|
-
<ChartTableModal
|
|
174
|
-
dataSet={dataSet}
|
|
175
|
-
isOpen
|
|
176
|
-
onClose={onClose}
|
|
177
|
-
title="Test"
|
|
178
|
-
/>
|
|
179
|
-
);
|
|
180
|
-
|
|
181
|
-
fireEvent.click(screen.getByTestId('modal-closebtn'));
|
|
182
|
-
|
|
183
|
-
await act(async () => {
|
|
184
|
-
jest.runAllTimers();
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
expect(onClose).toHaveBeenCalledTimes(1);
|
|
188
|
-
jest.useRealTimers();
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
it('renders with isInverse without error', () => {
|
|
192
|
-
render(
|
|
193
|
-
<ChartTableModal
|
|
194
|
-
dataSet={dataSet}
|
|
195
|
-
isInverse
|
|
196
|
-
isOpen
|
|
197
|
-
onClose={jest.fn()}
|
|
198
|
-
title="Inverse Modal"
|
|
199
|
-
/>
|
|
200
|
-
);
|
|
201
|
-
|
|
202
|
-
expect(screen.getByRole('dialog')).toBeInTheDocument();
|
|
203
|
-
});
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
// ---------------------------------------------------------------------------
|
|
207
|
-
// ChartTableButton
|
|
208
|
-
// ---------------------------------------------------------------------------
|
|
209
|
-
describe('ChartTableButton', () => {
|
|
210
|
-
const icon = <TableChartIcon />;
|
|
211
|
-
|
|
212
|
-
it('renders with aria-haspopup="dialog"', () => {
|
|
213
|
-
render(
|
|
214
|
-
<ChartTableButton
|
|
215
|
-
ariaLabel="Overall Performance"
|
|
216
|
-
icon={icon}
|
|
217
|
-
isTableOpen={false}
|
|
218
|
-
onClick={jest.fn()}
|
|
219
|
-
/>
|
|
220
|
-
);
|
|
221
|
-
|
|
222
|
-
const button = screen.getByRole('button', { name: 'Overall Performance' });
|
|
223
|
-
|
|
224
|
-
expect(button).toHaveAttribute('aria-haspopup', 'dialog');
|
|
225
|
-
});
|
|
226
|
-
|
|
227
|
-
it('sets aria-expanded to false when modal is closed', () => {
|
|
228
|
-
render(
|
|
229
|
-
<ChartTableButton
|
|
230
|
-
ariaLabel="Overall Performance"
|
|
231
|
-
icon={icon}
|
|
232
|
-
isTableOpen={false}
|
|
233
|
-
onClick={jest.fn()}
|
|
234
|
-
/>
|
|
235
|
-
);
|
|
236
|
-
|
|
237
|
-
expect(
|
|
238
|
-
screen.getByRole('button', { name: 'Overall Performance' })
|
|
239
|
-
).toHaveAttribute('aria-expanded', 'false');
|
|
240
|
-
});
|
|
241
|
-
|
|
242
|
-
it('sets aria-expanded to true when modal is open', () => {
|
|
243
|
-
render(
|
|
244
|
-
<ChartTableButton
|
|
245
|
-
ariaLabel="Overall Performance"
|
|
246
|
-
icon={icon}
|
|
247
|
-
isTableOpen
|
|
248
|
-
onClick={jest.fn()}
|
|
249
|
-
/>
|
|
250
|
-
);
|
|
251
|
-
|
|
252
|
-
expect(
|
|
253
|
-
screen.getByRole('button', { name: 'Overall Performance' })
|
|
254
|
-
).toHaveAttribute('aria-expanded', 'true');
|
|
255
|
-
});
|
|
256
|
-
|
|
257
|
-
it('calls onClick when activated', () => {
|
|
258
|
-
const onClick = jest.fn();
|
|
259
|
-
|
|
260
|
-
render(
|
|
261
|
-
<ChartTableButton
|
|
262
|
-
ariaLabel="Overall Performance"
|
|
263
|
-
icon={icon}
|
|
264
|
-
isTableOpen={false}
|
|
265
|
-
onClick={onClick}
|
|
266
|
-
/>
|
|
267
|
-
);
|
|
268
|
-
|
|
269
|
-
fireEvent.click(
|
|
270
|
-
screen.getByRole('button', { name: 'Overall Performance' })
|
|
271
|
-
);
|
|
272
|
-
expect(onClick).toHaveBeenCalledTimes(1);
|
|
273
|
-
});
|
|
274
|
-
|
|
275
|
-
it('renders with custom tooltip content on hover', async () => {
|
|
276
|
-
render(
|
|
277
|
-
<ChartTableButton
|
|
278
|
-
ariaLabel="Overall Performance"
|
|
279
|
-
icon={icon}
|
|
280
|
-
isTableOpen={false}
|
|
281
|
-
onClick={jest.fn()}
|
|
282
|
-
tooltipContent="View data as table"
|
|
283
|
-
/>
|
|
284
|
-
);
|
|
285
|
-
|
|
286
|
-
const button = screen.getByRole('button', { name: 'Overall Performance' });
|
|
287
|
-
|
|
288
|
-
fireEvent.mouseEnter(button);
|
|
289
|
-
|
|
290
|
-
await waitFor(() => {
|
|
291
|
-
expect(screen.getByText('View data as table')).toBeInTheDocument();
|
|
292
|
-
});
|
|
293
|
-
});
|
|
294
|
-
});
|
|
295
|
-
|
|
296
|
-
// ---------------------------------------------------------------------------
|
|
297
|
-
// ChartFullscreenButton
|
|
298
|
-
// ---------------------------------------------------------------------------
|
|
299
|
-
describe('ChartFullscreenButton', () => {
|
|
300
|
-
it('does NOT have aria-haspopup', () => {
|
|
301
|
-
render(
|
|
302
|
-
<ChartFullscreenButton
|
|
303
|
-
ariaLabel="View chart in full screen"
|
|
304
|
-
icon={<FullscreenIcon />}
|
|
305
|
-
isFullscreen={false}
|
|
306
|
-
onClick={jest.fn()}
|
|
307
|
-
/>
|
|
308
|
-
);
|
|
309
|
-
|
|
310
|
-
const button = screen.getByRole('button', {
|
|
311
|
-
name: 'View chart in full screen',
|
|
312
|
-
});
|
|
313
|
-
|
|
314
|
-
expect(button).not.toHaveAttribute('aria-haspopup');
|
|
315
|
-
});
|
|
316
|
-
|
|
317
|
-
it('calls onClick when activated', () => {
|
|
318
|
-
const onClick = jest.fn();
|
|
319
|
-
|
|
320
|
-
render(
|
|
321
|
-
<ChartFullscreenButton
|
|
322
|
-
ariaLabel="View chart in full screen"
|
|
323
|
-
icon={<FullscreenIcon />}
|
|
324
|
-
isFullscreen={false}
|
|
325
|
-
onClick={onClick}
|
|
326
|
-
/>
|
|
327
|
-
);
|
|
328
|
-
|
|
329
|
-
fireEvent.click(
|
|
330
|
-
screen.getByRole('button', { name: 'View chart in full screen' })
|
|
331
|
-
);
|
|
332
|
-
expect(onClick).toHaveBeenCalledTimes(1);
|
|
333
|
-
});
|
|
334
|
-
|
|
335
|
-
it('shows "Make full screen" tooltip by default', async () => {
|
|
336
|
-
render(
|
|
337
|
-
<ChartFullscreenButton
|
|
338
|
-
ariaLabel="Fullscreen"
|
|
339
|
-
icon={<FullscreenIcon />}
|
|
340
|
-
isFullscreen={false}
|
|
341
|
-
onClick={jest.fn()}
|
|
342
|
-
/>
|
|
343
|
-
);
|
|
344
|
-
|
|
345
|
-
fireEvent.mouseEnter(screen.getByRole('button', { name: 'Fullscreen' }));
|
|
346
|
-
await waitFor(() => {
|
|
347
|
-
expect(screen.getByText('Make full screen')).toBeInTheDocument();
|
|
348
|
-
});
|
|
349
|
-
});
|
|
350
|
-
|
|
351
|
-
it('shows "Exit full screen" tooltip when in fullscreen', async () => {
|
|
352
|
-
render(
|
|
353
|
-
<ChartFullscreenButton
|
|
354
|
-
ariaLabel="Fullscreen"
|
|
355
|
-
icon={<FullscreenIcon />}
|
|
356
|
-
exitIcon={<FullscreenExitIcon />}
|
|
357
|
-
isFullscreen
|
|
358
|
-
onClick={jest.fn()}
|
|
359
|
-
/>
|
|
360
|
-
);
|
|
361
|
-
|
|
362
|
-
fireEvent.mouseEnter(screen.getByRole('button', { name: 'Fullscreen' }));
|
|
363
|
-
await waitFor(() => {
|
|
364
|
-
expect(screen.getByText('Exit full screen')).toBeInTheDocument();
|
|
365
|
-
});
|
|
366
|
-
});
|
|
367
|
-
});
|
|
368
|
-
|
|
369
|
-
// ---------------------------------------------------------------------------
|
|
370
|
-
// ChartMoreOptionsButton
|
|
371
|
-
// ---------------------------------------------------------------------------
|
|
372
|
-
describe('ChartMoreOptionsButton', () => {
|
|
373
|
-
it('renders with default "More options" label', () => {
|
|
374
|
-
render(
|
|
375
|
-
<ChartMoreOptionsButton icon={<MoreVertIcon />}>
|
|
376
|
-
<DropdownMenuItem>Download</DropdownMenuItem>
|
|
377
|
-
</ChartMoreOptionsButton>
|
|
378
|
-
);
|
|
379
|
-
|
|
380
|
-
expect(
|
|
381
|
-
screen.getByRole('button', { name: 'More options' })
|
|
382
|
-
).toBeInTheDocument();
|
|
383
|
-
});
|
|
384
|
-
|
|
385
|
-
it('renders with custom aria-label', () => {
|
|
386
|
-
render(
|
|
387
|
-
<ChartMoreOptionsButton ariaLabel="Chart actions" icon={<MoreVertIcon />}>
|
|
388
|
-
<DropdownMenuItem>Download</DropdownMenuItem>
|
|
389
|
-
</ChartMoreOptionsButton>
|
|
390
|
-
);
|
|
391
|
-
|
|
392
|
-
expect(
|
|
393
|
-
screen.getByRole('button', { name: 'Chart actions' })
|
|
394
|
-
).toBeInTheDocument();
|
|
395
|
-
});
|
|
396
|
-
|
|
397
|
-
it('opens dropdown menu on click', () => {
|
|
398
|
-
render(
|
|
399
|
-
<ChartMoreOptionsButton icon={<MoreVertIcon />}>
|
|
400
|
-
<DropdownMenuItem>Download as CSV</DropdownMenuItem>
|
|
401
|
-
</ChartMoreOptionsButton>
|
|
402
|
-
);
|
|
403
|
-
|
|
404
|
-
fireEvent.click(screen.getByRole('button', { name: 'More options' }));
|
|
405
|
-
expect(screen.getByText('Download as CSV')).toBeVisible();
|
|
406
|
-
});
|
|
407
|
-
});
|
|
408
|
-
|
|
409
|
-
// ---------------------------------------------------------------------------
|
|
410
|
-
// ChartToolbar
|
|
411
|
-
// ---------------------------------------------------------------------------
|
|
412
|
-
describe('ChartToolbar', () => {
|
|
413
|
-
it('renders the title as a heading', () => {
|
|
414
|
-
render(
|
|
415
|
-
<ChartToolbar title="Overall Performance">
|
|
416
|
-
<button>Action</button>
|
|
417
|
-
</ChartToolbar>
|
|
418
|
-
);
|
|
419
|
-
|
|
420
|
-
expect(
|
|
421
|
-
screen.getByRole('heading', { level: 3, name: 'Overall Performance' })
|
|
422
|
-
).toBeInTheDocument();
|
|
423
|
-
});
|
|
424
|
-
|
|
425
|
-
it('renders children action buttons', () => {
|
|
426
|
-
render(
|
|
427
|
-
<ChartToolbar title="Test">
|
|
428
|
-
<button>Show as table</button>
|
|
429
|
-
<button>Full screen</button>
|
|
430
|
-
</ChartToolbar>
|
|
431
|
-
);
|
|
432
|
-
|
|
433
|
-
expect(
|
|
434
|
-
screen.getByRole('button', { name: 'Show as table' })
|
|
435
|
-
).toBeInTheDocument();
|
|
436
|
-
expect(
|
|
437
|
-
screen.getByRole('button', { name: 'Full screen' })
|
|
438
|
-
).toBeInTheDocument();
|
|
439
|
-
});
|
|
440
|
-
|
|
441
|
-
it('respects custom heading level', () => {
|
|
442
|
-
render(
|
|
443
|
-
<ChartToolbar title="Test" headingLevel={2}>
|
|
444
|
-
<button>Action</button>
|
|
445
|
-
</ChartToolbar>
|
|
446
|
-
);
|
|
447
|
-
|
|
448
|
-
expect(
|
|
449
|
-
screen.getByRole('heading', { level: 2, name: 'Test' })
|
|
450
|
-
).toBeInTheDocument();
|
|
451
|
-
});
|
|
452
|
-
});
|