|
|
|
@ -4,6 +4,7 @@ import { UI, Pointer, Keyboard } from "./helpers/ui";
|
|
|
|
|
import { getTransformHandles } from "../element/transformHandles";
|
|
|
|
|
import { API } from "./helpers/api";
|
|
|
|
|
import { KEYS } from "../keys";
|
|
|
|
|
import { actionCreateContainerFromText } from "../actions/actionBoundText";
|
|
|
|
|
|
|
|
|
|
const { h } = window;
|
|
|
|
|
|
|
|
|
@ -209,4 +210,103 @@ describe("element binding", () => {
|
|
|
|
|
).toBe(null);
|
|
|
|
|
expect(arrow.endBinding?.elementId).toBe(text.id);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("should update binding when text containerized", async () => {
|
|
|
|
|
const rectangle1 = API.createElement({
|
|
|
|
|
type: "rectangle",
|
|
|
|
|
id: "rectangle1",
|
|
|
|
|
width: 100,
|
|
|
|
|
height: 100,
|
|
|
|
|
boundElements: [
|
|
|
|
|
{ id: "arrow1", type: "arrow" },
|
|
|
|
|
{ id: "arrow2", type: "arrow" },
|
|
|
|
|
],
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const arrow1 = API.createElement({
|
|
|
|
|
type: "arrow",
|
|
|
|
|
id: "arrow1",
|
|
|
|
|
points: [
|
|
|
|
|
[0, 0],
|
|
|
|
|
[0, -87.45777932247563],
|
|
|
|
|
],
|
|
|
|
|
startBinding: {
|
|
|
|
|
elementId: "rectangle1",
|
|
|
|
|
focus: 0.2,
|
|
|
|
|
gap: 7,
|
|
|
|
|
},
|
|
|
|
|
endBinding: {
|
|
|
|
|
elementId: "text1",
|
|
|
|
|
focus: 0.2,
|
|
|
|
|
gap: 7,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const arrow2 = API.createElement({
|
|
|
|
|
type: "arrow",
|
|
|
|
|
id: "arrow2",
|
|
|
|
|
points: [
|
|
|
|
|
[0, 0],
|
|
|
|
|
[0, -87.45777932247563],
|
|
|
|
|
],
|
|
|
|
|
startBinding: {
|
|
|
|
|
elementId: "text1",
|
|
|
|
|
focus: 0.2,
|
|
|
|
|
gap: 7,
|
|
|
|
|
},
|
|
|
|
|
endBinding: {
|
|
|
|
|
elementId: "rectangle1",
|
|
|
|
|
focus: 0.2,
|
|
|
|
|
gap: 7,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const text1 = API.createElement({
|
|
|
|
|
type: "text",
|
|
|
|
|
id: "text1",
|
|
|
|
|
text: "ola",
|
|
|
|
|
boundElements: [
|
|
|
|
|
{ id: "arrow1", type: "arrow" },
|
|
|
|
|
{ id: "arrow2", type: "arrow" },
|
|
|
|
|
],
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
h.elements = [rectangle1, arrow1, arrow2, text1];
|
|
|
|
|
|
|
|
|
|
API.setSelectedElements([text1]);
|
|
|
|
|
|
|
|
|
|
expect(h.state.selectedElementIds[text1.id]).toBe(true);
|
|
|
|
|
|
|
|
|
|
h.app.actionManager.executeAction(actionCreateContainerFromText);
|
|
|
|
|
|
|
|
|
|
// new text container will be placed before the text element
|
|
|
|
|
const container = h.elements.at(-2)!;
|
|
|
|
|
|
|
|
|
|
expect(container.type).toBe("rectangle");
|
|
|
|
|
expect(container.id).not.toBe(rectangle1.id);
|
|
|
|
|
|
|
|
|
|
expect(container).toEqual(
|
|
|
|
|
expect.objectContaining({
|
|
|
|
|
boundElements: expect.arrayContaining([
|
|
|
|
|
{
|
|
|
|
|
type: "text",
|
|
|
|
|
id: text1.id,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
type: "arrow",
|
|
|
|
|
id: arrow1.id,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
type: "arrow",
|
|
|
|
|
id: arrow2.id,
|
|
|
|
|
},
|
|
|
|
|
]),
|
|
|
|
|
}),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(arrow1.startBinding?.elementId).toBe(rectangle1.id);
|
|
|
|
|
expect(arrow1.endBinding?.elementId).toBe(container.id);
|
|
|
|
|
expect(arrow2.startBinding?.elementId).toBe(container.id);
|
|
|
|
|
expect(arrow2.endBinding?.elementId).toBe(rectangle1.id);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|