Files
ausboss-ComfyUI-AusBoss/tests/widget_visibility.test.mjs
T
ausboss ae931c9b36 Add shared per-node settings and help-card infrastructure
A schema-driven gear menu (toggles, numbers, text, segmented choices)
persisted per node type in localStorage, a reusable info-card popup, a
widget show/hide helper that keeps widgets_values stable, and a hand-drawn
gear icon - the plumbing the LoRA Loader and LM Studio gears build on.
2026-08-16 19:42:08 -05:00

57 lines
1.7 KiB
JavaScript

import test from "node:test";
import assert from "node:assert/strict";
import {
hideWidget,
setWidgetVisible,
showWidget,
} from "../js/shared/widget_visibility.mjs";
function makeWidget() {
return { name: "crop_position", value: "center", hidden: false };
}
test("hide collapses the widget and reports the change", () => {
const widget = makeWidget();
assert.equal(hideWidget(widget), true);
assert.equal(widget.hidden, true);
assert.deepEqual(widget.computeSize(), [0, -4]);
assert.deepEqual(widget.computeLayoutSize(), { minWidth: 0, minHeight: 0 });
assert.equal(typeof widget.draw, "function");
});
test("hide is idempotent", () => {
const widget = makeWidget();
assert.equal(hideWidget(widget), true);
assert.equal(hideWidget(widget), false);
});
test("show restores exactly what hide stashed", () => {
const widget = makeWidget();
const originalCompute = () => [120, 20];
widget.computeSize = originalCompute;
hideWidget(widget);
assert.equal(showWidget(widget), true);
assert.equal(widget.hidden, false);
assert.equal(widget.computeSize, originalCompute);
});
test("show without a prior hide is a no-op", () => {
const widget = makeWidget();
assert.equal(showWidget(widget), false);
assert.equal(widget.hidden, false);
});
test("setWidgetVisible only reports real transitions", () => {
const widget = makeWidget();
assert.equal(setWidgetVisible(widget, false), true);
assert.equal(setWidgetVisible(widget, false), false);
assert.equal(setWidgetVisible(widget, true), true);
assert.equal(setWidgetVisible(widget, true), false);
});
test("hide tolerates missing widgets", () => {
assert.equal(hideWidget(null), false);
assert.equal(showWidget(undefined), false);
});