46 lines
1.5 KiB
JavaScript

const {
createEmptyFrame,
applyBlackout,
cloneFrame,
getIntensity,
setIntensity,
} = require("../src/renderer/frame");
describe("LogicalFrame helpers", () => {
it("createEmptyFrame zeroes all intensities", () => {
const frame = createEmptyFrame(["a", "b", "c"], 40);
expect(frame.fps).toBe(40);
expect(getIntensity(frame, "a")).toEqual({ top: 0, bottom: 0 });
expect(getIntensity(frame, "b")).toEqual({ top: 0, bottom: 0 });
expect(getIntensity(frame, "c")).toEqual({ top: 0, bottom: 0 });
});
it("setIntensity clamps to 0-1", () => {
const frame = createEmptyFrame(["a"], 40);
setIntensity(frame, "a", 1.5, -0.5);
expect(getIntensity(frame, "a")).toEqual({ top: 1, bottom: 0 });
});
it("applyBlackout zeroes all intensities", () => {
const frame = createEmptyFrame(["a", "b"], 40);
setIntensity(frame, "a", 0.8, 0.4);
setIntensity(frame, "b", 1, 1);
const blacked = applyBlackout(frame);
expect(getIntensity(blacked, "a")).toEqual({ top: 0, bottom: 0 });
expect(getIntensity(blacked, "b")).toEqual({ top: 0, bottom: 0 });
});
it("cloneFrame is independent", () => {
const frame = createEmptyFrame(["a"], 40);
setIntensity(frame, "a", 0.5, 0.5);
const clone = cloneFrame(frame);
setIntensity(frame, "a", 1, 1);
expect(getIntensity(clone, "a")).toEqual({ top: 0.5, bottom: 0.5 });
});
it("getIntensity defaults to zero for unknown id", () => {
const frame = createEmptyFrame(["a"], 40);
expect(getIntensity(frame, "missing")).toEqual({ top: 0, bottom: 0 });
});
});