1+ var should = require ( "should" ) ;
2+ var editorGraph = require ( "../lib/editor-graph" ) ;
3+
4+ function createEditorRed ( nodes , links ) {
5+ return {
6+ _ : function ( key , args ) {
7+ if ( key === "components.message.returnWithoutStart" ) {
8+ return key + ":" + args . inNodeLength ;
9+ }
10+ return key ;
11+ } ,
12+ nodes : {
13+ node : function ( id ) {
14+ return nodes [ id ] || null ;
15+ } ,
16+ eachLink : function ( callback ) {
17+ links . forEach ( callback ) ;
18+ }
19+ }
20+ } ;
21+ }
22+
23+ describe ( "editor graph helpers" , function ( ) {
24+ it ( "should validate component_out through junction links" , function ( ) {
25+ var red = createEditorRed (
26+ {
27+ in01 : { id : "in01" , type : "component_in" } ,
28+ junction01 : { id : "junction01" , type : "junction" } ,
29+ ret01 : { id : "ret01" , type : "component_out" }
30+ } ,
31+ [
32+ { source : { id : "in01" } , target : { id : "junction01" } } ,
33+ { source : { id : "junction01" } , target : { id : "ret01" } }
34+ ]
35+ ) ;
36+
37+ editorGraph . getComponentReturnValidationResult ( red , { id : "ret01" } ) . should . eql ( {
38+ codes : [ ] ,
39+ message : ""
40+ } ) ;
41+ } ) ;
42+
43+ it ( "should ignore malformed links while finding start nodes" , function ( ) {
44+ var red = createEditorRed (
45+ {
46+ in01 : { id : "in01" , type : "component_in" } ,
47+ junction01 : { id : "junction01" , type : "junction" } ,
48+ ret01 : { id : "ret01" , type : "component_out" }
49+ } ,
50+ [
51+ { source : { id : "in01" } , target : { id : "junction01" } } ,
52+ { source : "junction01" , target : "ret01" } ,
53+ { source : undefined , target : { id : "ret01" } } ,
54+ { source : { id : "missing" } , target : null }
55+ ]
56+ ) ;
57+
58+ Array . from ( editorGraph . findStartNodes ( red , "ret01" ) ) . should . eql ( [ "in01" ] ) ;
59+ } ) ;
60+
61+ it ( "should report multiple component starts as invalid" , function ( ) {
62+ var red = createEditorRed (
63+ {
64+ in01 : { id : "in01" , type : "component_in" } ,
65+ in02 : { id : "in02" , type : "component_in" } ,
66+ junction01 : { id : "junction01" , type : "junction" } ,
67+ ret01 : { id : "ret01" , type : "component_out" }
68+ } ,
69+ [
70+ { source : { id : "in01" } , target : { id : "junction01" } } ,
71+ { source : { id : "in02" } , target : { id : "junction01" } } ,
72+ { source : { id : "junction01" } , target : { id : "ret01" } }
73+ ]
74+ ) ;
75+
76+ editorGraph . getComponentReturnValidationResult ( red , { id : "ret01" } ) . should . eql ( {
77+ codes : [ "tooManyStartNodes" ] ,
78+ message : "components.message.returnWithoutStart:2"
79+ } ) ;
80+ } ) ;
81+ } ) ;
0 commit comments