@@ -185,4 +185,100 @@ describe('Document', () =>
185185 nodeGraph . delete ( ) ;
186186 doc . delete ( ) ;
187187 } ) ;
188+
189+ // Sample node graph for defintion tests
190+ function create_sample_graph ( )
191+ {
192+ const doc = mx . createDocument ( ) ;
193+
194+ // Create a node graph with a single image node and output.
195+ const nodeGraph = doc . addNodeGraph ( 'NG_wrapper' ) ;
196+ expect ( doc . getNodeGraphs ( ) . length ) . to . equal ( 1 ) ;
197+ const image = nodeGraph . addNode ( 'image' ) ;
198+ const nodes = nodeGraph . getNodes ( ) ;
199+ expect ( nodes . length ) . to . equal ( 1 ) ;
200+ expect ( nodes [ 0 ] ) . to . eql ( image ) ;
201+
202+ image . setInputValueString ( 'file' , 'image1.png' , 'filename' ) ;
203+ const input = image . getInput ( 'file' ) ;
204+ expect ( input ) . to . not . be . null ;
205+
206+ const output = nodeGraph . addOutput ( ) ;
207+ const outputs = nodeGraph . getOutputs ( ) ;
208+ expect ( outputs . length ) . to . equal ( 1 ) ;
209+ expect ( outputs [ 0 ] ) . to . eql ( output ) ;
210+
211+ // Verify the graph is valid
212+ expect ( doc . validate ( ) ) . to . be . true ;
213+ return { doc, nodeGraph } ;
214+ }
215+
216+ it ( 'Create NodeDef from NodeGraph with child implementation' , ( ) =>
217+ {
218+ const { doc, nodeGraph } = create_sample_graph ( ) ;
219+
220+ // Create DefinitionOptions with addImplementationAsChild set to true
221+ const options = new mx . DefinitionOptions ( ) ;
222+ options . addImplementationAsChild = true ;
223+
224+ // Create NodeDef from the NodeGraph with embedded implementation
225+ const nodeDef = doc . addNodeDefFromGraph (
226+ nodeGraph ,
227+ 'ND_wrapper' ,
228+ 'texture' ,
229+ 'NG_wrapper' ,
230+ options
231+ ) ;
232+
233+ expect ( nodeDef ) . to . exist ;
234+
235+ // Verify the implementation was created as a child of the nodedef
236+ const impl = nodeDef . getImplementation ( ) ;
237+ expect ( impl ) . to . exist ;
238+ expect ( impl . isANodeGraph ( ) )
239+ expect ( impl . getName ( ) ) . to . equal ( 'NG_wrapper' ) ;
240+
241+ // Verify the implementation matches the original node graph
242+ let diff_options = new mx . ElementEquivalenceOptions ( ) ;
243+ let differences = { } ;
244+ options . performValueComparisons = false ;
245+ let result = impl . isEquivalent ( nodeGraph , diff_options , differences ) ;
246+ expect ( result ) . to . be . true ;
247+
248+ // Cleanup
249+ diff_options . delete ( ) ;
250+ options . delete ( ) ;
251+ doc . delete ( ) ;
252+ } ) ;
253+
254+ it ( 'Create NodeDef from NodeGraph with referencing implementation' , ( ) =>
255+ {
256+ const { doc, nodeGraph } = create_sample_graph ( ) ;
257+
258+ // Create DefinitionOptions with addImplementationAsChild set to true
259+ const options = new mx . DefinitionOptions ( ) ;
260+ options . addImplementationAsChild = false
261+
262+ const nodeDef2 = doc . addNodeDefFromGraph (
263+ nodeGraph ,
264+ 'ND_wrapper_2' ,
265+ 'texture' ,
266+ 'NG_wrapper_2' ,
267+ options
268+ ) ;
269+
270+ expect ( nodeDef2 ) . to . exist ;
271+
272+ // Verify the implementation was created as a referenced implementation
273+ const impl2 = nodeDef2 . getImplementation ( ) ;
274+ expect ( impl2 ) . to . exist ;
275+ expect ( impl2 . isANodeGraph ( ) )
276+ expect ( impl2 . getName ( ) ) . to . equal ( 'NG_wrapper_2' ) ;
277+ const nodedef_string = impl2 . getNodeDefString ( ) ;
278+ expect ( nodedef_string ) . to . equal ( 'ND_wrapper_2' ) ;
279+
280+ // Cleanup
281+ options . delete ( ) ;
282+ doc . delete ( ) ;
283+ } ) ;
188284} ) ;
0 commit comments