@@ -18,6 +18,8 @@ import FieldToolbarComponent from "../FieldToolbar";
1818import {
1919 mockMultipleLinkFieldSchema ,
2020 mockMultipleFileFieldSchema ,
21+ mockMultipleCustomFieldSchema ,
22+ mockSingleCustomFieldSchema ,
2123} from "../../../__test__/data/fields" ;
2224import { VisualBuilderCslpEventDetails } from "../../types/visualBuilder.types" ;
2325import { isFieldDisabled } from "../../utils/isFieldDisabled" ;
@@ -355,6 +357,119 @@ describe("FieldToolbarComponent", () => {
355357 } ) ;
356358 } ) ;
357359
360+ describe ( "Custom field multiple — toolbar visibility" , ( ) => {
361+ const customFieldInstanceMetadata : CslpData = {
362+ ...mockMultipleFieldMetadata ,
363+ fieldPathWithIndex : "custom_field" ,
364+ multipleFieldMetadata : {
365+ index : 0 ,
366+ parentDetails : {
367+ parentPath : "custom_field" ,
368+ parentCslpValue : "entry.ct.en-us" ,
369+ } ,
370+ } ,
371+ instance : { fieldPathWithIndex : "custom_field.0" } ,
372+ } ;
373+
374+ const customFieldWholeMetadata : CslpData = {
375+ ...mockMultipleFieldMetadata ,
376+ fieldPathWithIndex : "custom_field" ,
377+ instance : { fieldPathWithIndex : "custom_field" } ,
378+ } ;
379+
380+ test ( "renders nothing for a multiple custom field instance" , async ( ) => {
381+ vi . mocked ( FieldSchemaMap . getFieldSchema ) . mockImplementation ( ( ) =>
382+ Promise . resolve ( mockMultipleCustomFieldSchema )
383+ ) ;
384+
385+ const { container } = render (
386+ < FieldToolbarComponent
387+ eventDetails = { {
388+ ...mockEventDetails ,
389+ fieldMetadata : customFieldInstanceMetadata ,
390+ } }
391+ hideOverlay = { vi . fn ( ) }
392+ />
393+ ) ;
394+
395+ await act ( async ( ) => {
396+ await new Promise ( ( r ) => setTimeout ( r , 0 ) ) ;
397+ } ) ;
398+
399+ expect (
400+ container . querySelector (
401+ '[data-testid="visual-builder__focused-toolbar__multiple-field-toolbar"]'
402+ )
403+ ) . not . toBeInTheDocument ( ) ;
404+ } ) ;
405+
406+ test ( "shows edit button for a multiple custom field whole-field selection" , async ( ) => {
407+ vi . mocked ( FieldSchemaMap . getFieldSchema ) . mockImplementation ( ( ) =>
408+ Promise . resolve ( mockMultipleCustomFieldSchema )
409+ ) ;
410+
411+ const { container } = render (
412+ < FieldToolbarComponent
413+ eventDetails = { {
414+ ...mockEventDetails ,
415+ fieldMetadata : customFieldWholeMetadata ,
416+ } }
417+ hideOverlay = { vi . fn ( ) }
418+ />
419+ ) ;
420+
421+ await act ( async ( ) => {
422+ await new Promise ( ( r ) => setTimeout ( r , 0 ) ) ;
423+ } ) ;
424+
425+ const editButton = await findByTestId (
426+ container ,
427+ "visual-builder__focused-toolbar__multiple-field-toolbar__edit-button" ,
428+ { } ,
429+ { timeout : 1000 }
430+ ) ;
431+ expect ( editButton ) . toBeInTheDocument ( ) ;
432+ } ) ;
433+
434+ test ( "shows edit button for a single (non-multiple) custom field" , async ( ) => {
435+ vi . mocked ( FieldSchemaMap . getFieldSchema ) . mockImplementation ( ( ) =>
436+ Promise . resolve ( mockSingleCustomFieldSchema )
437+ ) ;
438+
439+ const singleCustomFieldMetadata : CslpData = {
440+ ...mockMultipleFieldMetadata ,
441+ fieldPathWithIndex : "custom_field" ,
442+ multipleFieldMetadata : {
443+ index : - 1 ,
444+ parentDetails : null ,
445+ } ,
446+ instance : { fieldPathWithIndex : "custom_field" } ,
447+ } ;
448+
449+ const { container } = render (
450+ < FieldToolbarComponent
451+ eventDetails = { {
452+ ...mockEventDetails ,
453+ fieldMetadata : singleCustomFieldMetadata ,
454+ } }
455+ hideOverlay = { vi . fn ( ) }
456+ />
457+ ) ;
458+
459+ await act ( async ( ) => {
460+ await new Promise ( ( r ) => setTimeout ( r , 0 ) ) ;
461+ } ) ;
462+
463+ const editButton = await findByTestId (
464+ container ,
465+ "visual-builder__focused-toolbar__multiple-field-toolbar__edit-button" ,
466+ { } ,
467+ { timeout : 1000 }
468+ ) ;
469+ expect ( editButton ) . toBeInTheDocument ( ) ;
470+ } ) ;
471+ } ) ;
472+
358473 describe ( "'Replace button' visibility for multiple file fields" , ( ) => {
359474 beforeEach ( ( ) => {
360475 // Override the mock for this describe block - resolve immediately
0 commit comments