|
3 | 3 | */ |
4 | 4 | import { describe, expect, it } from 'vitest' |
5 | 5 | import { |
| 6 | + applyEdgeSelectionChanges, |
6 | 7 | getArrowNavigationDirection, |
| 8 | + getEdgeSelectionMapKey, |
7 | 9 | isPositionalTriggerBlock, |
8 | 10 | reconcileCanvasEdges, |
9 | 11 | reconcileCanvasNodes, |
10 | 12 | shouldHighlightContainerDropTarget, |
11 | 13 | } from '@/app/workspace/[workspaceId]/w/[workflowId]/utils/workflow-canvas-helpers' |
12 | 14 |
|
| 15 | +describe('edge selection helpers', () => { |
| 16 | + it('keeps modifier selections and removes deselected edges', () => { |
| 17 | + const selected = new Map([['edge-1-loop-1', 'edge-1']]) |
| 18 | + const selectionKeys = new Map([ |
| 19 | + ['edge-1', 'edge-1-loop-1'], |
| 20 | + ['edge-2', 'edge-2-loop-1'], |
| 21 | + ]) |
| 22 | + |
| 23 | + const withSecondEdge = applyEdgeSelectionChanges( |
| 24 | + selected, |
| 25 | + [{ id: 'edge-2', type: 'select', selected: true }], |
| 26 | + (edgeId) => selectionKeys.get(edgeId) ?? null |
| 27 | + ) |
| 28 | + expect([...withSecondEdge]).toEqual([ |
| 29 | + ['edge-1-loop-1', 'edge-1'], |
| 30 | + ['edge-2-loop-1', 'edge-2'], |
| 31 | + ]) |
| 32 | + |
| 33 | + const withoutFirstEdge = applyEdgeSelectionChanges( |
| 34 | + withSecondEdge, |
| 35 | + [{ id: 'edge-1', type: 'select', selected: false }], |
| 36 | + (edgeId) => selectionKeys.get(edgeId) ?? null |
| 37 | + ) |
| 38 | + expect([...withoutFirstEdge]).toEqual([['edge-2-loop-1', 'edge-2']]) |
| 39 | + }) |
| 40 | + |
| 41 | + it('uses nested context keys and ignores temporary edges', () => { |
| 42 | + const key = getEdgeSelectionMapKey( |
| 43 | + { id: 'edge-1', source: 'source', target: 'target' }, |
| 44 | + [{ id: 'source', parentId: 'loop-1' }, { id: 'target' }], |
| 45 | + {} |
| 46 | + ) |
| 47 | + expect(key).toBe('edge-1-loop-1') |
| 48 | + |
| 49 | + const selected = new Map<string, string>() |
| 50 | + expect( |
| 51 | + applyEdgeSelectionChanges( |
| 52 | + selected, |
| 53 | + [{ id: 'connection-block-selector-edge', type: 'select', selected: true }], |
| 54 | + () => null |
| 55 | + ) |
| 56 | + ).toBe(selected) |
| 57 | + }) |
| 58 | +}) |
| 59 | + |
13 | 60 | describe('getArrowNavigationDirection', () => { |
14 | 61 | it('moves once for a fresh horizontal arrow press', () => { |
15 | 62 | expect( |
|
0 commit comments