-
Notifications
You must be signed in to change notification settings - Fork 8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(editor): Add selection navigation using the keyboard on new canvas #11679
Merged
alexgrozav
merged 3 commits into
master
from
cat-322-change-arrow-keys-behaviour-to-be-consistent-with-old-canvas
Nov 18, 2024
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
180 changes: 180 additions & 0 deletions
180
packages/editor-ui/src/composables/useCanvasTraversal.test.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,180 @@ | ||
import { useCanvasTraversal } from '@/composables/useCanvasTraversal'; | ||
import type { CanvasNode } from '@/types'; | ||
import type { VueFlowStore } from '@vue-flow/core'; | ||
import { mock } from 'vitest-mock-extended'; | ||
|
||
describe('useCanvasTraversal', () => { | ||
const mockGetIncomers = vi.fn(); | ||
const mockGetOutgoers = vi.fn(); | ||
|
||
const vueFlow = mock<VueFlowStore>({ | ||
getIncomers: mockGetIncomers, | ||
getOutgoers: mockGetOutgoers, | ||
}); | ||
|
||
const { | ||
sortNodesByVerticalPosition, | ||
getIncomingNodes, | ||
getOutgoingNodes, | ||
getSiblingNodes, | ||
getDownstreamNodes, | ||
getUpstreamNodes, | ||
} = useCanvasTraversal(vueFlow); | ||
|
||
describe('sortNodesByVerticalPosition', () => { | ||
it('should sort nodes by their vertical position', () => { | ||
const nodes: CanvasNode[] = [ | ||
{ id: '1', position: { x: 0, y: 200 } }, | ||
{ id: '2', position: { x: 0, y: 100 } }, | ||
]; | ||
const result = sortNodesByVerticalPosition(nodes); | ||
expect(result).toEqual([ | ||
{ id: '2', position: { x: 0, y: 100 } }, | ||
{ id: '1', position: { x: 0, y: 200 } }, | ||
]); | ||
}); | ||
}); | ||
|
||
describe('getIncomingNodes', () => { | ||
it('should return sorted incoming nodes by vertical position', () => { | ||
const incomingNodes = [ | ||
{ id: '1', position: { x: 0, y: 200 } }, | ||
{ id: '2', position: { x: 0, y: 100 } }, | ||
]; | ||
mockGetIncomers.mockReturnValue([...incomingNodes]); | ||
const result = getIncomingNodes('3'); | ||
expect(result).toEqual([incomingNodes[1], incomingNodes[0]]); | ||
}); | ||
}); | ||
|
||
describe('getOutgoingNodes', () => { | ||
it('should return sorted outgoing nodes by vertical position', () => { | ||
const outgoingNodes = [ | ||
{ id: '1', position: { x: 0, y: 300 } }, | ||
{ id: '2', position: { x: 0, y: 150 } }, | ||
]; | ||
mockGetOutgoers.mockReturnValue([...outgoingNodes]); | ||
const result = getOutgoingNodes('3'); | ||
expect(result).toEqual([outgoingNodes[1], outgoingNodes[0]]); | ||
}); | ||
}); | ||
|
||
describe('getSiblingNodes', () => { | ||
it('should return sorted sibling nodes by vertical position', () => { | ||
const incomingNodes = [{ id: '1', position: { x: 0, y: 200 } }]; | ||
const incomingNodesOutgoingChildren = [{ id: '2', position: { x: 0, y: 400 } }]; | ||
const outgoingNodes = [{ id: '3', position: { x: 0, y: 300 } }]; | ||
const outgoingNodesIncomingChildren = [{ id: '4', position: { x: 0, y: 500 } }]; | ||
|
||
mockGetIncomers.mockReturnValueOnce(incomingNodes); | ||
mockGetOutgoers.mockReturnValueOnce(incomingNodesOutgoingChildren); | ||
mockGetOutgoers.mockReturnValueOnce(outgoingNodes); | ||
mockGetIncomers.mockReturnValueOnce(outgoingNodesIncomingChildren); | ||
|
||
const result = getSiblingNodes('5'); | ||
expect(result).toEqual([...incomingNodesOutgoingChildren, ...outgoingNodesIncomingChildren]); | ||
}); | ||
}); | ||
|
||
describe('getDownstreamNodes', () => { | ||
it('should return sorted downstream nodes by vertical position - one level', () => { | ||
const outgoingNodes = [{ id: '2', position: { x: 0, y: 100 } }]; | ||
|
||
mockGetOutgoers.mockReturnValue(outgoingNodes); | ||
|
||
const result = getDownstreamNodes('1'); | ||
expect(result).toEqual([{ id: '2', position: { x: 0, y: 100 } }]); | ||
}); | ||
|
||
it('should return sorted downstream nodes by vertical position - multiple levels', () => { | ||
const outgoingNodes1 = [{ id: '1', position: { x: 0, y: 100 } }]; | ||
const outgoingNodes2 = [{ id: '2', position: { x: 0, y: 200 } }]; | ||
const outgoingNodes3 = [{ id: '3', position: { x: 0, y: 300 } }]; | ||
|
||
mockGetOutgoers | ||
.mockReturnValueOnce(outgoingNodes1) | ||
.mockReturnValueOnce(outgoingNodes2) | ||
.mockReturnValueOnce(outgoingNodes3); | ||
|
||
const result = getDownstreamNodes('4'); | ||
expect(result).toEqual([...outgoingNodes1, ...outgoingNodes2, ...outgoingNodes3]); | ||
}); | ||
|
||
it('should handle circular references in downstream nodes', () => { | ||
const outgoingNodes1 = [{ id: '1', position: { x: 0, y: 100 } }]; | ||
const outgoingNodes2 = [ | ||
{ id: '1', position: { x: 0, y: 100 } }, | ||
{ id: '2', position: { x: 0, y: 300 } }, | ||
{ id: '3', position: { x: 0, y: 400 } }, | ||
]; | ||
const outgoingNodes3 = [ | ||
{ id: '1', position: { x: 0, y: 100 } }, | ||
{ id: '4', position: { x: 0, y: 600 } }, | ||
]; | ||
|
||
mockGetOutgoers | ||
.mockReturnValueOnce(outgoingNodes1) | ||
.mockReturnValueOnce(outgoingNodes2) | ||
.mockReturnValueOnce(outgoingNodes3); | ||
|
||
const result = getDownstreamNodes('5'); | ||
expect(result).toEqual([ | ||
outgoingNodes1[0], | ||
outgoingNodes2[1], | ||
outgoingNodes2[2], | ||
outgoingNodes3[1], | ||
]); | ||
}); | ||
}); | ||
|
||
describe('getUpstreamNodes', () => { | ||
it('should return sorted upstream nodes by vertical position - one level', () => { | ||
const incomingNodes = [{ id: '2', position: { x: 0, y: 100 } }]; | ||
|
||
mockGetIncomers.mockReturnValue(incomingNodes); | ||
|
||
const result = getUpstreamNodes('1'); | ||
expect(result).toEqual([{ id: '2', position: { x: 0, y: 100 } }]); | ||
}); | ||
|
||
it('should return sorted upstream nodes by vertical position - multiple levels', () => { | ||
const incomingNodes1 = [{ id: '1', position: { x: 0, y: 100 } }]; | ||
const incomingNodes2 = [{ id: '2', position: { x: 0, y: 200 } }]; | ||
const incomingNodes3 = [{ id: '3', position: { x: 0, y: 300 } }]; | ||
|
||
mockGetIncomers | ||
.mockReturnValueOnce(incomingNodes1) | ||
.mockReturnValueOnce(incomingNodes2) | ||
.mockReturnValueOnce(incomingNodes3); | ||
|
||
const result = getUpstreamNodes('4'); | ||
expect(result).toEqual([...incomingNodes1, ...incomingNodes2, ...incomingNodes3]); | ||
}); | ||
|
||
it('should handle circular references in upstream nodes', () => { | ||
const incomingNodes1 = [{ id: '1', position: { x: 0, y: 100 } }]; | ||
const incomingNodes2 = [ | ||
{ id: '1', position: { x: 0, y: 100 } }, | ||
{ id: '2', position: { x: 0, y: 300 } }, | ||
{ id: '3', position: { x: 0, y: 400 } }, | ||
]; | ||
const incomingNodes3 = [ | ||
{ id: '1', position: { x: 0, y: 100 } }, | ||
{ id: '4', position: { x: 0, y: 600 } }, | ||
]; | ||
|
||
mockGetIncomers | ||
.mockReturnValueOnce(incomingNodes1) | ||
.mockReturnValueOnce(incomingNodes2) | ||
.mockReturnValueOnce(incomingNodes3); | ||
|
||
const result = getUpstreamNodes('5'); | ||
expect(result).toEqual([ | ||
incomingNodes1[0], | ||
incomingNodes2[1], | ||
incomingNodes2[2], | ||
incomingNodes3[1], | ||
]); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this expected?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, position listener got changed.