-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Copy pathLineChartPro.zoom.test.tsx
155 lines (135 loc) · 4.58 KB
/
LineChartPro.zoom.test.tsx
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
import * as React from 'react';
import { expect } from 'chai';
import { createRenderer, screen, fireEvent } from '@mui/internal-test-utils';
import { describeSkipIf, isJSDOM } from 'test/utils/skipIf';
import { LineChartPro } from './LineChartPro';
describeSkipIf(isJSDOM)('<LineChartPro /> - Zoom', () => {
const { render } = createRenderer();
const lineChartProps = {
series: [
{
data: [10, 20, 30, 40],
},
],
xAxis: [
{
scaleType: 'point',
data: ['A', 'B', 'C', 'D'],
zoom: true,
height: 30,
id: 'x',
},
],
yAxis: [{ position: 'none' }],
width: 100,
height: 130,
margin: 5,
slotProps: { tooltip: { trigger: 'none' } },
} as const;
const options = {
wrapper: ({ children }: { children?: React.ReactNode }) => (
<div style={{ width: 100, height: 130 }}>{children}</div>
),
};
// eslint-disable-next-line mocha/no-top-level-hooks
beforeEach(() => {
// TODO: Remove beforeEach/afterEach after vitest becomes our main runner
if (window?.document?.body?.style) {
window.document.body.style.margin = '0';
}
});
// eslint-disable-next-line mocha/no-top-level-hooks
afterEach(() => {
if (window?.document?.body?.style) {
window.document.body.style.margin = '8px';
}
});
it('should zoom on wheel', async () => {
const { user } = render(<LineChartPro {...lineChartProps} />, options);
expect(screen.queryByText('A')).not.to.equal(null);
expect(screen.queryByText('B')).not.to.equal(null);
expect(screen.queryByText('C')).not.to.equal(null);
expect(screen.queryByText('D')).not.to.equal(null);
const svg = document.querySelector('svg')!;
await user.pointer([
{
target: svg,
coords: { x: 50, y: 50 },
},
]);
// scroll, we scroll exactly in the center of the svg
// And we do it 200 times which is the lowest number to trigger a zoom where both A and D are not visible
for (let i = 0; i < 200; i += 1) {
fireEvent.wheel(svg, { deltaY: -1, clientX: 50, clientY: 50 });
}
expect(screen.queryByText('A')).to.equal(null);
expect(screen.queryByText('B')).not.to.equal(null);
expect(screen.queryByText('C')).not.to.equal(null);
expect(screen.queryByText('D')).to.equal(null);
// scroll back
for (let i = 0; i < 200; i += 1) {
fireEvent.wheel(svg, { deltaY: 1, clientX: 50, clientY: 50 });
}
expect(screen.queryByText('A')).not.to.equal(null);
expect(screen.queryByText('B')).not.to.equal(null);
expect(screen.queryByText('C')).not.to.equal(null);
expect(screen.queryByText('D')).not.to.equal(null);
});
['MouseLeft', 'TouchA'].forEach((pointerName) => {
it(`should pan on ${pointerName} drag`, async () => {
const { user } = render(
<LineChartPro {...lineChartProps} initialZoom={[{ axisId: 'x', start: 75, end: 100 }]} />,
options,
);
expect(screen.queryByText('A')).to.equal(null);
expect(screen.queryByText('B')).to.equal(null);
expect(screen.queryByText('C')).to.equal(null);
expect(screen.queryByText('D')).not.to.equal(null);
const svg = document.querySelector('svg')!;
// we drag one position so C should be visible
await user.pointer([
{
keys: `[${pointerName}>]`,
target: svg,
coords: { x: 5, y: 20 },
},
{
pointerName: pointerName === 'MouseLeft' ? undefined : pointerName,
target: svg,
coords: { x: 100, y: 20 },
},
{
keys: `[/${pointerName}]`,
target: svg,
coords: { x: 100, y: 20 },
},
]);
expect(screen.queryByText('A')).to.equal(null);
expect(screen.queryByText('B')).to.equal(null);
expect(screen.queryByText('C')).not.to.equal(null);
expect(screen.queryByText('D')).to.equal(null);
// we drag all the way to the left so A should be visible
await user.pointer([
{
keys: `[${pointerName}>]`,
target: svg,
coords: { x: 5, y: 20 },
},
{
pointerName: pointerName === 'MouseLeft' ? undefined : pointerName,
target: svg,
coords: { x: 300, y: 20 },
},
{
keys: `[/${pointerName}]`,
target: svg,
coords: { x: 300, y: 20 },
},
]);
expect(screen.queryByText('A')).not.to.equal(null);
expect(screen.queryByText('B')).to.equal(null);
expect(screen.queryByText('C')).to.equal(null);
expect(screen.queryByText('D')).to.equal(null);
});
});
});