From bd4424bbe3e853798b7aac84cb7fef804af1ee62 Mon Sep 17 00:00:00 2001 From: Aakansha Doshi Date: Tue, 28 Feb 2023 19:53:30 +0530 Subject: [PATCH] fix: consider arrow for bound text element (#6297) * fix: consider arrow for bound text element * add spec --- src/components/App.tsx | 1 - src/element/typeChecks.test.ts | 66 ++++++++++++++++++++++++++++++++++ src/element/typeChecks.ts | 2 +- 3 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 src/element/typeChecks.test.ts diff --git a/src/components/App.tsx b/src/components/App.tsx index 5b9311f8..24da7d85 100644 --- a/src/components/App.tsx +++ b/src/components/App.tsx @@ -2767,7 +2767,6 @@ class App extends React.Component { ); if (container) { if ( - isArrowElement(container) || hasBoundTextElement(container) || !isTransparent(container.backgroundColor) || isHittingElementNotConsideringBoundingBox(container, this.state, [ diff --git a/src/element/typeChecks.test.ts b/src/element/typeChecks.test.ts new file mode 100644 index 00000000..ab04c29b --- /dev/null +++ b/src/element/typeChecks.test.ts @@ -0,0 +1,66 @@ +import { API } from "../tests/helpers/api"; +import { hasBoundTextElement } from "./typeChecks"; + +describe("Test TypeChecks", () => { + describe("Test hasBoundTextElement", () => { + it("should return true for text bindable containers with bound text", () => { + expect( + hasBoundTextElement( + API.createElement({ + type: "rectangle", + boundElements: [{ type: "text", id: "text-id" }], + }), + ), + ).toBeTruthy(); + + expect( + hasBoundTextElement( + API.createElement({ + type: "ellipse", + boundElements: [{ type: "text", id: "text-id" }], + }), + ), + ).toBeTruthy(); + + expect( + hasBoundTextElement( + API.createElement({ + type: "arrow", + boundElements: [{ type: "text", id: "text-id" }], + }), + ), + ).toBeTruthy(); + + expect( + hasBoundTextElement( + API.createElement({ + type: "image", + boundElements: [{ type: "text", id: "text-id" }], + }), + ), + ).toBeTruthy(); + }); + + it("should return false for text bindable containers without bound text", () => { + expect( + hasBoundTextElement( + API.createElement({ + type: "freedraw", + boundElements: [{ type: "arrow", id: "arrow-id" }], + }), + ), + ).toBeFalsy(); + }); + + it("should return false for non text bindable containers", () => { + expect( + hasBoundTextElement( + API.createElement({ + type: "freedraw", + boundElements: [{ type: "text", id: "text-id" }], + }), + ), + ).toBeFalsy(); + }); + }); +}); diff --git a/src/element/typeChecks.ts b/src/element/typeChecks.ts index a6b6cb2d..0f13648f 100644 --- a/src/element/typeChecks.ts +++ b/src/element/typeChecks.ts @@ -139,7 +139,7 @@ export const hasBoundTextElement = ( element: ExcalidrawElement | null, ): element is MarkNonNullable => { return ( - isBindableElement(element) && + isTextBindableContainer(element) && !!element.boundElements?.some(({ type }) => type === "text") ); };