Refactored and extended test

This commit is contained in:
pythongosssss 2023-10-12 20:28:25 +01:00
parent be191b1489
commit a2fafda0e0

View File

@ -13,7 +13,19 @@ afterEach(() => {
jest.resetModules(); jest.resetModules();
}); });
test("widget conversion + primitive works on all standard types", async () => { [
{ name: "int", type: "INT", widget: "number", control: true },
{ name: "float", type: "FLOAT", widget: "number", control: true },
{ name: "text", type: "STRING" },
{
name: "customtext",
type: "STRING",
opt: { multiline: true },
},
{ name: "toggle", type: "BOOLEAN" },
{ name: "combo", type: ["a", "b", "c"], control: true },
].forEach((c) => {
test(`widget conversion + primitive works on ${c.name}`, async () => {
/** /**
* Test node with widgets of each type * Test node with widgets of each type
* @type { import("../../web/types/comfy").ComfyObjectInfo } ComfyObjectInfo * @type { import("../../web/types/comfy").ComfyObjectInfo } ComfyObjectInfo
@ -24,37 +36,46 @@ test("widget conversion + primitive works on all standard types", async () => {
output_name: [], output_name: [],
input: { input: {
required: { required: {
int: ["INT", {}], [c.name]: [c.type, c.opt ?? {}],
float: ["FLOAT", {}],
text: ["STRING", {}],
multiline: ["STRING", { multiline: true }],
bool: ["BOOLEAN", {}],
combo: [["a", "b", "c"], {}],
}, },
}, },
}; };
const { graph, ez } = await start({ const { ez } = await start({
mockNodeDefs: { mockNodeDefs: {
WidgetTestNode, WidgetTestNode,
}, },
}); });
// Create test node and convert to input
const n = ez.WidgetTestNode(); const n = ez.WidgetTestNode();
const w = n.widgets[c.name];
for (const name in WidgetTestNode.input?.required) {
const w = n.widgets[name];
w.convertToInput(); w.convertToInput();
expect(w.isConvertedToInput).toBeTruthy(); expect(w.isConvertedToInput).toBeTruthy();
const input = w.getConvertedInput(); const input = w.getConvertedInput();
expect(input).toBeTruthy(); expect(input).toBeTruthy();
// Connect to primitive
const p1 = ez.PrimitiveNode(); const p1 = ez.PrimitiveNode();
// @ts-ignore : input is valid // @ts-ignore : input is valid
p1.outputs[0].connectTo(input); p1.outputs[0].connectTo(input);
expect(p1.outputs[0].connectTo).toHaveLength(1); expect(p1.outputs[0].connectTo).toHaveLength(1);
// Ensure widget is correct type
const valueWidget = p1.widgets.value;
expect(valueWidget.widget.type).toBe(c.widget ?? c.name);
// Check if control_after_generate should be added
if (c.control) {
const controlWidget = p1.widgets.control_after_generate;
expect(controlWidget.widget.type).toBe("combo");
} }
// Ensure we dont have other widgets
expect(p1.node.widgets).toHaveLength(1 + +!!c.control);
}); });
});
test("converted widget works after reload", async () => { test("converted widget works after reload", async () => {
const { graph, ez } = await start(); const { graph, ez } = await start();