Files
webstudio/packages/react-sdk/src/hook.test.ts
T
Bogdan Chadkin 641619e4b4 refactor: remove instance selector from component hooks (#4469)
We need to remove reliance on instance selector iteration as much as
possible. In most cases we need only instance key which is a
JSON.stringify or instance selector to access computed props and
variables.

Here got rid of instance selector in component hooks and instead made
api to accept "instance data" with instance id, key and component
inside.
2024-11-29 21:23:24 +07:00

36 lines
934 B
TypeScript

import { expect, test } from "vitest";
import { getClosestInstance, type InstancePath } from "./hook";
test("get closest instance", () => {
const instancePath: InstancePath = [
{
id: "4",
instanceKey: JSON.stringify(["4", "3", "2", "1", "0"]),
component: "Content",
},
{
id: "3",
instanceKey: JSON.stringify(["3", "2", "1", "0"]),
component: "Tabs",
},
{
id: "2",
instanceKey: JSON.stringify(["2", "1", "0"]),
component: "Content",
},
{
id: "1",
instanceKey: JSON.stringify(["1", "0"]),
component: "Tabs",
},
{
id: "0",
instanceKey: JSON.stringify(["0"]),
component: "Body",
},
];
const [content2, tabs2, content1, tabs1, _body] = instancePath;
expect(getClosestInstance(instancePath, content2, "Tabs")).toBe(tabs2);
expect(getClosestInstance(instancePath, content1, "Tabs")).toBe(tabs1);
});