Files
olivv-cs-ComfyUI-FunPack/app/shell/tests/panels.test.js
T
digital-garbage 549e430806 app: one gutter, one head height, one control column
The layout was assembled by hand and read like it. Measured at 1440x900:
the three columns started at three different heights, a panel head was 41px
when it held a control and 34 when it did not, the gap left of the centre
was 7px and right of it 19, the properties column sat 11px further in than
the others inside a border that meant nothing, and five controls in one
list had four different widths -- a <select> takes the width of its widest
option, so the row listing checkpoint filenames was 124px wider than its
neighbours.

Now: --gutter is the space between regions, between two panels stacked in
a column, and inside the bands; the head band height is the panel head
height is the collapsible head height; --control-col gives every settings
control the same two edges. The frame's bands run edge to edge and the
content is inset by the gutter, so the app has an outline instead of a
margin that changed per region.

Also here, all of it visible in the same screenshot:

* The status sat against the Generate button with 1300px of empty bar to
  its left -- everything was in one right-aligned group. What the app says
  is at the start of the row now, what you press is at the end.
* A panel body is a column with a gap: two things put in it by two parts
  of the app had whatever space their line boxes happened to leave.
* A container query adds no specificity, so the narrow-panel rule written
  above the rules it overrides lost -- and flex-basis in a column is
  HEIGHT, which turned four settings into a panel two screens long.
* The theme you picked was thrown away on every load: the appearance
  module applied its own declared default over the choice the page had
  already applied from storage. It adopts the live value now, and a panel
  is built after setup so its control shows what setup settled on.
2026-08-30 21:01:50 +03:00

143 lines
5.2 KiB
JavaScript

// Mounting a module's panel.
//
// The guarantee this file exists to check is stated in panels.js: a module that
// failed is indistinguishable from one nobody installed. No placeholder, no
// greyed row, nothing on screen. It had never been tested against a module that
// fails AFTER its panel is built, which is the only case where there is
// something on screen to leave behind.
import test from "node:test";
import assert from "node:assert/strict";
import { setupDom, teardownDom } from "../../composer/tests/_dom.js";
let mountAll, offer, settle, resetMounts, resetValues;
test.before(async () => {
setupDom();
await import("../../composer/composer.js");
({ mountAll } = await import("../panels.js"));
({ offer, settle, _reset: resetMounts } = await import("../mounts.js"));
({ _reset: resetValues } = await import("../values.js"));
});
test.after(() => teardownDom());
function region() {
resetMounts();
resetValues();
const host = document.createElement("div");
document.body.replaceChildren(host);
offer("generation.model", host);
return host;
}
const spec = (over = {}) => ({
id: "demo", title: "Demo", mount: "generation.model",
settings: { steps: { type: "int", label: "Steps", default: 20 } },
...over,
});
test("a module whose setup throws leaves nothing on screen", async () => {
const host = region();
const { mounted, hidden } = await mountAll(
{ modules: [spec({ ui: "./boom.js" })] },
{ load: async () => ({ setup: () => { throw new Error("no"); } }) });
assert.deepEqual(mounted, []);
assert.equal(hidden.length, 1);
assert.equal(host.childElementCount, 0,
"a hidden module left its panel in the document");
});
test("a module whose ui.js will not import leaves nothing on screen", async () => {
const host = region();
const { hidden } = await mountAll(
{ modules: [spec({ ui: "./missing.js" })] },
{ load: async () => { throw new Error("404"); } });
assert.equal(hidden.length, 1);
assert.equal(host.childElementCount, 0);
});
test("a module that mounts is on screen, so the checks above can fail", async () => {
// Without this the two tests above pass on a mountAll that mounts nothing.
const host = region();
const { mounted, hidden } = await mountAll({ modules: [spec()] });
assert.deepEqual(hidden, []);
assert.equal(mounted.length, 1);
assert.equal(host.childElementCount, 1);
});
test("a module's setup still runs, and its teardown is kept", async () => {
const host = region();
let torn = 0;
const { mounted } = await mountAll(
{ modules: [spec({ ui: "./ok.js" })] },
{ load: async () => ({ setup: () => () => { torn += 1; } }) });
assert.equal(host.childElementCount, 1);
mounted[0].destroy();
assert.equal(torn, 1, "the unsubscribe setup() returned was dropped");
});
test("a region's stand-in comes down once something is in it", () => {
// A line reading "modules appear here" left above the modules that appeared
// is a region explaining itself to nobody.
resetMounts();
const host = document.createElement("div");
const standIn = document.createElement("p");
host.append(standIn);
document.body.replaceChildren(host);
offer("generation.model", host, standIn);
settle();
assert.ok(standIn.parentNode, "a region nothing mounted into lost its stand-in");
host.append(document.createElement("div"));
settle();
assert.equal(standIn.parentNode, null, "the stand-in stayed above what mounted");
});
test("two names on one host share its stand-in", () => {
// Five mount points are offered on the Generation panel. Taking the stand-in
// down as each one mounted would take down a stand-in belonging to all five,
// on behalf of the first.
resetMounts();
const host = document.createElement("div");
const standIn = document.createElement("p");
host.append(standIn);
document.body.replaceChildren(host);
offer("generation.model", host, standIn);
offer("generation.sampling", host, standIn);
settle();
assert.ok(standIn.parentNode);
host.append(document.createElement("div"));
settle();
assert.equal(standIn.parentNode, null);
});
test("a value a module adopts in setup is what its control shows", () => {
// The theme is applied by the page before any module exists, and the module's
// own declared default is something else. Building the panel from a snapshot
// taken BEFORE setup meant the control said "Auto" while the app was dark --
// and the first click on it, being a change to what it already showed, did
// nothing at all.
const host = region();
const spec = {
id: "appearance", mount: "generation.model", ui: "adopts",
settings: { theme: { type: "enum", default: "auto", label: "Colour scheme",
options: [{ value: "dark", label: "Dark" },
{ value: "auto", label: "Auto" }] } },
};
const load = async () => ({
setup: ({ values }) => { values.set("theme", "dark"); },
});
return mountAll({ modules: [spec] }, { load }).then(({ mounted }) => {
assert.equal(mounted.length, 1);
const chosen = [...host.querySelectorAll('[aria-checked="true"], option:checked')]
.map((n) => n.textContent.trim());
assert.deepEqual(chosen, ["Dark"], "the control showed the default, not what the app was set to");
});
});