ComfyUI/tests-ui/tests/widgetInputs.test.js
2023-10-11 21:32:13 +01:00

80 lines
2.5 KiB
JavaScript

/// <reference path="../node_modules/@types/jest/index.d.ts" />
// @ts-check
const { start } = require("../utils");
const lg = require("../utils/litegraph");
beforeEach(() => {
lg.setup(global);
});
afterEach(() => {
lg.teardown(global);
jest.resetModules();
});
test("converted widget works after reload", async () => {
const { graph, ez } = await start();
let { $: n } = ez.CheckpointLoaderSimple();
const inputCount = n.inputs.length;
// Convert ckpt name to an input
n.widgets.ckpt_name.convertToInput();
expect(n.widgets.ckpt_name.isConvertedToInput).toBeTruthy();
expect(n.inputs.ckpt_name).toBeTruthy();
expect(n.inputs.length).toEqual(inputCount + 1);
// Convert back to widget and ensure input is removed
n.widgets.ckpt_name.convertToWidget();
expect(n.widgets.ckpt_name.isConvertedToInput).toBeFalsy();
expect(() => n.inputs.ckpt_name).toThrow(/Unknown input/);
expect(n.inputs.length).toEqual(inputCount);
// Convert again and reload the graph to ensure it maintains state
n.widgets.ckpt_name.convertToInput();
expect(n.inputs.length).toEqual(inputCount + 1);
// TODO: connect primitive
await graph.reload();
// TODO: ensure primitive connected, disconnect, reconnect
// Find the reloaded node in the graph
n = graph.find(n);
expect(n.widgets.ckpt_name.isConvertedToInput).toBeTruthy();
expect(n.inputs.ckpt_name).toBeTruthy();
expect(n.inputs.length).toEqual(inputCount + 1);
// Convert back to widget and ensure input is removed
n.widgets.ckpt_name.convertToWidget();
expect(n.widgets.ckpt_name.isConvertedToInput).toBeFalsy();
expect(() => n.inputs.ckpt_name).toThrow(/Unknown input/);
expect(n.inputs.length).toEqual(inputCount);
});
test("converted widget works on clone", async () => {
const { graph, ez } = await start();
let { $: n } = ez.CheckpointLoaderSimple();
// Convert the widget to an input
n.widgets.ckpt_name.convertToInput();
expect(n.widgets.ckpt_name.isConvertedToInput).toBeTruthy();
// Clone the node
n.menu["Clone"].call();
expect(graph.nodes).toHaveLength(2);
const clone = graph.nodes[1];
expect(clone.id).not.toEqual(n.id);
// Ensure the clone has an input
expect(clone.widgets.ckpt_name.isConvertedToInput).toBeTruthy();
expect(clone.inputs.ckpt_name).toBeTruthy();
// TODO: connect primitive to clone
// Convert back to widget and ensure input is removed
clone.widgets.ckpt_name.convertToWidget();
expect(clone.widgets.ckpt_name.isConvertedToInput).toBeFalsy();
expect(() => clone.inputs.ckpt_name).toThrow(/Unknown input/);
});