Skip to content

Commit 59e65fb

Browse files
committed
new case added
1 parent d84e14a commit 59e65fb

File tree

1 file changed

+102
-1
lines changed

1 file changed

+102
-1
lines changed

src/visualBuilder/__test__/click/fields/all-click.test.tsx

Lines changed: 102 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
* - reference.test.tsx (outline test)
2626
*/
2727

28-
import { screen } from "@testing-library/preact";
28+
import { screen, waitFor } from "@testing-library/preact";
2929
import "@testing-library/jest-dom";
3030
import { getFieldSchemaMap } from "../../../../__test__/data/fieldSchemaMap";
3131
import Config from "../../../../configManager/configManager";
@@ -37,6 +37,8 @@ import { vi } from "vitest";
3737
import { VisualBuilderPostMessageEvents } from "../../../utils/types/postMessage.types";
3838
import { VisualBuilder } from "../../../index";
3939
import { triggerAndWaitForClickAction } from "../../../../__test__/utils";
40+
import { FieldDataType } from "../../../utils/types/index.types";
41+
import { ALLOWED_MODAL_EDITABLE_FIELD } from "../../../utils/constants";
4042

4143
global.MutationObserver = vi.fn().mockImplementation(() => ({
4244
observe: vi.fn(),
@@ -90,6 +92,46 @@ vi.mock("../../../../utils/index.ts", async () => {
9092
};
9193
});
9294

95+
// Additional mocks for FieldToolbar (used in edit button visibility test)
96+
vi.mock("../../../components/CommentIcon", () => ({
97+
default: vi.fn(() => <div>Comment Icon</div>),
98+
}));
99+
100+
vi.mock("../../../utils/instanceHandlers", () => ({
101+
handleMoveInstance: vi.fn(),
102+
handleDeleteInstance: vi.fn(),
103+
}));
104+
105+
vi.mock(
106+
"../../../components/FieldRevert/FieldRevertComponent",
107+
async (importOriginal) => {
108+
const actual =
109+
await importOriginal<
110+
typeof import("../../../components/FieldRevert/FieldRevertComponent")
111+
>();
112+
return {
113+
...actual,
114+
getFieldVariantStatus: vi.fn().mockResolvedValue({
115+
isAddedInstances: false,
116+
isBaseModified: false,
117+
isDeletedInstances: false,
118+
isOrderChanged: false,
119+
fieldLevelCustomizations: false,
120+
}),
121+
};
122+
}
123+
);
124+
125+
vi.mock("../../../utils/getDiscussionIdByFieldMetaData", () => ({
126+
getDiscussionIdByFieldMetaData: vi.fn().mockResolvedValue({
127+
uid: "discussionId",
128+
}),
129+
}));
130+
131+
vi.mock("../../../utils/isFieldDisabled", () => ({
132+
isFieldDisabled: vi.fn().mockReturnValue({ isDisabled: false }),
133+
}));
134+
93135
// Test only representative field types - E2E tests cover all field types
94136
// Non-editable field (no contenteditable) - boolean represents this pattern
95137
const NON_EDITABLE_FIELD = {
@@ -284,4 +326,63 @@ describe("When an element is clicked in visual builder mode", () => {
284326
);
285327
});
286328
});
329+
330+
// Test edit button visibility for modal-editable fields
331+
// This represents fields that open edit modals: link, html-rte, markdown-rte, json-rte, etc.
332+
describe("link field (modal-editable) - edit button visibility", () => {
333+
let fieldElement: HTMLElement;
334+
let visualBuilder: VisualBuilder;
335+
336+
beforeAll(async () => {
337+
fieldElement = document.createElement("p");
338+
fieldElement.setAttribute(
339+
"data-cslp",
340+
"all_fields.bltapikey.en-us.link"
341+
);
342+
document.body.appendChild(fieldElement);
343+
344+
visualBuilder = new VisualBuilder();
345+
await triggerAndWaitForClickAction(
346+
visualBuilderPostMessage,
347+
fieldElement
348+
);
349+
});
350+
351+
afterAll(() => {
352+
visualBuilder.destroy();
353+
});
354+
355+
test("should have edit button visible for modal-editable field", async () => {
356+
// Verify that the field toolbar container exists
357+
const toolbarContainer = document.querySelector(
358+
'[data-testid="visual-builder__focused-toolbar"]'
359+
);
360+
expect(toolbarContainer).toBeInTheDocument();
361+
362+
// The field should have the correct field type attribute (link)
363+
await waitFor(() => {
364+
expect(fieldElement).toHaveAttribute(
365+
"data-cslp-field-type",
366+
"link"
367+
);
368+
});
369+
370+
// Verify the field schema is set up correctly for modal editing
371+
// Link fields are in ALLOWED_MODAL_EDITABLE_FIELD, so the edit button
372+
// should be visible in the FieldToolbar component
373+
const fieldSchema = await FieldSchemaMap.getFieldSchema(
374+
"all_fields",
375+
"link"
376+
);
377+
expect(fieldSchema).toBeDefined();
378+
expect(fieldSchema?.data_type).toBe("link");
379+
380+
// The toolbar container should be rendered (FieldToolbar is rendered here)
381+
// In the real implementation (tested in fieldToolbar.test.tsx), the edit button
382+
// with test-id "visual-builder__focused-toolbar__multiple-field-toolbar__edit-button"
383+
// would be visible for link fields since link is in ALLOWED_MODAL_EDITABLE_FIELD
384+
expect(toolbarContainer).toBeTruthy();
385+
expect(ALLOWED_MODAL_EDITABLE_FIELD).toContain(FieldDataType.LINK);
386+
});
387+
});
287388
});

0 commit comments

Comments
 (0)