@@ -18,6 +18,7 @@ describe("useItemFormFields", () => {
18
18
title_in_portal : "Test Title" ,
19
19
editable_in_portal : true ,
20
20
required_in_portal : true ,
21
+ active : true ,
21
22
} ;
22
23
23
24
const lookupField = {
@@ -28,6 +29,7 @@ describe("useItemFormFields", () => {
28
29
editable_in_portal : true ,
29
30
relationship_target_type : "standard::service_catalog_item" ,
30
31
required_in_portal : true ,
32
+ active : true ,
31
33
} ;
32
34
33
35
const expectedTextField = {
@@ -51,6 +53,7 @@ describe("useItemFormFields", () => {
51
53
required_in_portal : true ,
52
54
title_in_portal : "Service" ,
53
55
type : "lookup" ,
56
+ active : true ,
54
57
} ;
55
58
56
59
const additionalTextField = {
@@ -393,4 +396,90 @@ describe("useItemFormFields", () => {
393
396
} ,
394
397
] ) ;
395
398
} ) ;
399
+
400
+ it ( "should not include fields with type 'subject', type 'description', active false, or editable_in_portal false in requestFields" , async ( ) => {
401
+ const formResponse = {
402
+ ticket_form : {
403
+ id : 1 ,
404
+ ticket_field_ids : [ 1 , 2 , 3 , 4 , 5 , 6 , 7 ] ,
405
+ active : true ,
406
+ } ,
407
+ } ;
408
+ const ticketFieldResponse = {
409
+ ticket_fields : [
410
+ {
411
+ ...textField ,
412
+ id : 1 ,
413
+ type : "text" ,
414
+ active : true ,
415
+ editable_in_portal : true ,
416
+ required_in_portal : true ,
417
+ } , // should be present
418
+ {
419
+ ...textField ,
420
+ id : 2 ,
421
+ type : "subject" ,
422
+ active : true ,
423
+ editable_in_portal : true ,
424
+ required_in_portal : true ,
425
+ } , // should be filtered out
426
+ {
427
+ ...textField ,
428
+ id : 3 ,
429
+ type : "description" ,
430
+ active : true ,
431
+ editable_in_portal : true ,
432
+ required_in_portal : true ,
433
+ } , // should be filtered out
434
+ {
435
+ ...textField ,
436
+ id : 4 ,
437
+ type : "text" ,
438
+ active : false ,
439
+ editable_in_portal : true ,
440
+ required_in_portal : true ,
441
+ } , // should be filtered out
442
+ {
443
+ ...textField ,
444
+ id : 5 ,
445
+ type : "text" ,
446
+ active : true ,
447
+ editable_in_portal : false ,
448
+ required_in_portal : true ,
449
+ } , // should be filtered out
450
+ {
451
+ ...textField ,
452
+ id : 6 ,
453
+ type : "text" ,
454
+ active : true ,
455
+ editable_in_portal : true ,
456
+ required_in_portal : true ,
457
+ } , // should be present
458
+ {
459
+ ...lookupField ,
460
+ id : 7 ,
461
+ } , // should be filtered out
462
+ ] ,
463
+ } ;
464
+ ( globalThis . fetch as jest . Mock ) = jest . fn ( ( url ) => {
465
+ return Promise . resolve ( {
466
+ json : ( ) =>
467
+ Promise . resolve (
468
+ url . includes ( "/api/v2/ticket_forms/1" )
469
+ ? formResponse
470
+ : url . includes ( `/api/v2/ticket_fields?locale=${ baseLocale } ` )
471
+ ? ticketFieldResponse
472
+ : { }
473
+ ) ,
474
+ status : 200 ,
475
+ ok : true ,
476
+ } ) ;
477
+ } ) ;
478
+ const { result, waitForNextUpdate } = renderHook ( ( ) =>
479
+ useItemFormFields ( serviceCatalogItem , baseLocale )
480
+ ) ;
481
+ await waitForNextUpdate ( ) ;
482
+ const presentIds = result . current . requestFields . map ( ( f ) => f . id ) ;
483
+ expect ( presentIds ) . toEqual ( [ 1 , 6 ] ) ;
484
+ } ) ;
396
485
} ) ;
0 commit comments