-
Notifications
You must be signed in to change notification settings - Fork 0
/
api-chart-on-component-click.spec.ts
76 lines (66 loc) · 2.7 KB
/
api-chart-on-component-click.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
import { chartOnComponentClick as render } from '../plots/api/chart-on-component-click';
import { createNodeGCanvas } from './utils/createNodeGCanvas';
import { dispatchFirstShapeEvent, createPromise } from './utils/event';
import './utils/useSnapshotMatchers';
import { ChartEvent } from '../../src';
describe('chart.on', () => {
const canvas = createNodeGCanvas(640, 480);
const { finished, chart } = render({ canvas });
chart.off();
it('chart.on("component:click", callback) should emit events', async () => {
await finished;
const [fired, resolve] = createPromise();
chart.on(`component:${ChartEvent.CLICK}`, resolve);
dispatchFirstShapeEvent(canvas, 'component', 'click', { detail: 1 });
await fired;
});
it('chart.on("legend-category:click", callback) should emit events', async () => {
await finished;
const [fired, resolve] = createPromise();
chart.on(`legend-category:${ChartEvent.CLICK}`, resolve);
dispatchFirstShapeEvent(canvas, 'legend-category', 'click', { detail: 1 });
await fired;
});
it('chart.on("legend-category-item-marker:click", callback) should emit events', async () => {
await finished;
const [fired, resolve] = createPromise();
chart.on(`legend-category-item-marker:${ChartEvent.CLICK}`, resolve);
dispatchFirstShapeEvent(canvas, 'legend-category-item-marker', 'click', {
detail: 1,
});
await fired;
});
it('chart.on("legend-category-item-label:click", callback) should emit events', async () => {
await finished;
const [fired, resolve] = createPromise();
chart.on(`legend-category-item-label:${ChartEvent.CLICK}`, resolve);
dispatchFirstShapeEvent(canvas, 'legend-category-item-label', 'click', {
detail: 1,
});
await fired;
});
it('chart.on("grid-line:click", callback) should emit events', async () => {
await finished;
const [fired, resolve] = createPromise();
chart.on(`grid-line:${ChartEvent.CLICK}`, resolve);
dispatchFirstShapeEvent(canvas, 'grid-line', 'click', { detail: 1 });
await fired;
});
it('chart.on("axis-tick-item:click", callback) should emit events', async () => {
await finished;
const [fired, resolve] = createPromise();
chart.on(`axis-tick-item:${ChartEvent.CLICK}`, resolve);
dispatchFirstShapeEvent(canvas, 'axis-tick-item', 'click', { detail: 1 });
await fired;
});
it('chart.on("axis-label-item:click", callback) should emit events', async () => {
await finished;
const [fired, resolve] = createPromise();
chart.on(`axis-label-item:${ChartEvent.CLICK}`, resolve);
dispatchFirstShapeEvent(canvas, 'axis-label-item', 'click', { detail: 1 });
await fired;
});
afterAll(() => {
canvas?.destroy();
});
});