Files
webstudio/app/shared/tree-utils/insert-instance.test.ts
T
2022-03-13 04:22:21 +00:00

102 lines
2.4 KiB
TypeScript

import { type Instance } from "@webstudio-is/sdk";
import { type InstanceInsertionSpec } from ".";
import { insertInstance } from "./insert-instance";
describe("Insert instance", () => {
test(`inside a nested div using "end": div 1 > div 2 > [div 3]`, () => {
const instance: Instance = {
component: "Box",
id: "1",
style: {},
children: [
{
component: "Box",
id: "2",
style: {},
children: [],
},
],
};
const instanceInsertionSpec: InstanceInsertionSpec = {
parentId: "2",
component: "Box",
position: "end",
id: "3",
};
const result = insertInstance(instanceInsertionSpec, instance);
expect(result).toMatchSnapshot();
});
test("after a nested div using index: div 1 > div 2, [div 3]", () => {
const instance: Instance = {
component: "Box",
id: "1",
style: {},
children: [
{
component: "Box",
id: "2",
style: {},
children: [],
},
],
};
const instanceInsertionSpec: InstanceInsertionSpec = {
parentId: "1",
component: "Box",
position: 1,
id: "3",
};
const result = insertInstance(instanceInsertionSpec, instance);
expect(result).toMatchSnapshot();
});
test("before a nested div using index: div 1 > [div 3], div 2", () => {
const instance: Instance = {
component: "Box",
id: "1",
style: {},
children: [
{
component: "Box",
id: "2",
style: {},
children: [],
},
],
};
const instanceInsertionSpec: InstanceInsertionSpec = {
parentId: "1",
component: "Box",
position: 0,
id: "3",
};
const result = insertInstance(instanceInsertionSpec, instance);
expect(result).toMatchSnapshot();
});
test(`after a nested div using "end": div 1 > div 2, [div 3]`, () => {
const instance: Instance = {
component: "Box",
id: "1",
style: {},
children: [
{
component: "Box",
id: "2",
style: {},
children: [],
},
],
};
const instanceInsertionSpec: InstanceInsertionSpec = {
parentId: "1",
component: "Box",
position: "end",
id: "3",
};
const result = insertInstance(instanceInsertionSpec, instance);
expect(result).toMatchSnapshot();
});
});