-
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.
fix(behaviors): fix click-select lost preset states (#6161)
Co-authored-by: antv <[email protected]>
- Loading branch information
Showing
7 changed files
with
204 additions
and
3 deletions.
There are no files selected for viewing
108 changes: 108 additions & 0 deletions
108
packages/g6/__tests__/bugs/element-custom-state-switch.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,108 @@ | ||
import { createGraph } from '@@/utils'; | ||
import { CanvasEvent, CommonEvent, NodeEvent } from '@antv/g6'; | ||
|
||
describe('bug: element-custom-state-switch', () => { | ||
it('single select', async () => { | ||
const graph = createGraph({ | ||
data: { | ||
nodes: [{ id: 'node-1', states: ['important'], style: { x: 100, y: 100 } }], | ||
}, | ||
node: { | ||
style: { | ||
fill: 'red', | ||
}, | ||
state: { | ||
important: { | ||
fill: 'green', | ||
}, | ||
}, | ||
}, | ||
behaviors: [ | ||
{ | ||
type: 'click-select', | ||
}, | ||
], | ||
}); | ||
|
||
await graph.draw(); | ||
|
||
await expect(graph).toMatchSnapshot(__filename, 'single'); | ||
|
||
expect(graph.getElementState('node-1')).toEqual(['important']); | ||
|
||
// click | ||
graph.emit(NodeEvent.CLICK, { target: { id: 'node-1' }, targetType: 'node' }); | ||
|
||
expect(graph.getElementState('node-1')).toEqual(['important', 'selected']); | ||
|
||
await expect(graph).toMatchSnapshot(__filename, 'single-select'); | ||
|
||
// click again | ||
graph.emit(NodeEvent.CLICK, { target: { id: 'node-1' }, targetType: 'node' }); | ||
|
||
expect(graph.getElementState('node-1')).toEqual(['important']); | ||
|
||
await expect(graph).toMatchSnapshot(__filename, 'single'); | ||
}); | ||
|
||
it('multiple select', async () => { | ||
const graph = createGraph({ | ||
data: { | ||
nodes: [ | ||
{ id: 'node-1', states: ['important'], style: { x: 100, y: 100 } }, | ||
{ id: 'node-2', style: { x: 150, y: 100 } }, | ||
], | ||
}, | ||
node: { | ||
style: { | ||
fill: 'red', | ||
}, | ||
state: { | ||
important: { | ||
fill: 'green', | ||
}, | ||
}, | ||
}, | ||
behaviors: [ | ||
{ | ||
type: 'click-select', | ||
multiple: true, | ||
}, | ||
], | ||
}); | ||
|
||
await graph.draw(); | ||
|
||
await expect(graph).toMatchSnapshot(__filename, 'multiple'); | ||
|
||
graph.emit(NodeEvent.CLICK, { target: { id: 'node-2' }, targetType: 'node' }); | ||
graph.emit(CommonEvent.KEY_DOWN, { key: 'shift' }); | ||
graph.emit(NodeEvent.CLICK, { target: { id: 'node-1' }, targetType: 'node' }); | ||
// graph.emit(CommonEvent.KEY_UP, { key: 'shift' }); | ||
|
||
expect(graph.getElementState('node-1')).toEqual(['important', 'selected']); | ||
expect(graph.getElementState('node-2')).toEqual(['selected']); | ||
|
||
await expect(graph).toMatchSnapshot(__filename, 'multiple-select'); | ||
|
||
// unselect | ||
graph.emit(NodeEvent.CLICK, { target: { id: 'node-1' }, targetType: 'node' }); | ||
expect(graph.getElementState('node-1')).toEqual(['important']); | ||
graph.emit(NodeEvent.CLICK, { target: { id: 'node-2' }, targetType: 'node' }); | ||
expect(graph.getElementState('node-2')).toEqual([]); | ||
|
||
await expect(graph).toMatchSnapshot(__filename, 'multiple'); | ||
|
||
// reselect | ||
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' }); | ||
|
||
// click canvas | ||
graph.emit(CanvasEvent.CLICK); | ||
expect(graph.getElementState('node-1')).toEqual(['important']); | ||
expect(graph.getElementState('node-2')).toEqual([]); | ||
|
||
await expect(graph).toMatchSnapshot(__filename, 'multiple-unselect'); | ||
}); | ||
}); |
25 changes: 25 additions & 0 deletions
25
...ges/g6/__tests__/snapshots/bugs/element-custom-state-switch/multiple-select.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions
19
...s/g6/__tests__/snapshots/bugs/element-custom-state-switch/multiple-unselect.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions
19
packages/g6/__tests__/snapshots/bugs/element-custom-state-switch/multiple.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions
17
packages/g6/__tests__/snapshots/bugs/element-custom-state-switch/single-select.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions
14
packages/g6/__tests__/snapshots/bugs/element-custom-state-switch/single.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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