mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-30 19:21:54 +00:00
[Test] Add more tests on reroute (#793)
This commit is contained in:
@@ -43,6 +43,39 @@ describe("LGraph", () => {
|
|||||||
expect(graph.floatingLinks.size).toBe(0)
|
expect(graph.floatingLinks.size).toBe(0)
|
||||||
expect(graph.reroutes.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()
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
96
test/assets/linkedNodes.json
Normal file
96
test/assets/linkedNodes.json
Normal file
@@ -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
|
||||||
|
}
|
||||||
@@ -6,6 +6,7 @@ import { LGraph } from "@/LGraph"
|
|||||||
import { LiteGraph } from "@/litegraph"
|
import { LiteGraph } from "@/litegraph"
|
||||||
|
|
||||||
import floatingLink from "./assets/floatingLink.json"
|
import floatingLink from "./assets/floatingLink.json"
|
||||||
|
import linkedNodes from "./assets/linkedNodes.json"
|
||||||
import { basicSerialisableGraph, minimalSerialisableGraph, oldSchemaGraph } from "./assets/testGraphs"
|
import { basicSerialisableGraph, minimalSerialisableGraph, oldSchemaGraph } from "./assets/testGraphs"
|
||||||
|
|
||||||
interface LitegraphFixtures {
|
interface LitegraphFixtures {
|
||||||
@@ -13,6 +14,7 @@ interface LitegraphFixtures {
|
|||||||
minimalSerialisableGraph: SerialisableGraph
|
minimalSerialisableGraph: SerialisableGraph
|
||||||
oldSchemaGraph: ISerialisedGraph
|
oldSchemaGraph: ISerialisedGraph
|
||||||
floatingLinkGraph: 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. */
|
/** 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<LitegraphFixtures>({
|
|||||||
minimalSerialisableGraph: structuredClone(minimalSerialisableGraph),
|
minimalSerialisableGraph: structuredClone(minimalSerialisableGraph),
|
||||||
oldSchemaGraph: structuredClone(oldSchemaGraph),
|
oldSchemaGraph: structuredClone(oldSchemaGraph),
|
||||||
floatingLinkGraph: structuredClone(floatingLink as unknown as ISerialisedGraph),
|
floatingLinkGraph: structuredClone(floatingLink as unknown as ISerialisedGraph),
|
||||||
|
linkedNodesGraph: structuredClone(linkedNodes as unknown as ISerialisedGraph),
|
||||||
})
|
})
|
||||||
|
|
||||||
/** Test that use {@link DirtyFixtures}. One test per file. */
|
/** Test that use {@link DirtyFixtures}. One test per file. */
|
||||||
|
|||||||
Reference in New Issue
Block a user