@@ -12,6 +12,9 @@ import { asyncRender } from "../../../__test__/utils";
1212import { VisualBuilderCslpEventDetails } from "../../types/visualBuilder.types" ;
1313import { isFieldDisabled } from "../../utils/isFieldDisabled" ;
1414import React from "preact/compat" ;
15+ import visualBuilderPostMessage from "../../utils/visualBuilderPostMessage" ;
16+ import { FieldLocationIcon } from "../FieldLocationIcon" ;
17+ import { VisualBuilderPostMessageEvents } from "../../utils/types/postMessage.types" ;
1518
1619vi . mock ( "../../utils/instanceHandlers" , ( ) => ( {
1720 handleMoveInstance : vi . fn ( ) ,
@@ -182,7 +185,7 @@ describe("FieldToolbarComponent", () => {
182185 test ( "display variant icon instead of dropdown" , async ( ) => {
183186 mockEventDetails . fieldMetadata . variant = "variant" ;
184187 const { findByTestId } = await asyncRender (
185- < FieldToolbarComponent eventDetails = { mockEventDetails } />
188+ < FieldToolbarComponent eventDetails = { mockEventDetails } hideOverlay = { vi . fn ( ) } />
186189 ) ;
187190
188191 const variantIcon = await findByTestId (
@@ -301,4 +304,85 @@ describe("FieldToolbarComponent", () => {
301304 expect ( replaceButton ) . toBeDisabled ( ) ;
302305 }
303306 } ) ;
307+
308+ describe ( "Field Location Dropdown" , ( ) => {
309+
310+
311+
312+ test ( "FieldLocationIcon shows dropdown icon when multiple apps are available" , async ( ) => {
313+ const mockFieldLocationData = {
314+ apps : [
315+ {
316+ uid : "app1" ,
317+ title : "First App" ,
318+ icon : "icon1.png" ,
319+ app_installation_uid : "install1"
320+ } ,
321+ {
322+ uid : "app2" ,
323+ title : "Second App" ,
324+ icon : "icon2.png" ,
325+ app_installation_uid : "install2"
326+ }
327+ ]
328+ } ;
329+
330+ const mockHandleMoreIconClick = vi . fn ( ) ;
331+ const mockButtonRef = { current : null } ;
332+ const mockToolbarRef = { current : null } ;
333+
334+ const { container } = await asyncRender (
335+ < FieldLocationIcon
336+ fieldLocationData = { mockFieldLocationData }
337+ multipleFieldToolbarButtonClasses = "mock-button-class"
338+ handleMoreIconClick = { mockHandleMoreIconClick }
339+ moreButtonRef = { mockButtonRef }
340+ toolbarRef = { mockToolbarRef }
341+ />
342+ ) ;
343+
344+ const appIcon = container . querySelector ( '[data-testid="field-location-icon"]' ) ;
345+ expect ( appIcon ) . toBeInTheDocument ( ) ;
346+
347+ const moreButton = container . querySelector ( '[data-testid="field-location-more-button"]' ) ;
348+ expect ( moreButton ) . toBeInTheDocument ( ) ;
349+
350+ fireEvent . click ( moreButton ! ) ;
351+ expect ( mockHandleMoreIconClick ) . toHaveBeenCalledTimes ( 1 ) ;
352+ } ) ;
353+
354+ test ( "FieldLocationIcon does not show dropdown icon when only one app is available" , async ( ) => {
355+ const mockFieldLocationData = {
356+ apps : [
357+ {
358+ uid : "app1" ,
359+ title : "First App" ,
360+ icon : "icon1.png" ,
361+ app_installation_uid : "install1"
362+ }
363+ ]
364+ } ;
365+
366+ const mockHandleMoreIconClick = vi . fn ( ) ;
367+ const mockButtonRef = { current : null } ;
368+ const mockToolbarRef = { current : null } ;
369+
370+ const { container } = await asyncRender (
371+ < FieldLocationIcon
372+ fieldLocationData = { mockFieldLocationData }
373+ multipleFieldToolbarButtonClasses = "mock-button-class"
374+ handleMoreIconClick = { mockHandleMoreIconClick }
375+ moreButtonRef = { mockButtonRef }
376+ toolbarRef = { mockToolbarRef }
377+ />
378+ ) ;
379+
380+ const appIcon = container . querySelector ( '[data-testid="field-location-icon"]' ) ;
381+ expect ( appIcon ) . toBeInTheDocument ( ) ;
382+
383+ const moreButton = container . querySelector ( '[data-testid="field-location-more-button"]' ) ;
384+ expect ( moreButton ) . not . toBeInTheDocument ( ) ;
385+ } ) ;
386+
387+ } ) ;
304388} ) ;
0 commit comments