@@ -2,7 +2,7 @@ import { describe, expect } from 'vitest'
22import { DataHubNodeType , DataPolicyData , OperationData , SchemaType , StrategyType , ValidatorType } from '../types.ts'
33import { getNodeId , getNodePayload , isValidPolicyConnection } from './node.utils.ts'
44import { MOCK_JSONSCHEMA_SCHEMA } from '../__test-utils__/schema.mocks.ts'
5- import { Node } from 'reactflow'
5+ import { Edge , Node } from 'reactflow'
66import { MOCK_DEFAULT_NODE } from '@/__test-utils__/react-flow/nodes.ts'
77
88describe ( 'getNodeId' , ( ) => {
@@ -70,7 +70,7 @@ describe('getNodePayload', () => {
7070describe ( 'isValidPolicyConnection' , ( ) => {
7171 it ( 'should not be a valid connection with an unknown source' , async ( ) => {
7272 expect (
73- isValidPolicyConnection ( { source : 'source' , target : 'target' , sourceHandle : null , targetHandle : null } , [ ] )
73+ isValidPolicyConnection ( { source : 'source' , target : 'target' , sourceHandle : null , targetHandle : null } , [ ] , [ ] )
7474 ) . toBeFalsy ( )
7575 } )
7676
@@ -82,9 +82,11 @@ describe('isValidPolicyConnection', () => {
8282 position : { x : 0 , y : 0 } ,
8383 }
8484 expect (
85- isValidPolicyConnection ( { source : 'node-id' , target : 'target' , sourceHandle : null , targetHandle : null } , [
86- MOCK_NODE_DATA_POLICY ,
87- ] )
85+ isValidPolicyConnection (
86+ { source : 'node-id' , target : 'target' , sourceHandle : null , targetHandle : null } ,
87+ [ MOCK_NODE_DATA_POLICY ] ,
88+ [ ]
89+ )
8890 ) . toBeFalsy ( )
8991 } )
9092
@@ -97,9 +99,11 @@ describe('isValidPolicyConnection', () => {
9799 position : { x : 0 , y : 0 } ,
98100 }
99101 expect (
100- isValidPolicyConnection ( { source : 'node-id' , target : 'target' , sourceHandle : null , targetHandle : null } , [
101- MOCK_NODE_DATA_POLICY ,
102- ] )
102+ isValidPolicyConnection (
103+ { source : 'node-id' , target : 'target' , sourceHandle : null , targetHandle : null } ,
104+ [ MOCK_NODE_DATA_POLICY ] ,
105+ [ ]
106+ )
103107 ) . toBeFalsy ( )
104108 } )
105109
@@ -120,10 +124,11 @@ describe('isValidPolicyConnection', () => {
120124 position : { x : 0 , y : 0 } ,
121125 }
122126 expect (
123- isValidPolicyConnection ( { source : 'node-id' , target : 'node-operation' , sourceHandle : null , targetHandle : null } , [
124- MOCK_NODE_DATA_POLICY ,
125- MOCK_NODE_OPERATION ,
126- ] )
127+ isValidPolicyConnection (
128+ { source : 'node-id' , target : 'node-operation' , sourceHandle : null , targetHandle : null } ,
129+ [ MOCK_NODE_DATA_POLICY , MOCK_NODE_OPERATION ] ,
130+ [ ]
131+ )
127132 ) . toBeTruthy ( )
128133 } )
129134
@@ -151,7 +156,8 @@ describe('isValidPolicyConnection', () => {
151156 sourceHandle : null ,
152157 targetHandle : OperationData . Handle . SCHEMA ,
153158 } ,
154- [ MOCK_NODE_DATA_POLICY , MOCK_NODE_OPERATION ]
159+ [ MOCK_NODE_DATA_POLICY , MOCK_NODE_OPERATION ] ,
160+ [ ]
155161 )
156162 ) . toBeTruthy ( )
157163
@@ -163,7 +169,75 @@ describe('isValidPolicyConnection', () => {
163169 sourceHandle : null ,
164170 targetHandle : DataPolicyData . Handle . ON_SUCCESS ,
165171 } ,
166- [ MOCK_NODE_DATA_POLICY , MOCK_NODE_OPERATION ]
172+ [ MOCK_NODE_DATA_POLICY , MOCK_NODE_OPERATION ] ,
173+ [ ]
174+ )
175+ ) . toBeFalsy ( )
176+ } )
177+
178+ it ( 'should not be a valid connection if self-referencing' , async ( ) => {
179+ const MOCK_NODE_OPERATION : Node = {
180+ id : 'node-operation' ,
181+ type : DataHubNodeType . OPERATION ,
182+ data : { } ,
183+ ...MOCK_DEFAULT_NODE ,
184+ position : { x : 0 , y : 0 } ,
185+ }
186+ expect (
187+ isValidPolicyConnection (
188+ {
189+ source : 'node-operation' ,
190+ target : 'node-operation' ,
191+ sourceHandle : null ,
192+ targetHandle : null ,
193+ } ,
194+ [ MOCK_NODE_OPERATION ] ,
195+ [ ]
196+ )
197+ ) . toBeFalsy ( )
198+ } )
199+
200+ it ( 'should not be a valid connection if creating a cycle' , async ( ) => {
201+ const MOCK_NODE_OPERATION : Node = {
202+ id : 'node-operation' ,
203+ type : DataHubNodeType . OPERATION ,
204+ data : { } ,
205+ ...MOCK_DEFAULT_NODE ,
206+ position : { x : 0 , y : 0 } ,
207+ }
208+
209+ const nodes : Node [ ] = [
210+ MOCK_NODE_OPERATION ,
211+ { ...MOCK_NODE_OPERATION , id : 'node-operation-1' } ,
212+ { ...MOCK_NODE_OPERATION , id : 'node-operation-2' } ,
213+ ]
214+ const edges : Edge [ ] = [
215+ { id : '1' , source : 'node-operation' , target : 'node-operation-1' , sourceHandle : null , targetHandle : null } ,
216+ { id : '1' , source : 'node-operation-1' , target : 'node-operation-2' , sourceHandle : null , targetHandle : null } ,
217+ ]
218+
219+ expect (
220+ isValidPolicyConnection (
221+ {
222+ source : 'node-operation-1' ,
223+ target : 'node-operation' ,
224+ sourceHandle : null ,
225+ targetHandle : null ,
226+ } ,
227+ nodes ,
228+ edges
229+ )
230+ ) . toBeFalsy ( )
231+ expect (
232+ isValidPolicyConnection (
233+ {
234+ source : 'node-operation-2' ,
235+ target : 'node-operation' ,
236+ sourceHandle : null ,
237+ targetHandle : null ,
238+ } ,
239+ nodes ,
240+ edges
167241 )
168242 ) . toBeFalsy ( )
169243 } )
0 commit comments