@@ -62,11 +62,44 @@ describe('LayoutTreeCrawler', () => {
6262 } ;
6363
6464 const node : any = { type : LayoutType . Component , data : { name : 'theComponentName' } } ;
65- store . setOriginalComponentClassForName ( 'theComponentName' , MyComponent ) ;
65+ store . setComponentClassForName ( 'theComponentName' , ( ) => MyComponent ) ;
6666 uut . crawl ( node ) ;
6767 expect ( node . data . options ) . toEqual ( theStyle ) ;
6868 } ) ;
6969
70+ it ( 'Components: crawl does not cache options' , ( ) => {
71+ const optionsWithTitle = ( title ) => {
72+ return {
73+ topBar : {
74+ title : {
75+ text : title
76+ }
77+ }
78+ }
79+ } ;
80+
81+ const MyComponent = class {
82+ static options ( props ) {
83+ return {
84+ topBar : {
85+ title : {
86+ text : props . title
87+ }
88+ }
89+ } ;
90+ }
91+ } ;
92+
93+ const node : any = { type : LayoutType . Component , data : { name : 'theComponentName' , passProps : { title : 'title' } } } ;
94+ store . setComponentClassForName ( 'theComponentName' , ( ) => MyComponent ) ;
95+ uut . crawl ( node ) ;
96+ expect ( node . data . options ) . toEqual ( optionsWithTitle ( 'title' ) ) ;
97+
98+ const node2 : any = { type : LayoutType . Component , data : { name : 'theComponentName' } } ;
99+ uut . crawl ( node2 ) ;
100+ expect ( node2 . data . options ) . toEqual ( optionsWithTitle ( undefined ) ) ;
101+ } ) ;
102+
70103 it ( 'Components: passes passProps to the static options function to be used by the user' , ( ) => {
71104 const MyComponent = class {
72105 static options ( passProps ) {
@@ -75,7 +108,7 @@ describe('LayoutTreeCrawler', () => {
75108 } ;
76109
77110 const node : any = { type : LayoutType . Component , data : { name : 'theComponentName' , passProps : { bar : { baz : { value : 'hello' } } } } } ;
78- store . setOriginalComponentClassForName ( 'theComponentName' , MyComponent ) ;
111+ store . setComponentClassForName ( 'theComponentName' , ( ) => MyComponent ) ;
79112 uut . crawl ( node ) ;
80113 expect ( node . data . options ) . toEqual ( { foo : 'hello' } ) ;
81114 } ) ;
@@ -88,7 +121,7 @@ describe('LayoutTreeCrawler', () => {
88121 } ;
89122
90123 const node : any = { type : LayoutType . Component , data : { name : 'theComponentName' } } ;
91- store . setOriginalComponentClassForName ( 'theComponentName' , MyComponent ) ;
124+ store . setComponentClassForName ( 'theComponentName' , ( ) => MyComponent ) ;
92125 uut . crawl ( node ) ;
93126 expect ( node . data . options ) . toEqual ( { foo : { } } ) ;
94127 } ) ;
@@ -116,7 +149,7 @@ describe('LayoutTreeCrawler', () => {
116149 } ;
117150
118151 const node = { type : LayoutType . Component , data : { name : 'theComponentName' , options : passedOptions } } ;
119- store . setOriginalComponentClassForName ( 'theComponentName' , MyComponent ) ;
152+ store . setComponentClassForName ( 'theComponentName' , ( ) => MyComponent ) ;
120153
121154 uut . crawl ( node ) ;
122155
@@ -139,7 +172,7 @@ describe('LayoutTreeCrawler', () => {
139172 } ;
140173
141174 const node : any = { type : LayoutType . Component , data : { name : 'theComponentName' } } ;
142- store . setOriginalComponentClassForName ( 'theComponentName' , MyComponent ) ;
175+ store . setComponentClassForName ( 'theComponentName' , ( ) => MyComponent ) ;
143176 uut . crawl ( node ) ;
144177 expect ( node . data . options ) . not . toBe ( theStyle ) ;
145178 } ) ;
@@ -153,7 +186,7 @@ describe('LayoutTreeCrawler', () => {
153186 const MyComponent = class { } ;
154187
155188 const node : any = { type : LayoutType . Component , data : { name : 'theComponentName' } } ;
156- store . setOriginalComponentClassForName ( 'theComponentName' , MyComponent ) ;
189+ store . setComponentClassForName ( 'theComponentName' , ( ) => MyComponent ) ;
157190 uut . crawl ( node ) ;
158191 expect ( node . data . options ) . toEqual ( { } ) ;
159192 } ) ;
0 commit comments