Skip to content

Commit d31a114

Browse files
committed
add more connection tests
Signed-off-by: Teo Koon Peng <[email protected]>
1 parent 5fdc12f commit d31a114

File tree

6 files changed

+95
-11
lines changed

6 files changed

+95
-11
lines changed

diagram-editor/frontend/edges/buffer-edge.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { type EdgeProps, StepEdge } from '@xyflow/react';
2+
import { memo } from 'react';
23
import type { Edge } from '../types/react-flow';
34
import type { SectionBufferSlotData } from './section-edge';
4-
import { memo } from 'react';
55

66
export type BufferKeySlotData = {
77
type: 'bufferKey';

diagram-editor/frontend/edges/create-edge.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { MarkerType } from '@xyflow/react';
22
import { v4 as uuidv4 } from 'uuid';
33
import type { DiagramEditorEdge, EdgeOutputData } from '.';
44
import type { BufferKeySlotData, BufferSeqSlotData } from './buffer-edge';
5+
import type { DefaultEdge } from './default-edge';
6+
import type { SectionBufferSlotData } from './section-edge';
57

68
export function createBaseEdge(
79
source: string,
@@ -14,20 +16,21 @@ export function createBaseEdge(
1416
target,
1517
markerEnd: {
1618
type: MarkerType.ArrowClosed,
17-
width: 24,
18-
height: 24,
19+
width: 20,
20+
height: 20,
1921
},
2022
};
2123
}
2224

2325
export function createDefaultEdge(
2426
source: string,
2527
target: string,
28+
inputSlot?: DefaultEdge['data']['input'],
2629
): DiagramEditorEdge<'default'> {
2730
return {
2831
...createBaseEdge(source, target),
2932
type: 'default',
30-
data: { output: {}, input: { type: 'default' } },
33+
data: { output: {}, input: inputSlot || { type: 'default' } },
3134
};
3235
}
3336

@@ -106,7 +109,7 @@ export function createSplitRemainingEdge(
106109
export function createBufferEdge(
107110
source: string,
108111
target: string,
109-
data: BufferKeySlotData | BufferSeqSlotData,
112+
data: BufferKeySlotData | BufferSeqSlotData | SectionBufferSlotData,
110113
): DiagramEditorEdge<'buffer'> {
111114
return {
112115
...createBaseEdge(source, target),

diagram-editor/frontend/edges/default-edge.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import { type EdgeProps, StepEdge } from '@xyflow/react';
22
import { memo } from 'react';
33
import type { DataEdge } from '.';
44

5-
export type DefaultOutputData = Record<string, never>;
5+
export type DefaultEdgeOutputData = Record<string, never>;
66

7-
export type DefaultEdge = DataEdge<DefaultOutputData, 'default'>;
7+
export type DefaultEdge = DataEdge<DefaultEdgeOutputData, 'default'>;
88

99
export type DefaultEdgeCompProps = Omit<EdgeProps<DefaultEdge>, 'label'>;
1010

diagram-editor/frontend/edges/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ export type { SplitSeqEdge } from './split-seq-edge';
2929
export type { StreamOutEdge } from './stream-out-edge';
3030
export type { UnzipEdge } from './unzip-edge';
3131

32-
export type DefaultInputData = { type: 'default' };
32+
export type DefaultInputSlotData = { type: 'default' };
3333

3434
export type DataEdge<
3535
O extends Record<string, unknown>,
3636
S extends string,
37-
> = Edge<O, DefaultInputData | SectionInputSlotData, S>;
37+
> = Edge<O, DefaultInputSlotData | SectionInputSlotData, S>;
3838

3939
export type EdgeMapping = {
4040
default: DefaultEdge;

diagram-editor/frontend/edges/stream-out-edge.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import { type EdgeProps, StepEdge } from '@xyflow/react';
22
import { memo } from 'react';
33
import type { Edge } from '../types/react-flow';
4-
import type { DefaultInputData } from '.';
4+
import type { DefaultInputSlotData } from '.';
55

66
export type StreamOutOutputData = {
77
name: string;
88
};
99

1010
export type StreamOutEdge = Edge<
1111
StreamOutOutputData,
12-
DefaultInputData,
12+
DefaultInputSlotData,
1313
'streamOut'
1414
>;
1515

diagram-editor/frontend/utils/connection.test.ts

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,4 +411,85 @@ describe('validate edges', () => {
411411
expect(result.valid).toBe(false);
412412
}
413413
});
414+
415+
test('buffer edges connecting to a section must have "sectionBuffer" input', () => {
416+
const bufferNode = createOperationNode(
417+
ROOT_NAMESPACE,
418+
undefined,
419+
{ x: 0, y: 0 },
420+
{
421+
type: 'buffer',
422+
},
423+
'test_op_buffer',
424+
);
425+
const sectionNode = createOperationNode(
426+
ROOT_NAMESPACE,
427+
undefined,
428+
{ x: 0, y: 0 },
429+
{ type: 'section', builder: 'test_section' },
430+
'test_op_section',
431+
);
432+
433+
{
434+
const reactFlow = new MockReactFlowAccessor(
435+
[bufferNode, sectionNode],
436+
[],
437+
);
438+
const edge = createBufferEdge(bufferNode.id, sectionNode.id, {
439+
type: 'bufferSeq',
440+
seq: 0,
441+
});
442+
const result = validateEdgeSimple(edge, reactFlow);
443+
expect(result.valid).toBe(false);
444+
}
445+
{
446+
const reactFlow = new MockReactFlowAccessor(
447+
[bufferNode, sectionNode],
448+
[],
449+
);
450+
const edge = createBufferEdge(bufferNode.id, sectionNode.id, {
451+
type: 'sectionBuffer',
452+
inputId: 'test',
453+
});
454+
const result = validateEdgeSimple(edge, reactFlow);
455+
expect(result.valid).toBe(true);
456+
}
457+
});
458+
459+
test('data edges connecting to a section must have "sectionInput" input', () => {
460+
const nodeNode = createOperationNode(
461+
ROOT_NAMESPACE,
462+
undefined,
463+
{ x: 0, y: 0 },
464+
{
465+
type: 'node',
466+
builder: 'test_builder',
467+
next: { builtin: 'dispose' },
468+
},
469+
'test_op_node',
470+
);
471+
const sectionNode = createOperationNode(
472+
ROOT_NAMESPACE,
473+
undefined,
474+
{ x: 0, y: 0 },
475+
{ type: 'section', builder: 'test_section' },
476+
'test_op_section',
477+
);
478+
479+
{
480+
const reactFlow = new MockReactFlowAccessor([nodeNode, sectionNode], []);
481+
const edge = createDefaultEdge(nodeNode.id, sectionNode.id);
482+
const result = validateEdgeSimple(edge, reactFlow);
483+
expect(result.valid).toBe(false);
484+
}
485+
{
486+
const reactFlow = new MockReactFlowAccessor([nodeNode, sectionNode], []);
487+
const edge = createDefaultEdge(nodeNode.id, sectionNode.id, {
488+
type: 'sectionInput',
489+
inputId: 'test',
490+
});
491+
const result = validateEdgeSimple(edge, reactFlow);
492+
expect(result.valid).toBe(true);
493+
}
494+
});
414495
});

0 commit comments

Comments
 (0)