Another test

This commit is contained in:
space-nuko
2023-05-21 18:27:37 -05:00
parent 57f635bbfd
commit 93afb64d63
5 changed files with 178 additions and 34 deletions

View File

@@ -10,10 +10,11 @@ import { LiteGraph } from '@litegraph-ts/core';
import type { ComfyNodeDef } from '$lib/ComfyNodeDef';
const objectInfo: Record<string, ComfyNodeDef> = await import("./data/objectInfo.json")
const json1: ComfyVanillaWorkflow = await import("./data/convertedWidgetAndPrimitiveNode.json")
const json1: ComfyVanillaWorkflow = await import("./data/convertedWidget.json")
const json2: ComfyVanillaWorkflow = await import("./data/convertedWidgetAndPrimitiveNode.json")
export default class convertVanillaWorkflowTests extends UnitTest {
test__convertsPrimitiveNodeAndConvertedInput() {
test__convertsWidget() {
const workflow = LiteGraph.cloneObject(json1)
const attrs: WorkflowAttributes = { ...defaultWorkflowAttributes }
@@ -31,6 +32,46 @@ export default class convertVanillaWorkflowTests extends UnitTest {
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", 0, 'seed'],
["ui/number", 20, 'steps'],
["ui/number", 8.5, 'cfg'],
["ui/combo", 'euler', 'sampler_name'],
["ui/combo", 'normal', 'scheduler'],
["ui/number", 1, 'denoise']
]);
const widget = widgets.find(w => w.attrs.title === "cfg") as WidgetLayout | null;
expect(widget).toBeDefined();
expect(widget.node).toBeDefined();
expect(widget.node.type).toEqual("ui/number")
expect(widget.node.getValue()).toEqual(8.5)
expect(convWorkflow.graph.getNodeById(widget.node.id)).toEqual(widget.node)
}
test__convertsPrimitiveNodeAndConvertedInput() {
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);
expect(widgets).toHaveLength(6);

View File

@@ -0,0 +1,68 @@
{
"last_node_id": 1,
"last_link_id": 0,
"nodes": [
{
"id": 1,
"type": "KSampler",
"pos": [
707,
502
],
"size": {
"0": 315,
"1": 262
},
"flags": {},
"order": 0,
"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
}
],
"outputs": [
{
"name": "LATENT",
"type": "LATENT",
"links": null,
"shape": 3
}
],
"properties": {
"Node name for S&R": "KSampler"
},
"widgets_values": [
0,
"randomize",
20,
8.5,
"euler",
"normal",
1
]
}
],
"links": [],
"groups": [],
"config": {},
"extra": {},
"version": 0.4
}