-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
api-chart-emit-enable-disable-tooltip.spec.ts
110 lines (97 loc) · 2.89 KB
/
api-chart-emit-enable-disable-tooltip.spec.ts
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
import './utils/useSnapshotMatchers';
import { Chart } from '../../src';
import { createNodeGCanvas } from './utils/createNodeGCanvas';
import { sleep } from './utils/sleep';
import {
dispatchFirstElementPointerMoveEvent,
dispatchPlotEvent,
} from './utils/event';
import { kebabCase } from './utils/kebabCase';
const data = [
{ date: '2007-04-23', close: 93.24 },
{ date: '2007-04-24', close: 95.35 },
{ date: '2007-04-25', close: 98.84 },
{ date: '2007-04-26', close: 99.92 },
{ date: '2007-04-29', close: 99.8 },
{ date: '2007-05-01', close: 99.47 },
{ date: '2007-05-02', close: 100.39 },
{ date: '2007-05-03', close: 100.4 },
{ date: '2007-05-04', close: 100.81 },
{ date: '2007-05-07', close: 103.92 },
];
function renderBar({ canvas, container }) {
const chart = new Chart({ canvas, container });
chart.options({
type: 'interval',
data,
encode: { x: 'date', y: 'close' },
});
const finished = chart.render();
return { chart, finished };
}
function renderLine({ canvas, container }) {
const chart = new Chart({ canvas, container });
chart.options({
type: 'line',
data,
encode: { x: 'date', y: 'close' },
});
const finished = chart.render();
return { chart, finished };
}
describe('chart.emit', () => {
const dir = `${__dirname}/snapshots/api/${kebabCase(
'chartEmitEnableDisableTooltip',
)}`;
const barCanvas = createNodeGCanvas(640, 480);
const lineCanvas = createNodeGCanvas(640, 480);
it('chart.emit enable item tooltip.', async () => {
const { finished, chart } = renderBar({
canvas: barCanvas,
container: document.createElement('div'),
});
await finished;
chart.emit('tooltip:disable');
await sleep(20);
dispatchFirstElementPointerMoveEvent(barCanvas);
await expect(barCanvas).toMatchDOMSnapshot(dir, 'step0', {
fileFormat: 'html',
selector: '.g2-tooltip',
});
chart.emit('tooltip:enable');
dispatchFirstElementPointerMoveEvent(barCanvas);
await expect(barCanvas).toMatchDOMSnapshot(dir, 'step1', {
fileFormat: 'html',
selector: '.g2-tooltip',
});
});
it('chart.emit enable series tooltip.', async () => {
const { finished, chart } = renderLine({
canvas: lineCanvas,
container: document.createElement('div'),
});
await finished;
chart.emit('tooltip:disable');
dispatchPlotEvent(lineCanvas, 'pointermove', {
offsetX: 100,
offsetY: 100,
});
await expect(lineCanvas).toMatchDOMSnapshot(dir, 'step2', {
fileFormat: 'html',
selector: '.g2-tooltip',
});
chart.emit('tooltip:enable');
dispatchPlotEvent(lineCanvas, 'pointermove', {
offsetX: 100,
offsetY: 100,
});
await expect(lineCanvas).toMatchDOMSnapshot(dir, 'step3', {
fileFormat: 'html',
selector: '.g2-tooltip',
});
});
afterAll(() => {
barCanvas?.destroy();
lineCanvas?.destroy();
});
});