diff --git a/test/LGraph.test.ts b/test/LGraph.test.ts index 4b3675bf5f..25d935f94e 100644 --- a/test/LGraph.test.ts +++ b/test/LGraph.test.ts @@ -43,6 +43,39 @@ describe("LGraph", () => { expect(graph.floatingLinks.size).toBe(0) expect(graph.reroutes.size).toBe(0) }) + + test("Can add reroute to existing link", ({ expect, linkedNodesGraph }) => { + const graph = new LGraph(linkedNodesGraph) + expect(graph.nodes.length).toBe(2) + expect(graph.links.size).toBe(1) + expect(graph.reroutes.size).toBe(0) + + graph.createReroute([0, 0], graph.links.values().next().value!) + expect(graph.links.size).toBe(1) + expect(graph.reroutes.size).toBe(1) + }) + + test("Create floating reroute when one side of node is removed", ({ expect, linkedNodesGraph }) => { + const graph = new LGraph(linkedNodesGraph) + graph.createReroute([0, 0], graph.links.values().next().value!) + graph.remove(graph.nodes[0]) + + expect(graph.links.size).toBe(0) + expect(graph.floatingLinks.size).toBe(1) + expect(graph.reroutes.size).toBe(1) + expect(graph.reroutes.values().next().value!.floating).not.toBeUndefined() + }) + + test("Create floating reroute when one side of link is removed", ({ expect, linkedNodesGraph }) => { + const graph = new LGraph(linkedNodesGraph) + graph.createReroute([0, 0], graph.links.values().next().value!) + graph.nodes[0].disconnectOutput(0) + + expect(graph.links.size).toBe(0) + expect(graph.floatingLinks.size).toBe(1) + expect(graph.reroutes.size).toBe(1) + expect(graph.reroutes.values().next().value!.floating).not.toBeUndefined() + }) }) }) diff --git a/test/assets/linkedNodes.json b/test/assets/linkedNodes.json new file mode 100644 index 0000000000..5eed02368b --- /dev/null +++ b/test/assets/linkedNodes.json @@ -0,0 +1,96 @@ +{ + "id": "26a34f13-1767-4847-b25f-a21dedf6840d", + "revision": 0, + "last_node_id": 3, + "last_link_id": 2, + "nodes": [ + { + "id": 2, + "type": "VAEDecode", + "pos": [ + 63.44815444946289, + 178.71633911132812 + ], + "size": [ + 210, + 46 + ], + "flags": {}, + "order": 0, + "mode": 0, + "inputs": [ + { + "name": "samples", + "type": "LATENT", + "link": null + }, + { + "name": "vae", + "type": "VAE", + "link": null + } + ], + "outputs": [ + { + "name": "IMAGE", + "type": "IMAGE", + "links": [ + 2 + ] + } + ], + "properties": { + "Node name for S&R": "VAEDecode" + }, + "widgets_values": [] + }, + { + "id": 3, + "type": "SaveImage", + "pos": [ + 419.36920166015625, + 179.71388244628906 + ], + "size": [ + 226.3714141845703, + 58 + ], + "flags": {}, + "order": 1, + "mode": 0, + "inputs": [ + { + "name": "images", + "type": "IMAGE", + "link": 2 + } + ], + "outputs": [], + "properties": {}, + "widgets_values": [ + "ComfyUI" + ] + } + ], + "links": [ + [ + 2, + 2, + 0, + 3, + 0, + "IMAGE" + ] + ], + "groups": [], + "config": {}, + "extra": { + "linkExtensions": [ + { + "id": 2, + "parentId": 1 + } + ] + }, + "version": 0.4 +} \ No newline at end of file diff --git a/test/testExtensions.ts b/test/testExtensions.ts index c70f1bb6f5..3953b08b6f 100644 --- a/test/testExtensions.ts +++ b/test/testExtensions.ts @@ -6,6 +6,7 @@ import { LGraph } from "@/LGraph" import { LiteGraph } from "@/litegraph" import floatingLink from "./assets/floatingLink.json" +import linkedNodes from "./assets/linkedNodes.json" import { basicSerialisableGraph, minimalSerialisableGraph, oldSchemaGraph } from "./assets/testGraphs" interface LitegraphFixtures { @@ -13,6 +14,7 @@ interface LitegraphFixtures { minimalSerialisableGraph: SerialisableGraph oldSchemaGraph: ISerialisedGraph floatingLinkGraph: ISerialisedGraph + linkedNodesGraph: ISerialisedGraph } /** These fixtures alter global state, and are difficult to reset. Relies on a single test per-file to reset state. */ @@ -32,6 +34,7 @@ export const test = baseTest.extend({ minimalSerialisableGraph: structuredClone(minimalSerialisableGraph), oldSchemaGraph: structuredClone(oldSchemaGraph), floatingLinkGraph: structuredClone(floatingLink as unknown as ISerialisedGraph), + linkedNodesGraph: structuredClone(linkedNodes as unknown as ISerialisedGraph), }) /** Test that use {@link DirtyFixtures}. One test per file. */