forked from antvis/G2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi-chart-emit-click-tooltip.spec.ts
44 lines (37 loc) · 1.33 KB
/
api-chart-emit-click-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
import { chartEmitClickTooltip as render } from '../plots/api/chart-emit-click-tooltip';
import { kebabCase } from './utils/kebabCase';
import { dispatchFirstElementEvent, dispatchPlotEvent } from './utils/event';
import './utils/useSnapshotMatchers';
import { createNodeGCanvas } from './utils/createNodeGCanvas';
describe('chart.emit', () => {
const dir = `${__dirname}/snapshots/api/${kebabCase(render.name)}`;
const canvas = createNodeGCanvas(640, 480);
it('chart.tooltip should disable native events.', async () => {
const { finished } = render({
canvas,
container: document.createElement('div'),
});
await finished;
// Disable native events.
dispatchFirstElementEvent(canvas, 'pointerover');
await expect(canvas).toMatchDOMSnapshot(dir, 'step0', {
fileFormat: 'html',
selector: '.g2-tooltip',
});
// Click item to show tooltip.
dispatchFirstElementEvent(canvas, 'click', { detail: 1 });
await expect(canvas).toMatchDOMSnapshot(dir, 'step1', {
fileFormat: 'html',
selector: '.g2-tooltip',
});
// Click plot to hide tooltip.
dispatchPlotEvent(canvas, 'click', { detail: 1 });
await expect(canvas).toMatchDOMSnapshot(dir, 'step2', {
fileFormat: 'html',
selector: '.g2-tooltip',
});
});
afterAll(() => {
canvas?.destroy();
});
});