11import { describe , expect , test } from 'vitest'
22
3+ import type { ISerialisedGraph } from '@/lib/litegraph/src/litegraph'
34import { LGraph , LGraphNode , LiteGraph } from '@/lib/litegraph/src/litegraph'
45import { usePreviewExposureStore } from '@/stores/previewExposureStore'
56import { renameWidget } from '@/utils/widgetUtil'
@@ -37,16 +38,20 @@ describe('LGraph.configure clears graph-scoped stores for the incoming id', () =
3738 return { graph, node }
3839 }
3940
41+ function serializeToJson ( graph : LGraph ) : ISerialisedGraph {
42+ return JSON . parse ( JSON . stringify ( graph . serialize ( ) ) ) as ISerialisedGraph
43+ }
44+
4045 test ( 'a reloaded widget label is read from the payload, never inherited from the live store' , ( ) => {
4146 const graph = new LGraph ( )
4247 const dropped = addLabelledNode ( graph , 'Dropped Label' )
4348 const kept = addLabelledNode ( graph , 'Kept Label' )
4449
45- const payload = JSON . parse ( JSON . stringify ( graph . serialize ( ) ) )
50+ const payload = serializeToJson ( graph )
4651 const droppedData = payload . nodes . find (
47- ( n : { id : unknown } ) => String ( n . id ) === String ( dropped . id )
48- )
49- delete droppedData . inputs [ 0 ] . label
52+ ( n ) => String ( n . id ) === String ( dropped . id )
53+ ) !
54+ delete droppedData . inputs ! [ 0 ] . label
5055
5156 const restored = new LGraph ( )
5257 restored . configure ( payload )
@@ -63,7 +68,7 @@ describe('LGraph.configure clears graph-scoped stores for the incoming id', () =
6368 { sourceNodeId : '1' , sourcePreviewName : 'preview' , name : 'preview' }
6469 ] )
6570
66- const payload = JSON . parse ( JSON . stringify ( graph . serialize ( ) ) )
71+ const payload = serializeToJson ( graph )
6772
6873 const restored = new LGraph ( )
6974 restored . configure ( payload )
0 commit comments