-
Notifications
You must be signed in to change notification settings - Fork 0
/
api-chart-emit-brush-highlight-axis-horizontal.spec.ts
72 lines (63 loc) · 2.33 KB
/
api-chart-emit-brush-highlight-axis-horizontal.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
import { chartEmitBrushHighlightAxisHorizontal as render } from '../plots/api/chart-emit-brush-highlight-axis-horizontal';
import { dblclick, brush } from '../plots/interaction/penguins-point-brush';
import { AXIS_HOT_AREA_CLASS_NAME } from '../../src/interaction/brushAxisHighlight';
import { createNodeGCanvas } from './utils/createNodeGCanvas';
import { createPromise, getElementByClassName } from './utils/event';
import { sleep } from './utils/sleep';
import { kebabCase } from './utils/kebabCase';
import './utils/useCustomFetch';
import './utils/useSnapshotMatchers';
describe('chart.on', () => {
const dir = `${__dirname}/snapshots/api/${kebabCase(render.name)}`;
const canvas = createNodeGCanvas(640, 800);
it('chart.emit("brushAxis:highlight", callback) should emit events.', async () => {
const { chart, finished } = render({
canvas,
container: document.createElement('div'),
});
await finished;
await sleep(20);
// chart.emit('brushAxis:highlight', options) should trigger slider.
chart.emit('brushAxis:highlight', {
data: { selection: [[20, 30], undefined, [100, 300]] },
});
await sleep(20);
await expect(canvas).toMatchDOMSnapshot(dir, 'step0');
// chart.emit('brushAxis:remove', options) should reset.
chart.emit('brushAxis:remove', {});
await sleep(20);
await expect(canvas).toMatchDOMSnapshot(dir, 'step1');
chart.off();
const axis = getElementByClassName(canvas, AXIS_HOT_AREA_CLASS_NAME);
// chart.on("brushAxis:highlight") should receive expected data.
const [highlight, resolveHighlight] = createPromise();
chart.on('brushAxis:highlight', (event) => {
if (!event.nativeEvent) return;
expect(event.data.selection).toEqual([
[11.999999999999998, 32.7],
[3, 8],
[68, 455],
[46, 230],
[1613, 5140],
[8, 24.8],
[70, 82],
]);
resolveHighlight();
});
brush(axis, 50, -Infinity, 400, Infinity);
await sleep(20);
await highlight;
// chart.on("brushAxis:remove") should be called.
const [remove, resolveRemove] = createPromise();
chart.on('brushAxis:remove', (event) => {
if (!event.nativeEvent) return;
resolveRemove();
});
dblclick(axis);
await sleep(20);
await remove;
});
afterAll(() => {
canvas?.destroy();
});
});