diff --git a/src/visualBuilder/__test__/hover/fields/boolean.test.ts b/src/visualBuilder/__test__/hover/fields/boolean.test.ts index 725893ef..585919f9 100644 --- a/src/visualBuilder/__test__/hover/fields/boolean.test.ts +++ b/src/visualBuilder/__test__/hover/fields/boolean.test.ts @@ -6,6 +6,7 @@ import { VisualBuilder } from "../../../index"; import { FieldSchemaMap } from "../../../utils/fieldSchemaMap"; import { mockDomRect } from "./mockDomRect"; import visualBuilderPostMessage from "../../../utils/visualBuilderPostMessage"; +import { act } from "@testing-library/preact"; vi.mock("../../../utils/visualBuilderPostMessage", async () => { const { getAllContentTypes } = await vi.importActual< @@ -64,7 +65,7 @@ describe("When an element is hovered in visual builder mode", () => { let booleanField: HTMLParagraphElement; let visualBuilder: VisualBuilder; - beforeEach( async () => { + beforeEach(async () => { booleanField = document.createElement("p"); booleanField.setAttribute( "data-cslp", @@ -86,7 +87,9 @@ describe("When an element is hovered in visual builder mode", () => { }); test("should have outline and custom cursor", async () => { - booleanField.dispatchEvent(mousemoveEvent); + await act(async () => { + booleanField.dispatchEvent(mousemoveEvent); + }); await waitForHoverOutline(); expect(booleanField).toHaveAttribute("data-cslp", "all_fields.bltapikey.en-us.boolean"); expect(booleanField).not.toHaveAttribute("contenteditable"); diff --git a/src/visualBuilder/__test__/hover/fields/date.test.ts b/src/visualBuilder/__test__/hover/fields/date.test.ts index 1928983f..054c017d 100644 --- a/src/visualBuilder/__test__/hover/fields/date.test.ts +++ b/src/visualBuilder/__test__/hover/fields/date.test.ts @@ -4,6 +4,7 @@ import Config from "../../../../configManager/configManager"; import { VisualBuilder } from "../../../index"; import { FieldSchemaMap } from "../../../utils/fieldSchemaMap"; import { mockDomRect } from "./mockDomRect"; +import { act } from "@testing-library/preact"; vi.mock("../../../utils/visualBuilderPostMessage", async () => { const { getAllContentTypes } = await vi.importActual< @@ -84,7 +85,9 @@ describe("When an element is hovered in visual builder mode", () => { }); test("should have outline and custom cursor", async () => { - dataField.dispatchEvent(mousemoveEvent); + await act(async () => { + dataField.dispatchEvent(mousemoveEvent); + }); await waitForHoverOutline(); expect(dataField).toHaveAttribute("data-cslp", "all_fields.bltapikey.en-us.date"); expect(dataField).not.toHaveAttribute("contenteditable"); diff --git a/src/visualBuilder/__test__/hover/fields/file.test.ts b/src/visualBuilder/__test__/hover/fields/file.test.ts index 4879ce51..1e1d3912 100644 --- a/src/visualBuilder/__test__/hover/fields/file.test.ts +++ b/src/visualBuilder/__test__/hover/fields/file.test.ts @@ -1,4 +1,4 @@ -import { screen, waitFor } from "@testing-library/preact"; +import { screen, waitFor, act } from "@testing-library/preact"; import { getFieldSchemaMap } from "../../../../__test__/data/fieldSchemaMap"; import { waitForHoverOutline } from "../../../../__test__/utils"; import Config from "../../../../configManager/configManager"; @@ -56,7 +56,6 @@ describe("When an element is hovered in visual builder mode", () => { observe: vi.fn(), disconnect: vi.fn(), })); - }); beforeEach(() => { @@ -111,7 +110,9 @@ describe("When an element is hovered in visual builder mode", () => { }); test("should have outline and custom cursor", async () => { - fileField.dispatchEvent(mousemoveEvent); + await act(async () => { + fileField.dispatchEvent(mousemoveEvent); + }); await waitForHoverOutline(); const hoverOutline = document.querySelector( "[data-testid='visual-builder__hover-outline']" @@ -126,7 +127,9 @@ describe("When an element is hovered in visual builder mode", () => { }); test("should have a outline and custom cursor on the url as well", async () => { - imageField.dispatchEvent(mousemoveEvent); + await act(async () => { + imageField.dispatchEvent(mousemoveEvent); + }); await waitForHoverOutline(); const hoverOutline = document.querySelector( @@ -214,7 +217,9 @@ describe("When an element is hovered in visual builder mode", () => { }); test("should have outline and custom cursor", async () => { - container.dispatchEvent(mousemoveEvent); + await act(async () => { + container.dispatchEvent(mousemoveEvent); + }); await waitForHoverOutline(); const hoverOutline = document.querySelector( "[data-testid='visual-builder__hover-outline']" @@ -229,7 +234,9 @@ describe("When an element is hovered in visual builder mode", () => { }); test("should have outline and custom cursor on individual instances", async () => { - firstFileField.dispatchEvent(mousemoveEvent); + await act(async () => { + firstFileField.dispatchEvent(mousemoveEvent); + }); await waitForHoverOutline(); const hoverOutline = document.querySelector( "[data-testid='visual-builder__hover-outline']" @@ -247,7 +254,9 @@ describe("When an element is hovered in visual builder mode", () => { }); test("should have outline and custom cursor on the url", async () => { - firstImageField.dispatchEvent(mousemoveEvent); + await act(async () => { + firstImageField.dispatchEvent(mousemoveEvent); + }); await waitForHoverOutline(); const hoverOutline = document.querySelector( "[data-testid='visual-builder__hover-outline']" diff --git a/src/visualBuilder/__test__/hover/fields/group.test.ts b/src/visualBuilder/__test__/hover/fields/group.test.ts index c4dd0e47..9626054a 100644 --- a/src/visualBuilder/__test__/hover/fields/group.test.ts +++ b/src/visualBuilder/__test__/hover/fields/group.test.ts @@ -5,6 +5,7 @@ import { FieldSchemaMap } from "../../../utils/fieldSchemaMap"; import { mockDomRect } from "./mockDomRect"; import { VisualBuilder } from "../../../index"; import { screen } from "@testing-library/preact"; +import { act } from "@testing-library/preact"; vi.mock("../../../utils/visualBuilderPostMessage", async () => { const { getAllContentTypes } = await vi.importActual< @@ -96,7 +97,9 @@ describe("When an element is hovered in visual builder mode", () => { }); test("should have outline and custom cursor", async () => { - groupField.dispatchEvent(mousemoveEvent); + await act(async () => { + groupField.dispatchEvent(mousemoveEvent); + }); await waitForHoverOutline(); const hoverOutline = document.querySelector( "[data-testid='visual-builder__hover-outline']" @@ -124,7 +127,9 @@ describe("When an element is hovered in visual builder mode", () => { groupField.appendChild(singleLine); - singleLine.dispatchEvent(mousemoveEvent); + await act(async () => { + singleLine.dispatchEvent(mousemoveEvent); + }); await waitForHoverOutline(); const hoverOutline = document.querySelector( "[data-testid='visual-builder__hover-outline']" @@ -203,7 +208,9 @@ describe("When an element is hovered in visual builder mode", () => { }); test("should have outline and custom cursor", async () => { - container.dispatchEvent(mousemoveEvent); + await act(async () => { + container.dispatchEvent(mousemoveEvent); + }); await waitForHoverOutline(); const hoverOutline = document.querySelector( "[data-testid='visual-builder__hover-outline']" @@ -217,7 +224,9 @@ describe("When an element is hovered in visual builder mode", () => { expect(customCursor).toHaveAttribute('data-icon', 'group'); expect(customCursor?.classList.contains("visible")).toBeTruthy(); - firstNestedMultiLine.dispatchEvent(mousemoveEvent); + await act(async () => { + firstNestedMultiLine.dispatchEvent(mousemoveEvent); + }); await waitForHoverOutline(); const newCustomCursor = document.querySelector( diff --git a/src/visualBuilder/__test__/hover/fields/html-rte.test.ts b/src/visualBuilder/__test__/hover/fields/html-rte.test.ts index 58215f4a..f71092e5 100644 --- a/src/visualBuilder/__test__/hover/fields/html-rte.test.ts +++ b/src/visualBuilder/__test__/hover/fields/html-rte.test.ts @@ -5,6 +5,7 @@ import Config from "../../../../configManager/configManager"; import { VisualBuilder } from "../../../index"; import { FieldSchemaMap } from "../../../utils/fieldSchemaMap"; import { mockDomRect } from "./mockDomRect"; +import { act } from "@testing-library/preact"; vi.mock("../../../utils/visualBuilderPostMessage", async () => { const { getAllContentTypes } = await vi.importActual< @@ -84,7 +85,9 @@ describe("When an element is hovered in visual builder mode", () => { }); test("should have outline and custom cursor", async () => { - htmlRteField.dispatchEvent(mousemoveEvent); + await act(async () => { + htmlRteField.dispatchEvent(mousemoveEvent); + }); await waitForHoverOutline(); const hoverOutline = document.querySelector( "[data-testid='visual-builder__hover-outline']" @@ -149,7 +152,9 @@ describe("When an element is hovered in visual builder mode", () => { }); test("should have outline and custom cursor", async () => { - container.dispatchEvent(mousemoveEvent); + await act(async () => { + container.dispatchEvent(mousemoveEvent); + }); await waitForHoverOutline(); const hoverOutline = document.querySelector( "[data-testid='visual-builder__hover-outline']" @@ -165,7 +170,9 @@ describe("When an element is hovered in visual builder mode", () => { }); test("should have outline and cursor on individual instances", async () => { - firstHtmlRteField.dispatchEvent(mousemoveEvent); + await act(async () => { + firstHtmlRteField.dispatchEvent(mousemoveEvent); + }); await waitForHoverOutline(); const hoverOutline = document.querySelector( "[data-testid='visual-builder__hover-outline']" diff --git a/src/visualBuilder/__test__/hover/fields/json-rte.test.ts b/src/visualBuilder/__test__/hover/fields/json-rte.test.ts index 55188e0b..835cba9a 100644 --- a/src/visualBuilder/__test__/hover/fields/json-rte.test.ts +++ b/src/visualBuilder/__test__/hover/fields/json-rte.test.ts @@ -5,6 +5,7 @@ import Config from "../../../../configManager/configManager"; import { VisualBuilder } from "../../../index"; import { FieldSchemaMap } from "../../../utils/fieldSchemaMap"; import { mockDomRect } from "./mockDomRect"; +import { act } from "@testing-library/preact"; vi.mock("../../../utils/visualBuilderPostMessage", async () => { const { getAllContentTypes } = await vi.importActual< @@ -84,7 +85,9 @@ describe("When an element is hovered in visual builder mode", () => { }); test("should have outline and custom cursor", async () => { - jsonRteField.dispatchEvent(mousemoveEvent); + await act(async () => { + jsonRteField.dispatchEvent(mousemoveEvent); + }); await waitForHoverOutline(); const hoverOutline = document.querySelector( "[data-testid='visual-builder__hover-outline']" @@ -149,7 +152,9 @@ describe("When an element is hovered in visual builder mode", () => { }); test("should have outline and custom cursor", async () => { - container.dispatchEvent(mousemoveEvent); + await act(async () => { + container.dispatchEvent(mousemoveEvent); + }); await waitForHoverOutline(); const hoverOutline = document.querySelector( "[data-testid='visual-builder__hover-outline']" @@ -165,7 +170,9 @@ describe("When an element is hovered in visual builder mode", () => { }); test("should have outline and custom cursor on individual instances", async () => { - firstJsonRteField.dispatchEvent(mousemoveEvent); + await act(async () => { + firstJsonRteField.dispatchEvent(mousemoveEvent); + }); await waitForHoverOutline(); const hoverOutline = document.querySelector( "[data-testid='visual-builder__hover-outline']" diff --git a/src/visualBuilder/__test__/hover/fields/link.test.ts b/src/visualBuilder/__test__/hover/fields/link.test.ts index e434b937..88044fb5 100644 --- a/src/visualBuilder/__test__/hover/fields/link.test.ts +++ b/src/visualBuilder/__test__/hover/fields/link.test.ts @@ -5,6 +5,7 @@ import Config from "../../../../configManager/configManager"; import { VisualBuilder } from "../../../index"; import { FieldSchemaMap } from "../../../utils/fieldSchemaMap"; import { mockDomRect } from "./mockDomRect"; +import { act } from "@testing-library/preact"; vi.mock("../../../utils/visualBuilderPostMessage", async () => { const { getAllContentTypes } = await vi.importActual< @@ -84,7 +85,9 @@ describe("When an element is hovered in visual builder mode", () => { }); test("should have outline and custom cursor", async () => { - linkField.dispatchEvent(mousemoveEvent); + await act(async () => { + linkField.dispatchEvent(mousemoveEvent); + }); await waitForHoverOutline(); const hoverOutline = document.querySelector( "[data-testid='visual-builder__hover-outline']" @@ -146,7 +149,9 @@ describe("When an element is hovered in visual builder mode", () => { }); test("should have outline and custom cursor", async () => { - container.dispatchEvent(mousemoveEvent); + await act(async () => { + container.dispatchEvent(mousemoveEvent); + }); await waitForHoverOutline(); const hoverOutline = document.querySelector( "[data-testid='visual-builder__hover-outline']" @@ -162,7 +167,9 @@ describe("When an element is hovered in visual builder mode", () => { }); test("should have outline and custom cursor on individual instances", async () => { - firstLinkField.dispatchEvent(mousemoveEvent); + await act(async () => { + firstLinkField.dispatchEvent(mousemoveEvent); + }); await waitForHoverOutline(); const hoverOutline = document.querySelector( "[data-testid='visual-builder__hover-outline']" diff --git a/src/visualBuilder/__test__/hover/fields/markdown.test.ts b/src/visualBuilder/__test__/hover/fields/markdown.test.ts index 88ec3ec0..2595450c 100644 --- a/src/visualBuilder/__test__/hover/fields/markdown.test.ts +++ b/src/visualBuilder/__test__/hover/fields/markdown.test.ts @@ -5,6 +5,7 @@ import Config from "../../../../configManager/configManager"; import { VisualBuilder } from "../../../index"; import { FieldSchemaMap } from "../../../utils/fieldSchemaMap"; import { mockDomRect } from "./mockDomRect"; +import { act } from "@testing-library/preact"; vi.mock("../../../utils/visualBuilderPostMessage", async () => { const { getAllContentTypes } = await vi.importActual< @@ -85,7 +86,9 @@ describe("When an element is hovered in visual builder mode", () => { }); test("should have outline and custom cursor", async () => { - markdownField.dispatchEvent(mousemoveEvent); + await act(async () => { + markdownField.dispatchEvent(mousemoveEvent); + }); await waitForHoverOutline(); const hoverOutline = document.querySelector( "[data-testid='visual-builder__hover-outline']" @@ -150,7 +153,9 @@ describe("When an element is hovered in visual builder mode", () => { }); test("should have outline and custom cursor", async () => { - container.dispatchEvent(mousemoveEvent); + await act(async () => { + container.dispatchEvent(mousemoveEvent); + }); await waitForHoverOutline(); const hoverOutline = document.querySelector( "[data-testid='visual-builder__hover-outline']" @@ -166,7 +171,9 @@ describe("When an element is hovered in visual builder mode", () => { }); test("should have outline and custom cursor on individual instances", async () => { - firstMarkdownField.dispatchEvent(mousemoveEvent); + await act(async () => { + firstMarkdownField.dispatchEvent(mousemoveEvent); + }); await waitForHoverOutline(); const hoverOutline = document.querySelector( "[data-testid='visual-builder__hover-outline']" diff --git a/src/visualBuilder/__test__/hover/fields/multi-line.test.ts b/src/visualBuilder/__test__/hover/fields/multi-line.test.ts index baaec300..d47ead2e 100644 --- a/src/visualBuilder/__test__/hover/fields/multi-line.test.ts +++ b/src/visualBuilder/__test__/hover/fields/multi-line.test.ts @@ -5,6 +5,7 @@ import Config from "../../../../configManager/configManager"; import { VisualBuilder } from "../../../index"; import { FieldSchemaMap } from "../../../utils/fieldSchemaMap"; import { mockDomRect } from "./mockDomRect"; +import { act } from "@testing-library/preact"; vi.mock("../../../utils/visualBuilderPostMessage", async () => { const { getAllContentTypes } = await vi.importActual< @@ -84,7 +85,9 @@ describe("When an element is hovered in visual builder mode", () => { }); test("should have outline and custom cursor", async () => { - multiLineField.dispatchEvent(mousemoveEvent); + await act(async () => { + multiLineField.dispatchEvent(mousemoveEvent); + }); await waitForHoverOutline(); const hoverOutline = screen.getByTestId( "visual-builder__hover-outline" @@ -148,7 +151,9 @@ describe("When an element is hovered in visual builder mode", () => { }); test("should have outline and custom cursor", async () => { - container.dispatchEvent(mousemoveEvent); + await act(async () => { + container.dispatchEvent(mousemoveEvent); + }); await waitForHoverOutline(); const hoverOutline = document.querySelector( "[data-testid='visual-builder__hover-outline']" @@ -164,7 +169,9 @@ describe("When an element is hovered in visual builder mode", () => { }); test("should have outline and custom cursor on individual instances", async () => { - firstMultiLineField.dispatchEvent(mousemoveEvent); + await act(async () => { + firstMultiLineField.dispatchEvent(mousemoveEvent); + }); await waitForHoverOutline(); const hoverOutline = document.querySelector( "[data-testid='visual-builder__hover-outline']" diff --git a/src/visualBuilder/__test__/hover/fields/number.test.ts b/src/visualBuilder/__test__/hover/fields/number.test.ts index 0d57bf3d..4d4f6854 100644 --- a/src/visualBuilder/__test__/hover/fields/number.test.ts +++ b/src/visualBuilder/__test__/hover/fields/number.test.ts @@ -5,6 +5,7 @@ import Config from "../../../../configManager/configManager"; import { VisualBuilder } from "../../../index"; import { FieldSchemaMap } from "../../../utils/fieldSchemaMap"; import { mockDomRect } from "./mockDomRect"; +import { act } from "@testing-library/preact"; vi.mock("../../../utils/visualBuilderPostMessage", async () => { const { getAllContentTypes } = await vi.importActual< @@ -84,7 +85,9 @@ describe("When an element is hovered in visual builder mode", () => { }); test("should have outline and custom cursor", async () => { - numberField.dispatchEvent(mousemoveEvent); + await act(async () => { + numberField.dispatchEvent(mousemoveEvent); + }); await waitForHoverOutline(); const hoverOutline = document.querySelector( "[data-testid='visual-builder__hover-outline']" @@ -146,7 +149,9 @@ describe("When an element is hovered in visual builder mode", () => { }); test("should have outline and custom cursor", async () => { - container.dispatchEvent(mousemoveEvent); + await act(async () => { + container.dispatchEvent(mousemoveEvent); + }); await waitForHoverOutline(); const hoverOutline = document.querySelector( "[data-testid='visual-builder__hover-outline']" @@ -162,7 +167,9 @@ describe("When an element is hovered in visual builder mode", () => { }); test("should have outline and custom cursor on individual instances", async () => { - firstNumberField.dispatchEvent(mousemoveEvent); + await act(async () => { + firstNumberField.dispatchEvent(mousemoveEvent); + }); await waitForHoverOutline(); const hoverOutline = document.querySelector( "[data-testid='visual-builder__hover-outline']" diff --git a/src/visualBuilder/__test__/hover/fields/reference.test.ts b/src/visualBuilder/__test__/hover/fields/reference.test.ts index 78ef1e14..c37a5bf4 100644 --- a/src/visualBuilder/__test__/hover/fields/reference.test.ts +++ b/src/visualBuilder/__test__/hover/fields/reference.test.ts @@ -5,6 +5,7 @@ import { VisualBuilder } from "../../../index"; import { FieldSchemaMap } from "../../../utils/fieldSchemaMap"; import { mockDomRect } from "./mockDomRect"; import { screen } from "@testing-library/preact"; +import { act } from "@testing-library/preact"; vi.mock("../../../utils/visualBuilderPostMessage", async () => { const { getAllContentTypes } = await vi.importActual< @@ -84,7 +85,9 @@ describe("When an element is hovered in visual builder mode", () => { }); test("should have outline and custom cursor", async () => { - referenceField.dispatchEvent(mousemoveEvent); + await act(async () => { + referenceField.dispatchEvent(mousemoveEvent); + }); await waitForHoverOutline(); const hoverOutline = document.querySelector( @@ -149,7 +152,9 @@ describe("When an element is hovered in visual builder mode", () => { }); test("should have outline and custom cursor", async () => { - container.dispatchEvent(mousemoveEvent); + await act(async () => { + container.dispatchEvent(mousemoveEvent); + }); await waitForHoverOutline(); const hoverOutline = document.querySelector( "[data-testid='visual-builder__hover-outline']" @@ -165,7 +170,9 @@ describe("When an element is hovered in visual builder mode", () => { }); test("should have outline and custom cursor on individual instances", async () => { - firstReferenceField.dispatchEvent(mousemoveEvent); + await act(async () => { + firstReferenceField.dispatchEvent(mousemoveEvent); + }); await waitForHoverOutline(); const hoverOutline = document.querySelector( "[data-testid='visual-builder__hover-outline']" diff --git a/src/visualBuilder/__test__/hover/fields/select.test.ts b/src/visualBuilder/__test__/hover/fields/select.test.ts index d1f57152..adf80857 100644 --- a/src/visualBuilder/__test__/hover/fields/select.test.ts +++ b/src/visualBuilder/__test__/hover/fields/select.test.ts @@ -4,7 +4,7 @@ import Config from "../../../../configManager/configManager"; import { VisualBuilder } from "../../../index"; import { FieldSchemaMap } from "../../../utils/fieldSchemaMap"; import { mockDomRect } from "./mockDomRect"; -import { screen } from "@testing-library/preact"; +import { act, screen } from "@testing-library/preact"; vi.mock("../../../utils/visualBuilderPostMessage", async () => { const { getAllContentTypes } = await vi.importActual< @@ -95,7 +95,9 @@ describe("When an element is hovered in visual builder mode", () => { }); test("should have outline and custom cursor", async () => { - selectField.dispatchEvent(mousemoveEvent); + await act(async () => { + selectField.dispatchEvent(mousemoveEvent); + }); await waitForHoverOutline(); const hoverOutline = document.querySelector( "[data-testid='visual-builder__hover-outline']" @@ -159,7 +161,9 @@ describe("When an element is hovered in visual builder mode", () => { }); test("should have outline and custom cursor", async () => { - container.dispatchEvent(mousemoveEvent); + await act(async () => { + container.dispatchEvent(mousemoveEvent); + }); await waitForHoverOutline(); const hoverOutline = document.querySelector( @@ -176,7 +180,9 @@ describe("When an element is hovered in visual builder mode", () => { }); test("should have outline and custom cursor on individual instances", async () => { - firstSelectField.dispatchEvent(mousemoveEvent); + await act(async () => { + firstSelectField.dispatchEvent(mousemoveEvent); + }); await waitForHoverOutline(); const hoverOutline = document.querySelector( diff --git a/src/visualBuilder/__test__/hover/fields/single-line.test.ts b/src/visualBuilder/__test__/hover/fields/single-line.test.ts index 2be12411..14ceba69 100644 --- a/src/visualBuilder/__test__/hover/fields/single-line.test.ts +++ b/src/visualBuilder/__test__/hover/fields/single-line.test.ts @@ -4,7 +4,7 @@ import Config from "../../../../configManager/configManager"; import { VisualBuilder } from "../../../index"; import { FieldSchemaMap } from "../../../utils/fieldSchemaMap"; import { mockDomRect } from "./mockDomRect"; -import { screen } from "@testing-library/preact"; +import { act, screen } from "@testing-library/preact"; vi.mock("../../../utils/visualBuilderPostMessage", async () => { const { getAllContentTypes } = await vi.importActual< @@ -82,7 +82,9 @@ describe("When an element is hovered in visual builder mode", () => { }); test("should have outline and custom cursor", async () => { - titleField.dispatchEvent(mousemoveEvent); + await act(() => { + titleField.dispatchEvent(mousemoveEvent); + }); await waitForHoverOutline(); expect(titleField).not.toHaveAttribute("style"); const hoverOutline = screen.getByTestId( @@ -121,7 +123,9 @@ describe("When an element is hovered in visual builder mode", () => { }); test("should have outline and custom cursor", async () => { - singleLineField.dispatchEvent(mousemoveEvent); + await act(() => { + singleLineField.dispatchEvent(mousemoveEvent); + }); await waitForHoverOutline(); expect(singleLineField).not.toHaveAttribute("style"); @@ -180,6 +184,9 @@ describe("When an element is hovered in visual builder mode", () => { }); test("should have outline and custom cursor", async () => { + await act(() => { + container.dispatchEvent(mousemoveEvent); + }); container.dispatchEvent(mousemoveEvent); await waitForHoverOutline(); expect(container).not.toHaveAttribute('style'); @@ -198,7 +205,9 @@ describe("When an element is hovered in visual builder mode", () => { }); test("should have outline and custom cursor on individual instances", async () => { - firstSingleLineField.dispatchEvent(mousemoveEvent); + await act(() => { + firstSingleLineField.dispatchEvent(mousemoveEvent); + }); await waitForHoverOutline(); expect(firstSingleLineField).not.toHaveAttribute('style'); const hoverOutline = document.querySelector( diff --git a/src/visualBuilder/listeners/mouseClick.ts b/src/visualBuilder/listeners/mouseClick.ts index 7a50cf7c..d9b4a595 100644 --- a/src/visualBuilder/listeners/mouseClick.ts +++ b/src/visualBuilder/listeners/mouseClick.ts @@ -302,11 +302,20 @@ async function handleFieldSchemaAndIndividualFields( content_type_uid, fieldPath ); - const entryAcl = await getEntryPermissionsCached({ - entryUid: entry_uid, - contentTypeUid: content_type_uid, - locale, - }); + let entryAcl; + try { + entryAcl = await getEntryPermissionsCached({ + entryUid: entry_uid, + contentTypeUid: content_type_uid, + locale, + }); + } catch (error) { + console.error( + "[Visual Builder] Error retrieving entry permissions:", + error + ); + return; + } if (fieldSchema) { const { isDisabled } = isFieldDisabled( diff --git a/src/visualBuilder/listeners/mouseHover.ts b/src/visualBuilder/listeners/mouseHover.ts index 5803ec38..2495e827 100644 --- a/src/visualBuilder/listeners/mouseHover.ts +++ b/src/visualBuilder/listeners/mouseHover.ts @@ -14,6 +14,7 @@ import { VB_EmptyBlockParentClass } from "../.."; import Config from "../../configManager/configManager"; import { isCollabThread } from "../generators/generateThread"; import { getEntryPermissionsCached } from "../utils/getEntryPermissionsCached"; +import { EntryPermissions } from "../utils/getEntryPermissions"; const config = Config.get(); export interface HandleMouseHoverParams @@ -235,24 +236,36 @@ async function handleMouseHover(params: HandleMouseHoverParams): Promise { (fieldSchema) => { if (!fieldSchema) return; + let entryAcl: EntryPermissions | undefined; getEntryPermissionsCached({ entryUid: fieldMetadata.entry_uid, contentTypeUid: fieldMetadata.content_type_uid, locale: fieldMetadata.locale, - }).then((entryAcl) => { - if (!params.customCursor) return; - const { isDisabled: fieldDisabled } = isFieldDisabled( - fieldSchema, - eventDetails, - entryAcl - ); - const fieldType = getFieldType(fieldSchema); - generateCustomCursor({ - fieldType, - customCursor: params.customCursor, - fieldDisabled, + }) + .then((data) => { + entryAcl = data; + }) + .catch((error) => { + console.error( + "[Visual Builder] Error retrieving entry permissions:", + error + ); + }) + .finally(() => { + if (!params.customCursor) return; + const { isDisabled: fieldDisabled } = + isFieldDisabled( + fieldSchema, + eventDetails, + entryAcl + ); + const fieldType = getFieldType(fieldSchema); + generateCustomCursor({ + fieldType, + customCursor: params.customCursor, + fieldDisabled, + }); }); - }); } ); @@ -267,19 +280,31 @@ async function handleMouseHover(params: HandleMouseHoverParams): Promise { addOutline(editableElement); FieldSchemaMap.getFieldSchema(content_type_uid, fieldPath).then( (fieldSchema) => { + let entryAcl: EntryPermissions | undefined; if (!fieldSchema) return; getEntryPermissionsCached({ entryUid: fieldMetadata.entry_uid, contentTypeUid: fieldMetadata.content_type_uid, locale: fieldMetadata.locale, - }).then((entryAcl) => { - const { isDisabled: fieldDisabled } = isFieldDisabled( - fieldSchema, - eventDetails, - entryAcl - ); - addOutline(editableElement, fieldDisabled); - }); + }) + .then((data) => { + entryAcl = data; + }) + .catch((error) => { + console.error( + "[Visual Builder] Error retrieving entry permissions:", + error + ); + }) + .finally(() => { + const { isDisabled: fieldDisabled } = + isFieldDisabled( + fieldSchema, + eventDetails, + entryAcl + ); + addOutline(editableElement, fieldDisabled); + }); } ); }