Skip to content

Commit a0ff5b0

Browse files
committed
fix: resolved the issues
1 parent bf2cc68 commit a0ff5b0

3 files changed

Lines changed: 101 additions & 11 deletions

File tree

src/visualBuilder/components/FieldLocationIcon.tsx

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,20 @@ export const FieldLocationIcon = ({
7272
)}
7373
</button>
7474

75-
<button
76-
ref={moreButtonRef}
77-
className={multipleFieldToolbarButtonClasses}
78-
data-tooltip={"More"}
79-
onClick={handleMoreIconClick}
80-
>
81-
<MoreIcon />
82-
</button>
75+
76+
{
77+
fieldLocationData.apps.length > 1 && (
78+
<button
79+
ref={moreButtonRef}
80+
className={multipleFieldToolbarButtonClasses}
81+
data-tooltip={"More"}
82+
onClick={handleMoreIconClick}
83+
data-testid="field-location-more-button"
84+
>
85+
<MoreIcon />
86+
</button>
87+
)
88+
}
8389
</div>
8490
);
8591
};

src/visualBuilder/components/__test__/fieldToolbar.test.tsx

Lines changed: 85 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ import { asyncRender } from "../../../__test__/utils";
1212
import { VisualBuilderCslpEventDetails } from "../../types/visualBuilder.types";
1313
import { isFieldDisabled } from "../../utils/isFieldDisabled";
1414
import React from "preact/compat";
15+
import visualBuilderPostMessage from "../../utils/visualBuilderPostMessage";
16+
import { FieldLocationIcon } from "../FieldLocationIcon";
17+
import { VisualBuilderPostMessageEvents } from "../../utils/types/postMessage.types";
1518

1619
vi.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
});

src/visualBuilder/visualBuilder.style.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -690,8 +690,8 @@ export function visualBuilderStyles() {
690690
background-color: #8a8f99;
691691
`,
692692
"visual-builder__field-location-icons-container__app-icon": css`
693-
width: 16px;
694-
height: 16px;
693+
width: 24px;
694+
height: 24px;
695695
object-fit: cover;
696696
`,
697697
"visual-builder__field-location-app-list": css`

0 commit comments

Comments
 (0)