From 915265a804a7fc14f434d78f2a5e4866669a40a3 Mon Sep 17 00:00:00 2001 From: space-nuko <24979496+space-nuko@users.noreply.github.com> Date: Sun, 21 May 2023 18:50:27 -0500 Subject: [PATCH] Converted seed widget test --- src/tests/convertVanillaWorkflowTests.ts | 52 ++++++++- src/tests/data/convertedSeedWidget.json | 134 +++++++++++++++++++++++ 2 files changed, 184 insertions(+), 2 deletions(-) create mode 100644 src/tests/data/convertedSeedWidget.json diff --git a/src/tests/convertVanillaWorkflowTests.ts b/src/tests/convertVanillaWorkflowTests.ts index 1ca8a1e..c4bfa1f 100644 --- a/src/tests/convertVanillaWorkflowTests.ts +++ b/src/tests/convertVanillaWorkflowTests.ts @@ -11,7 +11,8 @@ import type { ComfyNodeDef } from '$lib/ComfyNodeDef'; const objectInfo: Record = await import("./data/objectInfo.json") const json1: ComfyVanillaWorkflow = await import("./data/convertedWidget.json") -const json2: ComfyVanillaWorkflow = await import("./data/convertedWidgetAndPrimitiveNode.json") +const json2: ComfyVanillaWorkflow = await import("./data/convertedSeedWidget.json") +const json3: ComfyVanillaWorkflow = await import("./data/convertedWidgetAndPrimitiveNode.json") export default class convertVanillaWorkflowTests extends UnitTest { test__convertsWidget() { @@ -53,9 +54,56 @@ export default class convertVanillaWorkflowTests extends UnitTest { expect(convWorkflow.graph.getNodeById(widget.node.id)).toEqual(widget.node) } + test__convertsSeedWidget() { + const workflow = LiteGraph.cloneObject(json2) + const attrs: WorkflowAttributes = { ...defaultWorkflowAttributes } + + ComfyApp.knownBackendNodes["KSampler"] = { + nodeDef: objectInfo["KSampler"] + } + + const converted = convertVanillaWorkflow(workflow, attrs) + + expect(converted).toBeInstanceOf(Array) + + const [convWorkflow, convLayout] = converted; + + const layout = get(convLayout) + + expect(Object.keys(layout.allItems)).toHaveLength(10) + + const widgets = Object.values(layout.allItems).filter(di => di.dragItem.type === "widget").map(di => di.dragItem) as WidgetLayout[]; + expect(widgets).toHaveLength(6); + + const widgetsValues = widgets.map(w => { return [w.node.type, w.node.getValue(), w.attrs.title] }) + expect(widgetsValues).toEqual([ + ["ui/number", 20, 'steps'], + ["ui/number", 8, 'cfg'], + ["ui/combo", 'euler', 'sampler_name'], + ["ui/combo", 'normal', 'scheduler'], + ["ui/number", 1, 'denoise'], + ["ui/number", 1461, 'seed'] + ]); + + const widget = widgets.find(w => w.attrs.title === "seed") as WidgetLayout | null; + expect(widget).toBeDefined(); + expect(widget.node).toBeDefined(); + expect(widget.node.type).toEqual("ui/number") + expect(widget.node.getValue()).toEqual(1461) + expect(convWorkflow.graph.getNodeById(widget.node.id)).toEqual(widget.node) + + const links = widget.node.getOutputLinks(0) + expect(links).toHaveLength(1); + + const kSampler = convWorkflow.graph.findNodesByType("KSampler")[0]; + expect(links[0].origin_id).toEqual(widget.node.id); + expect(links[0].target_id).toEqual(kSampler.id); + expect(widget.node.outputs[0].type).toEqual("number"); + expect(links[0].type).toEqual("number"); + } test__convertsPrimitiveNodeAndConvertedInput() { - const workflow = LiteGraph.cloneObject(json2) + const workflow = LiteGraph.cloneObject(json3) const attrs: WorkflowAttributes = { ...defaultWorkflowAttributes } ComfyApp.knownBackendNodes["KSampler"] = { diff --git a/src/tests/data/convertedSeedWidget.json b/src/tests/data/convertedSeedWidget.json new file mode 100644 index 0000000..cc4ffc4 --- /dev/null +++ b/src/tests/data/convertedSeedWidget.json @@ -0,0 +1,134 @@ +{ + "last_node_id": 2, + "last_link_id": 1, + "nodes": [ + { + "id": 1, + "type": "KSampler", + "pos": [ + 1514, + 348 + ], + "size": [ + 315, + 262 + ], + "flags": {}, + "order": 1, + "mode": 0, + "inputs": [ + { + "name": "model", + "type": "MODEL", + "link": null + }, + { + "name": "positive", + "type": "CONDITIONING", + "link": null + }, + { + "name": "negative", + "type": "CONDITIONING", + "link": null + }, + { + "name": "latent_image", + "type": "LATENT", + "link": null + }, + { + "name": "seed", + "type": "INT", + "link": 1, + "widget": { + "name": "seed", + "config": [ + "INT", + { + "default": 0, + "min": 0, + "max": 18446744073709552000 + } + ] + }, + "slot_index": 4 + } + ], + "outputs": [ + { + "name": "LATENT", + "type": "LATENT", + "links": null, + "shape": 3 + } + ], + "properties": { + "Node name for S&R": "KSampler" + }, + "widgets_values": [ + 1461, + "randomize", + 20, + 8, + "euler", + "normal", + 1 + ] + }, + { + "id": 2, + "type": "PrimitiveNode", + "pos": [ + 1160, + 420 + ], + "size": { + "0": 210, + "1": 82 + }, + "flags": {}, + "order": 0, + "mode": 0, + "outputs": [ + { + "name": "INT", + "type": "INT", + "links": [ + 1 + ], + "widget": { + "name": "seed", + "config": [ + "INT", + { + "default": 0, + "min": 0, + "max": 18446744073709552000 + } + ] + } + } + ], + "properties": {}, + "widgets_values": [ + 1461, + "randomize" + ] + } + ], + "links": [ + [ + 1, + 2, + 0, + 1, + 4, + "INT" + ] + ], + "groups": [], + "config": {}, + "extra": {}, + "version": 0.4 +} \ No newline at end of file