-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
366 additions
and
0 deletions.
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
packages/g6/__tests__/bugs/behaviors-click-select-drag-node.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { CommonEvent, NodeEvent } from '@/src'; | ||
import { createGraph } from '@@/utils'; | ||
|
||
describe('behavior drag-node with click select', () => { | ||
const createDemoGraph = async () => { | ||
const graph = createGraph({ | ||
data: { | ||
nodes: [ | ||
{ id: 'node-1', style: { x: 100, y: 100 } }, | ||
{ id: 'node-2', combo: 'combo-1', style: { x: 200, y: 100 } }, | ||
{ id: 'node-3', style: { x: 100, y: 200 } }, | ||
{ id: 'node-4', combo: 'combo-1', style: { x: 200, y: 200 } }, | ||
], | ||
edges: [ | ||
{ source: 'node-1', target: 'node-2' }, | ||
{ source: 'node-2', target: 'node-4' }, | ||
{ source: 'node-1', target: 'node-3' }, | ||
{ source: 'node-3', target: 'node-4' }, | ||
], | ||
combos: [{ id: 'combo-1' }], | ||
}, | ||
node: { style: { size: 20 } }, | ||
edge: { | ||
style: { endArrow: true }, | ||
}, | ||
behaviors: [{ type: 'drag-element' }, { type: 'click-select', multiple: true }], | ||
}); | ||
await graph.render(); | ||
return graph; | ||
}; | ||
|
||
it('drag unselected node', async () => { | ||
const graph = await createDemoGraph(); | ||
|
||
graph.emit(NodeEvent.CLICK, { target: { id: 'node-1' }, targetType: 'node' }); | ||
|
||
await expect(graph).toMatchSnapshot(__filename, 'click-node-1'); | ||
|
||
// drag node-2 | ||
graph.emit(NodeEvent.DRAG_START, { target: { id: 'node-2' }, targetType: 'node' }); | ||
graph.emit(NodeEvent.DRAG, { dx: 20, dy: 20 }); | ||
graph.emit(NodeEvent.DRAG_END); | ||
|
||
await expect(graph).toMatchSnapshot(__filename, 'drag-node-2'); | ||
}); | ||
|
||
it('drag selected node', async () => { | ||
const graph = await createDemoGraph(); | ||
|
||
graph.emit(CommonEvent.KEY_DOWN, { key: 'shift' }); | ||
graph.emit(NodeEvent.CLICK, { target: { id: 'node-1' }, targetType: 'node' }); | ||
graph.emit(NodeEvent.CLICK, { target: { id: 'node-2' }, targetType: 'node' }); | ||
graph.emit(CommonEvent.KEY_UP, { key: 'shift' }); | ||
|
||
await expect(graph).toMatchSnapshot(__filename, 'click-node-1-node-2'); | ||
|
||
// drag node-2 | ||
graph.emit(NodeEvent.DRAG_START, { target: { id: 'node-2' }, targetType: 'node' }); | ||
graph.emit(NodeEvent.DRAG, { dx: 20, dy: 20 }); | ||
graph.emit(NodeEvent.DRAG_END); | ||
|
||
await expect(graph).toMatchSnapshot(__filename, 'drag-node-1-node-2'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
...tests__/snapshots/bugs/behaviors-click-select-drag-node/click-node-1-node-2.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
73 changes: 73 additions & 0 deletions
73
...s/g6/__tests__/snapshots/bugs/behaviors-click-select-drag-node/click-node-1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
76 changes: 76 additions & 0 deletions
76
..._tests__/snapshots/bugs/behaviors-click-select-drag-node/drag-node-1-node-2.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
73 changes: 73 additions & 0 deletions
73
...es/g6/__tests__/snapshots/bugs/behaviors-click-select-drag-node/drag-node-2.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.