@@ -8,15 +8,29 @@ import type { IComboWidget } from '@/lib/litegraph/src/types/widgets'
8
8
function createMockNode (
9
9
nodeTypeName : string ,
10
10
widgets : Array < { name : string ; value : any } > = [ ] ,
11
- isApiNode = true
11
+ isApiNode = true ,
12
+ inputs : Array < {
13
+ name : string
14
+ connected ?: boolean
15
+ useLinksArray ?: boolean
16
+ } > = [ ]
12
17
) : LGraphNode {
13
18
const mockWidgets = widgets . map ( ( { name, value } ) => ( {
14
19
name,
15
20
value,
16
21
type : 'combo'
17
22
} ) ) as IComboWidget [ ]
18
23
19
- return {
24
+ const mockInputs =
25
+ inputs . length > 0
26
+ ? inputs . map ( ( { name, connected, useLinksArray } ) =>
27
+ useLinksArray
28
+ ? { name, links : connected ? [ 1 ] : [ ] }
29
+ : { name, link : connected ? 1 : null }
30
+ )
31
+ : undefined
32
+
33
+ const node : any = {
20
34
id : Math . random ( ) . toString ( ) ,
21
35
widgets : mockWidgets ,
22
36
constructor : {
@@ -25,7 +39,24 @@ function createMockNode(
25
39
api_node : isApiNode
26
40
}
27
41
}
28
- } as unknown as LGraphNode
42
+ }
43
+
44
+ if ( mockInputs ) {
45
+ node . inputs = mockInputs
46
+ // Provide the common helpers some frontend code may call
47
+ node . findInputSlot = function ( portName : string ) {
48
+ return this . inputs ?. findIndex ( ( i : any ) => i . name === portName ) ?? - 1
49
+ }
50
+ node . isInputConnected = function ( idx : number ) {
51
+ const port = this . inputs ?. [ idx ]
52
+ if ( ! port ) return false
53
+ if ( typeof port . link !== 'undefined' ) return port . link != null
54
+ if ( Array . isArray ( port . links ) ) return port . links . length > 0
55
+ return false
56
+ }
57
+ }
58
+
59
+ return node as LGraphNode
29
60
}
30
61
31
62
describe ( 'useNodePricing' , ( ) => {
@@ -363,34 +394,51 @@ describe('useNodePricing', () => {
363
394
} )
364
395
365
396
describe ( 'dynamic pricing - IdeogramV3' , ( ) => {
366
- it ( 'should return $0.09 for Quality rendering speed' , ( ) => {
367
- const { getNodeDisplayPrice } = useNodePricing ( )
368
- const node = createMockNode ( 'IdeogramV3' , [
369
- { name : 'rendering_speed' , value : 'Quality' }
370
- ] )
371
-
372
- const price = getNodeDisplayPrice ( node )
373
- expect ( price ) . toBe ( '$0.09/Run' )
374
- } )
375
-
376
- it ( 'should return $0.06 for Balanced rendering speed' , ( ) => {
377
- const { getNodeDisplayPrice } = useNodePricing ( )
378
- const node = createMockNode ( 'IdeogramV3' , [
379
- { name : 'rendering_speed' , value : 'Balanced' }
380
- ] )
381
-
382
- const price = getNodeDisplayPrice ( node )
383
- expect ( price ) . toBe ( '$0.06/Run' )
384
- } )
385
-
386
- it ( 'should return $0.03 for Turbo rendering speed' , ( ) => {
387
- const { getNodeDisplayPrice } = useNodePricing ( )
388
- const node = createMockNode ( 'IdeogramV3' , [
389
- { name : 'rendering_speed' , value : 'Turbo' }
390
- ] )
391
-
392
- const price = getNodeDisplayPrice ( node )
393
- expect ( price ) . toBe ( '$0.03/Run' )
397
+ it ( 'should return correct prices for IdeogramV3 node' , ( ) => {
398
+ const { getNodeDisplayPrice } = useNodePricing ( )
399
+
400
+ const testCases = [
401
+ {
402
+ rendering_speed : 'Quality' ,
403
+ character_image : false ,
404
+ expected : '$0.09/Run'
405
+ } ,
406
+ {
407
+ rendering_speed : 'Quality' ,
408
+ character_image : true ,
409
+ expected : '$0.20/Run'
410
+ } ,
411
+ {
412
+ rendering_speed : 'Default' ,
413
+ character_image : false ,
414
+ expected : '$0.06/Run'
415
+ } ,
416
+ {
417
+ rendering_speed : 'Default' ,
418
+ character_image : true ,
419
+ expected : '$0.15/Run'
420
+ } ,
421
+ {
422
+ rendering_speed : 'Turbo' ,
423
+ character_image : false ,
424
+ expected : '$0.03/Run'
425
+ } ,
426
+ {
427
+ rendering_speed : 'Turbo' ,
428
+ character_image : true ,
429
+ expected : '$0.10/Run'
430
+ }
431
+ ]
432
+
433
+ testCases . forEach ( ( { rendering_speed, character_image, expected } ) => {
434
+ const node = createMockNode (
435
+ 'IdeogramV3' ,
436
+ [ { name : 'rendering_speed' , value : rendering_speed } ] ,
437
+ true ,
438
+ [ { name : 'character_image' , connected : character_image } ]
439
+ )
440
+ expect ( getNodeDisplayPrice ( node ) ) . toBe ( expected )
441
+ } )
394
442
} )
395
443
396
444
it ( 'should return range when rendering_speed widget is missing' , ( ) => {
@@ -935,7 +983,11 @@ describe('useNodePricing', () => {
935
983
const { getRelevantWidgetNames } = useNodePricing ( )
936
984
937
985
const widgetNames = getRelevantWidgetNames ( 'IdeogramV3' )
938
- expect ( widgetNames ) . toEqual ( [ 'rendering_speed' , 'num_images' ] )
986
+ expect ( widgetNames ) . toEqual ( [
987
+ 'rendering_speed' ,
988
+ 'num_images' ,
989
+ 'character_image'
990
+ ] )
939
991
} )
940
992
} )
941
993
0 commit comments