fix: fix missing refactor event (#5816)

This commit is contained in:
Aaron 2024-06-04 21:32:50 +08:00 committed by GitHub
parent e932c0ac7b
commit a5403b37a0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 23 additions and 22 deletions

View File

@ -1,4 +1,4 @@
import { Graph } from '@/src';
import { Graph, NodeEvent } from '@/src';
import { positionOf } from '@/src/utils/position';
import { createGraphCanvas } from '@@/utils';
@ -18,21 +18,21 @@ describe('behavior drag element bug', () => {
expect(graph.getZoom()).toBe(1);
expect(positionOf(graph.getNodeData('node-1'))).toEqual([100, 100, 0]);
graph.emit('node:dragstart', { target: { id: 'node-1' }, targetType: 'node' });
graph.emit('node:drag', { dx: 20, dy: 20 });
graph.emit('node:dragend');
graph.emit(NodeEvent.DRAG_START, { target: { id: 'node-1' }, targetType: 'node' });
graph.emit(NodeEvent.DRAG, { dx: 20, dy: 20 });
graph.emit(NodeEvent.DRAG_END);
expect(positionOf(graph.getNodeData('node-1'))).toEqual([120, 120, 0]);
graph.zoomTo(2);
graph.emit('node:dragstart', { target: { id: 'node-1' }, targetType: 'node' });
graph.emit('node:drag', { dx: 20, dy: 20 });
graph.emit('node:dragend');
graph.emit(NodeEvent.DRAG_START, { target: { id: 'node-1' }, targetType: 'node' });
graph.emit(NodeEvent.DRAG, { dx: 20, dy: 20 });
graph.emit(NodeEvent.DRAG_END);
expect(positionOf(graph.getNodeData('node-1'))).toEqual([130, 130, 0]);
graph.zoomTo(0.5);
graph.emit('node:dragstart', { target: { id: 'node-1' }, targetType: 'node' });
graph.emit('node:drag', { dx: 20, dy: 20 });
graph.emit('node:dragend');
graph.emit(NodeEvent.DRAG_START, { target: { id: 'node-1' }, targetType: 'node' });
graph.emit(NodeEvent.DRAG, { dx: 20, dy: 20 });
graph.emit(NodeEvent.DRAG_END);
expect(positionOf(graph.getNodeData('node-1'))).toEqual([170, 170, 0]);
graph.destroy();

View File

@ -1,25 +1,26 @@
import { pluginTooltip } from '@/__tests__/demos';
import { idOf, type Tooltip } from '@/src';
import type { Tooltip } from '@/src';
import { ComboEvent, EdgeEvent, NodeEvent, idOf } from '@/src';
import { createDemoGraph } from '@@/utils';
describe('plugin tooltip', () => {
it('node', async () => {
const graph = await createDemoGraph(pluginTooltip);
graph.emit('node:click', { targetType: 'node', target: { id: '6' } });
graph.emit(NodeEvent.CLICK, { targetType: 'node', target: { id: '6' } });
await expect(graph).toMatchSnapshot(__filename, 'node');
graph.destroy();
});
it.skip('combo', async () => {
const graph = await createDemoGraph(pluginTooltip);
graph.emit('combo:click', { targetType: 'combo', target: { id: 'a' } });
graph.emit(ComboEvent.CLICK, { targetType: 'combo', target: { id: 'a' } });
await expect(graph).toMatchSnapshot(__filename, 'combo');
graph.destroy();
});
it('edge', async () => {
const graph = await createDemoGraph(pluginTooltip);
graph.emit('edge:click', { targetType: 'edge', target: { id: idOf({ source: '0', target: '1' }) } });
graph.emit(EdgeEvent.CLICK, { targetType: 'edge', target: { id: idOf({ source: '0', target: '1' }) } });
await expect(graph).toMatchSnapshot(__filename, 'edge');
graph.destroy();
});
@ -37,7 +38,7 @@ describe('plugin tooltip', () => {
return plugin;
}),
);
graph.emit('node:pointerenter', { targetType: 'node', target: { id: '6' } });
graph.emit(NodeEvent.POINTER_ENTER, { targetType: 'node', target: { id: '6' } });
await expect(graph).toMatchSnapshot(__filename, 'hover');
graph.destroy();
});

View File

@ -10,7 +10,7 @@ import {
Rect,
} from '@antv/g';
import { isNil, isUndefined, pick } from '@antv/util';
import { NodeEvent } from '../../constants';
import { CommonEvent } from '../../constants';
import type { BaseNodeStyleProps } from './base-node';
import { BaseNode } from './base-node';
@ -55,12 +55,12 @@ export class HTML extends BaseNode<HTMLStyleProps> {
private get events() {
return [
NodeEvent.CLICK,
NodeEvent.POINTER_DOWN,
NodeEvent.POINTER_MOVE,
NodeEvent.POINTER_UP,
NodeEvent.POINTER_OVER,
NodeEvent.POINTER_LEAVE,
CommonEvent.CLICK,
CommonEvent.POINTER_DOWN,
CommonEvent.POINTER_MOVE,
CommonEvent.POINTER_UP,
CommonEvent.POINTER_OVER,
CommonEvent.POINTER_LEAVE,
];
}