-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
api-chart-emit-legend-highlight.spec.ts
71 lines (63 loc) · 2.23 KB
/
api-chart-emit-legend-highlight.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
import { chartEmitLegendHighlight as render } from '../plots/api/chart-emit-legend-highlight';
import {
LEGEND_ITEMS_CLASS_NAME,
CATEGORY_LEGEND_CLASS_NAME,
} from '../../src/interaction/legendFilter';
import { createNodeGCanvas } from './utils/createNodeGCanvas';
import { sleep } from './utils/sleep';
import { kebabCase } from './utils/kebabCase';
import { createPromise, dispatchFirstShapeEvent } from './utils/event';
import './utils/useSnapshotMatchers';
import './utils/useCustomFetch';
describe('chart.emit', () => {
const dir = `${__dirname}/snapshots/api/${kebabCase(render.name)}`;
const canvas = createNodeGCanvas(800, 500);
it('chart.on("legend:highlight") should receive expected data.', async () => {
const { chart, finished } = render({
canvas,
container: document.createElement('div'),
});
await finished;
await sleep(20);
// chart.emit('legend:highlight', options) should trigger slider.
chart.emit('legend:highlight', {
data: { channel: 'color', value: 'Increase' },
});
await sleep(20);
await expect(canvas).toMatchDOMSnapshot(dir, 'step0');
// chart.emit('legend:unhighlight', options) should reset.
chart.emit('legend:unhighlight', {});
await sleep(20);
await expect(canvas).toMatchDOMSnapshot(dir, 'step1');
chart.off();
// chart.on("legend:unhighlight") should be called.
const [unhighlight, resolveUnhighlight] = createPromise();
chart.on('legend:unhighlight', (event) => {
if (!event.nativeEvent) return;
resolveUnhighlight();
});
dispatchFirstShapeEvent(
canvas,
CATEGORY_LEGEND_CLASS_NAME,
'pointerleave',
{ nativeEvent: true },
);
await sleep(20);
await unhighlight;
// chart.on("legend:highlight") should receive expected data.
const [highlight, resolveHighlight] = createPromise();
chart.on('legend:highlight', (event) => {
if (!event.nativeEvent) return;
expect(event.data).toEqual({ channel: 'color', value: 'Increase' });
resolveHighlight();
});
dispatchFirstShapeEvent(canvas, LEGEND_ITEMS_CLASS_NAME, 'pointerover', {
nativeEvent: true,
});
await sleep(20);
await highlight;
});
afterAll(() => {
canvas?.destroy();
});
});