mirror of
https://github.com/webstudio-is/webstudio.git
synced 2026-11-09 22:14:29 +09:00
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.
36 lines
934 B
TypeScript
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);
|
|
});
|