Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.
TypeScript accessibilityalternativecloudflarecloudflare-workersdesignfreefrontendopen-sourceradix-uireactremixweb-developmentwebflowwebsite-builderwebsite-developmentwebsiteswebstudio
add test
Roman Pominov334384a457ce
diff --git a/apps/designer/app/canvas/shared/instance.test.ts b/apps/designer/app/canvas/shared/instance.test.tsnew file mode 100644index 0000000000..de679ae3a6--- /dev/null+++ b/apps/designer/app/canvas/shared/instance.test.ts@@ -0,0 +1,48 @@+import { type Instance } from "@webstudio-is/react-sdk";+import { findInsertLocation } from "./instance";++const tree: Instance = {+ component: "Body",+ id: "root",+ cssRules: [],+ children: [+ { component: "Heading", id: "heading1", cssRules: [], children: [] },+ {+ component: "Box",+ id: "box1",+ cssRules: [],+ children: [+ { component: "Box", id: "box2", cssRules: [], children: [] },+ { component: "Heading", id: "heading2", cssRules: [], children: [] },+ { component: "Heading", id: "heading3", cssRules: [], children: [] },+ ],+ },+ ],+};++describe("findInsertLocation", () => {+ test("if no selected instance, insert into root", () => {+ expect(findInsertLocation(tree, undefined)).toEqual({+ parentId: "root",+ position: "end",+ });+ });++ test("if selected instance can accept children insert into it", () => {+ expect(findInsertLocation(tree, "box1")).toEqual({+ parentId: "box1",+ position: "end",+ });+ });++ test("if selected instance can not accept children insert into parent", () => {+ expect(findInsertLocation(tree, "heading1")).toEqual({+ parentId: "root",+ position: 1,+ });+ expect(findInsertLocation(tree, "heading2")).toEqual({+ parentId: "box1",+ position: 2,+ });+ });+});diff --git a/apps/designer/app/canvas/shared/instance.ts b/apps/designer/app/canvas/shared/instance.tsindex aa2a1d3993..c1628538cd 100644--- a/apps/designer/app/canvas/shared/instance.ts+++ b/apps/designer/app/canvas/shared/instance.ts@@ -51,7 +51,7 @@ export const usePopulateRootInstance = (tree: Tree) => {}};-const findInsertLocation = (+export const findInsertLocation = (rootInstance: Instance,selectedInstanceId: Instance["id"] | undefined): InstanceInsertionSpec => {