Files

30 lines
2.1 KiB
JavaScript

import test from "node:test";
import assert from "node:assert/strict";
import { gridOf, learnGrid, offersLength } from "./frame_grid.js";
test("the frame grid is read from the model's own length input: H3 17k+5, LTX 8k+1, a plain count none", async () => {
const slots = [{ id: "r2v", node: "H3Node", roles: [{ at: "project.video", input: "length", drives: "frames" }] },
{ id: "cam", node: "Plain", roles: [{ at: "project.video", input: "length", drives: "frames" }] }];
const api = { describeNodes: async () => ({ nodes: { H3Node: { widgets: [{ name: "length", min: 5, step: 17 }] }, Plain: { widgets: [{ name: "length", min: 1, step: 1 }] } } }) };
assert.equal(gridOf(slots), null, "not described yet: no grid, nothing snaps");
assert.equal(await learnGrid(api, slots), true);
assert.deepEqual(gridOf(slots), { step: 17, base: 5, fps: null }, "the strictest input wins");
assert.equal(await learnGrid(api, slots), false, "asked once");
const ltx = [{ node: "LtxNode", roles: [{ drives: "frames", input: "length" }] }];
await learnGrid({ describeNodes: async () => ({ nodes: { LtxNode: { widgets: [{ name: "length", min: 1, step: 8 }] } } }) }, ltx);
assert.deepEqual(gridOf(ltx), { step: 8, base: 1, fps: null });
});
test("Length and FPS are not offered only for a pipeline that saves a picture and takes no length or rate", () => {
const length = { id: "r", roles: [{ at: "project.video", input: "length", drives: "frames" }] };
const rate = { id: "s", roles: [{ at: "project.video", input: "fps", drives: "fps" }] };
const size = { id: "a", roles: [{ at: "project.video", input: "width" }] };
const picture = { id: "p", node: "SaveImage" };
assert.equal(offersLength([size, picture]), false);
assert.equal(offersLength([size, picture, length]), true);
assert.equal(offersLength([size, picture, rate]), true);
assert.equal(offersLength([size, { id: "x", node: "FunUISaveVideo" }]), true); // a clip with no length input (an imported workflow): the project numbers still time it
assert.equal(offersLength([]), true);
assert.equal(offersLength(undefined), true);
});