-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
api-chart-on-series-element.spec.ts
99 lines (94 loc) · 2.03 KB
/
api-chart-on-series-element.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
import { chartOnSeriesElement as render } from '../plots/api/chart-on-series-element';
import { createNodeGCanvas } from './utils/createNodeGCanvas';
import {
dispatchFirstElementEvent,
createPromise,
receiveExpectData,
} from './utils/event';
import './utils/useSnapshotMatchers';
const data = {
data: [
{
month: 'Jan',
city: 'Tokyo',
temperature: 7,
},
{
month: 'Feb',
city: 'Tokyo',
temperature: 6.9,
},
{
month: 'Mar',
city: 'Tokyo',
temperature: 9.5,
},
{
month: 'Apr',
city: 'Tokyo',
temperature: 14.5,
},
{
month: 'May',
city: 'Tokyo',
temperature: 18.4,
},
{
month: 'Jun',
city: 'Tokyo',
temperature: 21.5,
},
{
month: 'Jul',
city: 'Tokyo',
temperature: 25.2,
},
{
month: 'Aug',
city: 'Tokyo',
temperature: 26.5,
},
{
month: 'Sep',
city: 'Tokyo',
temperature: 23.3,
},
{
month: 'Oct',
city: 'Tokyo',
temperature: 18.3,
},
{
month: 'Nov',
city: 'Tokyo',
temperature: 13.9,
},
{
month: 'Dec',
city: 'Tokyo',
temperature: 9.6,
},
],
};
describe('chart.on', () => {
const canvas = createNodeGCanvas(640, 480);
const { finished, chart } = render({ canvas });
chart.off();
it('chart.on("element:click", callback) should provide data for series element', async () => {
await finished;
const [fired, resolve] = createPromise();
chart.on('element:click', receiveExpectData(resolve, data));
dispatchFirstElementEvent(canvas, 'click', { detail: 1 });
await fired;
});
it('chart.on("line:click", callback) should provide data for series element', async () => {
await finished;
const [fired, resolve] = createPromise();
chart.on('line:click', receiveExpectData(resolve, data));
dispatchFirstElementEvent(canvas, 'click', { detail: 1 });
await fired;
});
afterAll(() => {
canvas?.destroy();
});
});