8
8
} from '../edges' ;
9
9
import {
10
10
createOperationNode ,
11
+ createSectionBufferNode ,
12
+ createSectionInputNode ,
13
+ createSectionOutputNode ,
11
14
createTerminateNode ,
12
15
type DiagramEditorNode ,
13
16
} from '../nodes' ;
@@ -54,43 +57,22 @@ class MockReactFlowAccessor implements NodesAndEdgesAccessor {
54
57
}
55
58
56
59
describe ( 'validate edges' , ( ) => {
57
- test ( 'buffer->node is invalid' , ( ) => {
58
- const sourceNode = createOperationNode (
59
- ROOT_NAMESPACE ,
60
- undefined ,
61
- { x : 0 , y : 0 } ,
62
- { type : 'buffer' } ,
63
- 'test_op_buffer' ,
64
- ) ;
65
- const targetNode = createOperationNode (
60
+ test ( '"buffer" can only connect to operations that accepts a buffer' , ( ) => {
61
+ const node = createOperationNode (
66
62
ROOT_NAMESPACE ,
67
63
undefined ,
68
64
{ x : 0 , y : 0 } ,
69
65
{ type : 'node' , builder : 'test_builder' , next : { builtin : 'dispose' } } ,
70
66
'test_op_node' ,
71
67
) ;
72
-
73
- const validEdges = getValidEdgeTypes ( sourceNode , targetNode ) ;
74
- expect ( validEdges . length ) . toBe ( 0 ) ;
75
-
76
- const edge = createDefaultEdge ( sourceNode . id , targetNode . id ) ;
77
- const reactFlow = new MockReactFlowAccessor (
78
- [ sourceNode , targetNode ] ,
79
- [ edge ] ,
80
- ) ;
81
- const result = validateEdgeQuick ( edge , reactFlow ) ;
82
- expect ( result . valid ) . toBe ( false ) ;
83
- } ) ;
84
-
85
- test ( 'buffer->join is valid only for buffer edges' , ( ) => {
86
- const sourceNode = createOperationNode (
68
+ const buffer = createOperationNode (
87
69
ROOT_NAMESPACE ,
88
70
undefined ,
89
71
{ x : 0 , y : 0 } ,
90
72
{ type : 'buffer' } ,
91
73
'test_op_buffer' ,
92
74
) ;
93
- const targetNode = createOperationNode (
75
+ const join = createOperationNode (
94
76
ROOT_NAMESPACE ,
95
77
undefined ,
96
78
{ x : 0 , y : 0 } ,
@@ -102,47 +84,45 @@ describe('validate edges', () => {
102
84
'test_op_join' ,
103
85
) ;
104
86
105
- const validEdges = getValidEdgeTypes ( sourceNode , targetNode ) ;
106
- expect ( validEdges . length ) . toBe ( 2 ) ;
107
- expect ( validEdges ) . toContain ( 'bufferKey' ) ;
108
- expect ( validEdges ) . toContain ( 'bufferSeq' ) ;
87
+ {
88
+ // "node" does not accept buffer
89
+ const validEdges = getValidEdgeTypes ( buffer , node ) ;
90
+ expect ( validEdges . length ) . toBe ( 0 ) ;
91
+
92
+ // "buffer" does not output data ("default" edge)
93
+ const edge = createDefaultEdge ( buffer . id , join . id ) ;
94
+ const reactFlow = new MockReactFlowAccessor ( [ buffer , join ] , [ edge ] ) ;
95
+ const result = validateEdgeQuick ( edge , reactFlow ) ;
96
+ expect ( result . valid ) . toBe ( false ) ;
97
+ }
98
+
99
+ {
100
+ const validEdges = getValidEdgeTypes ( buffer , join ) ;
101
+ expect ( validEdges . length ) . toBe ( 2 ) ;
102
+ expect ( validEdges ) . toContain ( 'bufferKey' ) ;
103
+ expect ( validEdges ) . toContain ( 'bufferSeq' ) ;
104
+ }
109
105
110
106
{
111
- const edge = createBufferSeqEdge ( sourceNode . id , targetNode . id , {
107
+ const edge = createBufferSeqEdge ( buffer . id , join . id , {
112
108
seq : 0 ,
113
109
} ) ;
114
- const reactFlow = new MockReactFlowAccessor (
115
- [ sourceNode , targetNode ] ,
116
- [ edge ] ,
117
- ) ;
110
+ const reactFlow = new MockReactFlowAccessor ( [ buffer , join ] , [ edge ] ) ;
118
111
const result = validateEdgeQuick ( edge , reactFlow ) ;
119
112
expect ( result . valid ) . toBe ( true ) ;
120
113
}
121
114
122
115
{
123
- const edge = createBufferKeyEdge ( sourceNode . id , targetNode . id , {
116
+ const edge = createBufferKeyEdge ( buffer . id , join . id , {
124
117
key : 'test' ,
125
118
} ) ;
126
- const reactFlow = new MockReactFlowAccessor (
127
- [ sourceNode , targetNode ] ,
128
- [ edge ] ,
129
- ) ;
119
+ const reactFlow = new MockReactFlowAccessor ( [ buffer , join ] , [ edge ] ) ;
130
120
const result = validateEdgeQuick ( edge , reactFlow ) ;
131
121
expect ( result . valid ) . toBe ( true ) ;
132
122
}
133
-
134
- {
135
- const edge = createDefaultEdge ( sourceNode . id , targetNode . id ) ;
136
- const reactFlow = new MockReactFlowAccessor (
137
- [ sourceNode , targetNode ] ,
138
- [ edge ] ,
139
- ) ;
140
- const result = validateEdgeQuick ( edge , reactFlow ) ;
141
- expect ( result . valid ) . toBe ( false ) ;
142
- }
143
123
} ) ;
144
124
145
- test ( 'node-> buffer_access and buffer->buffer_access are valid ' , ( ) => {
125
+ test ( '" buffer_access" accepts both data and buffer edges ' , ( ) => {
146
126
const nodeNode = createOperationNode (
147
127
ROOT_NAMESPACE ,
148
128
undefined ,
@@ -178,7 +158,7 @@ describe('validate edges', () => {
178
158
}
179
159
} ) ;
180
160
181
- test ( 'node-> join and buffer->join are valid ' , ( ) => {
161
+ test ( '" join" node accepts both data and buffer edges ' , ( ) => {
182
162
const nodeNode = createOperationNode (
183
163
ROOT_NAMESPACE ,
184
164
undefined ,
@@ -223,7 +203,106 @@ describe('validate edges', () => {
223
203
}
224
204
} ) ;
225
205
226
- test ( 'node operation only allows 1 output' , ( ) => {
206
+ test ( '"sectionInput" can only connect to operations that accepts data' , ( ) => {
207
+ const sectionInput = createSectionInputNode (
208
+ 'test_section_input' ,
209
+ 'test_section_input' ,
210
+ { x : 0 , y : 0 } ,
211
+ ) ;
212
+ const node = createOperationNode (
213
+ ROOT_NAMESPACE ,
214
+ undefined ,
215
+ { x : 0 , y : 0 } ,
216
+ { type : 'node' , builder : 'test_builder' , next : { builtin : 'dispose' } } ,
217
+ 'test_op_node' ,
218
+ ) ;
219
+ const listen = createOperationNode (
220
+ ROOT_NAMESPACE ,
221
+ undefined ,
222
+ { x : 0 , y : 0 } ,
223
+ { type : 'listen' , buffers : [ ] , next : { builtin : 'dispose' } } ,
224
+ 'test_op_listen' ,
225
+ ) ;
226
+
227
+ {
228
+ const validEdges = getValidEdgeTypes ( sectionInput , node ) ;
229
+ expect ( validEdges . length ) . toBe ( 1 ) ;
230
+ expect ( validEdges ) . toContain ( 'default' ) ;
231
+ }
232
+
233
+ {
234
+ const validEdges = getValidEdgeTypes ( sectionInput , listen ) ;
235
+ expect ( validEdges . length ) . toBe ( 0 ) ;
236
+ }
237
+ } ) ;
238
+
239
+ test ( '"sectionBuffer" can only connect to operations that accepts buffer' , ( ) => {
240
+ const sectionBuffer = createSectionBufferNode (
241
+ 'test_section_buffer' ,
242
+ 'test_section_buffer' ,
243
+ { x : 0 , y : 0 } ,
244
+ ) ;
245
+ const node = createOperationNode (
246
+ ROOT_NAMESPACE ,
247
+ undefined ,
248
+ { x : 0 , y : 0 } ,
249
+ { type : 'node' , builder : 'test_builder' , next : { builtin : 'dispose' } } ,
250
+ 'test_op_node' ,
251
+ ) ;
252
+ const listen = createOperationNode (
253
+ ROOT_NAMESPACE ,
254
+ undefined ,
255
+ { x : 0 , y : 0 } ,
256
+ { type : 'listen' , buffers : [ ] , next : { builtin : 'dispose' } } ,
257
+ 'test_op_listen' ,
258
+ ) ;
259
+
260
+ {
261
+ const validEdges = getValidEdgeTypes ( sectionBuffer , node ) ;
262
+ expect ( validEdges . length ) . toBe ( 0 ) ;
263
+ }
264
+
265
+ {
266
+ const validEdges = getValidEdgeTypes ( sectionBuffer , listen ) ;
267
+ expect ( validEdges . length ) . toBe ( 2 ) ;
268
+ expect ( validEdges ) . toContain ( 'bufferKey' ) ;
269
+ expect ( validEdges ) . toContain ( 'bufferSeq' ) ;
270
+ }
271
+ } ) ;
272
+
273
+ test ( '"sectionOutput" only accepts data edges' , ( ) => {
274
+ const sectionOutput = createSectionOutputNode ( 'test_section_output' , {
275
+ x : 0 ,
276
+ y : 0 ,
277
+ } ) ;
278
+ const node = createOperationNode (
279
+ ROOT_NAMESPACE ,
280
+ undefined ,
281
+ { x : 0 , y : 0 } ,
282
+ { type : 'node' , builder : 'test_builder' , next : { builtin : 'dispose' } } ,
283
+ 'test_op_node' ,
284
+ ) ;
285
+ const buffer = createOperationNode (
286
+ ROOT_NAMESPACE ,
287
+ undefined ,
288
+ { x : 0 , y : 0 } ,
289
+ { type : 'buffer' , buffers : [ ] } ,
290
+ 'test_op_buffer' ,
291
+ ) ;
292
+
293
+ {
294
+ const validEdges = getValidEdgeTypes ( node , sectionOutput ) ;
295
+ expect ( validEdges . length ) . toBe ( 1 ) ;
296
+ expect ( validEdges ) . toContain ( 'default' ) ;
297
+ }
298
+
299
+ {
300
+ const validEdges = getValidEdgeTypes ( buffer , sectionOutput ) ;
301
+ expect ( validEdges . length ) . toBe ( 0 ) ;
302
+ }
303
+ } ) ;
304
+
305
+ test ( '"node" operation only allows 1 output' , ( ) => {
227
306
const nodeNode = createOperationNode (
228
307
ROOT_NAMESPACE ,
229
308
undefined ,
@@ -262,7 +341,7 @@ describe('validate edges', () => {
262
341
}
263
342
} ) ;
264
343
265
- test ( 'fork clone operation allows multiple outputs' , ( ) => {
344
+ test ( '"fork_clone" operation allows multiple outputs' , ( ) => {
266
345
const forkCloneNode = createOperationNode (
267
346
ROOT_NAMESPACE ,
268
347
undefined ,
@@ -288,7 +367,7 @@ describe('validate edges', () => {
288
367
}
289
368
} ) ;
290
369
291
- test ( 'fork result operation only allows 2 outputs' , ( ) => {
370
+ test ( '"fork_result" operation only allows 2 outputs' , ( ) => {
292
371
const forkResultNode = createOperationNode (
293
372
ROOT_NAMESPACE ,
294
373
undefined ,
0 commit comments